diff --git a/Core/Helpers/WeatherHelper.cs b/Core/Helpers/WeatherHelper.cs
index 9912a883..0b3163f4 100644
--- a/Core/Helpers/WeatherHelper.cs
+++ b/Core/Helpers/WeatherHelper.cs
@@ -35,7 +35,7 @@ public class WeatherHelper
///
/// (new Date())
/// Date object of current in-raid time
- public DateTime GetInRaidTime(double? timestamp = null)
+ public DateTime GetInRaidTime(long? timestamp = null)
{
// tarkov time = (real time * 7 % 24 hr) + 3 hour
var russiaOffsetMilliseconds = _timeUtil.GetHoursAsSeconds(3) * 1000;
diff --git a/Core/Utils/TimeUtil.cs b/Core/Utils/TimeUtil.cs
index af167958..835ded70 100644
--- a/Core/Utils/TimeUtil.cs
+++ b/Core/Utils/TimeUtil.cs
@@ -12,7 +12,7 @@ public class TimeUtil
///
/// The date to format in UTC.
/// The formatted time as 'HH-MM-SS'.
- public string FormatTime(DateTime dateTime)
+ public string FormatTime(DateTimeOffset dateTime)
{
var hour = Pad(dateTime.ToUniversalTime().Hour);
var minute = Pad(dateTime.ToUniversalTime().Minute);
@@ -26,7 +26,7 @@ public class TimeUtil
///
/// The date to format in UTC.
/// The formatted date as 'YYYY-MM-DD'.
- public string FormatDate(DateTime dateTime)
+ public string FormatDate(DateTimeOffset dateTime)
{
var day = Pad(dateTime.ToUniversalTime().Day);
var month = Pad(dateTime.ToUniversalTime().Month);
@@ -41,7 +41,7 @@ public class TimeUtil
/// The current date as 'YYYY-MM-DD'.
public string GetDate()
{
- return FormatDate(DateTime.Now);
+ return FormatDate(DateTimeOffset.UtcNow);
}
///
@@ -50,7 +50,7 @@ public class TimeUtil
/// The current time as 'HH-MM-SS'.
public string GetTime()
{
- return FormatTime(DateTime.Now);
+ return FormatTime(DateTimeOffset.UtcNow);
}
///
@@ -59,7 +59,7 @@ public class TimeUtil
/// The current timestamp in seconds since the Unix epoch in UTC.
public long GetTimeStamp()
{
- return DateTimeOffset.Now.ToUnixTimeSeconds();
+ return DateTimeOffset.Now.ToUnixTimeMilliseconds();
}
///
@@ -67,12 +67,14 @@ public class TimeUtil
///
/// datetime to get the time stamp for, if null it uses current date.
/// Unix epoch for the start of day of the calculated date
- public long GetStartOfDayTimeStamp(DateTime? dateTime)
+ public long GetStartOfDayTimeStamp(long? timestamp)
{
- var now = dateTime ?? DateTime.Now;
-
- return new DateTimeOffset(new DateTime(now.Year, now.Month, now.Day, 0, 0, 0))
- .ToUnixTimeSeconds();
+ DateTime now = timestamp.HasValue
+ ? DateTimeOffset.FromUnixTimeMilliseconds(timestamp.Value).DateTime
+ : DateTime.Now;
+
+ DateTime startOfDay = new DateTime(now.Year, now.Month, now.Day, 0, 0, 0);
+ return ((DateTimeOffset)startOfDay).ToUnixTimeMilliseconds();
}
///
@@ -82,7 +84,7 @@ public class TimeUtil
///
public long GetTimeStampFromNowDays(int daysFromNow)
{
- return DateTimeOffset.Now.AddDays(daysFromNow).ToUnixTimeSeconds();
+ return DateTimeOffset.UtcNow.AddDays(daysFromNow).ToUnixTimeSeconds();
}
///
@@ -92,16 +94,17 @@ public class TimeUtil
///
public long GetTimeStampFromNowHours(int hoursFromNow)
{
- return DateTimeOffset.Now.AddHours(hoursFromNow).ToUnixTimeSeconds();
+ return DateTimeOffset.UtcNow.AddHours(hoursFromNow).ToUnixTimeSeconds();
}
///
/// Gets the current time in UTC in a format suitable for mail in EFT.
///
/// The current time as 'HH:MM' in UTC.
+ /// GetTimeMailFormat
public string GetTimeMailFormat()
{
- return DateTime.UtcNow.ToString("HH:mm");
+ return DateTimeOffset.UtcNow.ToString("HH:mm");
}
///
@@ -110,7 +113,7 @@ public class TimeUtil
/// The current date as 'DD.MM.YYYY' in UTC.
public string GetDateMailFormat()
{
- return DateTime.UtcNow.ToString("dd.MM.yyyy");
+ return DateTimeOffset.UtcNow.ToString("dd.MM.yyyy");
}
///
@@ -129,19 +132,14 @@ public class TimeUtil
/// Time stamp of the next hour in unix time seconds
public long GetTimeStampOfNextHour()
{
- var now = DateTime.UtcNow;
+ DateTime now = DateTime.Now;
+ TimeSpan timeUntilNextHour = TimeSpan.FromMinutes(60 - now.Minute)
+ .Subtract(TimeSpan.FromSeconds(now.Second))
+ .Subtract(TimeSpan.FromMilliseconds(now.Millisecond));
+
+ var time = ((DateTimeOffset)now.Add(timeUntilNextHour)).ToUnixTimeSeconds();
- var nextHour = new DateTime(
- now.Year,
- now.Month,
- now.Day,
- now.Hour,
- 0,
- 0,
- DateTimeKind.Utc
- ).AddHours(1);
-
- return new DateTimeOffset(nextHour).ToUnixTimeSeconds();
+ return time;
}
///
@@ -151,19 +149,20 @@ public class TimeUtil
/// Timestamp
public long GetTodayMidnightTimeStamp()
{
- var now = DateTime.UtcNow;
-
- var midNight = new DateTime(
- now.Year,
- now.Month,
- now.Day,
- 0,
- 0,
- 0,
- DateTimeKind.Utc
- );
-
- return new DateTimeOffset(midNight).ToUnixTimeSeconds();
+ DateTime now = DateTime.Now;
+ int hours = now.Hour;
+ int minutes = now.Minute;
+
+ // If minutes greater than 0, subtract 1 hour
+ if (minutes > 0)
+ {
+ hours--;
+ }
+
+ // Create a new DateTime with the last full hour, 0 minutes, and 0 seconds
+ DateTime lastFullHour = new DateTime(now.Year, now.Month, now.Day, hours, 0, 0);
+
+ return ((DateTimeOffset)lastFullHour).ToUnixTimeMilliseconds();
}
///