diff --git a/Libraries/SPTarkov.Server.Core/Extensions/DateTimeExtensions.cs b/Libraries/SPTarkov.Server.Core/Extensions/DateTimeExtensions.cs
new file mode 100644
index 00000000..e646db1e
--- /dev/null
+++ b/Libraries/SPTarkov.Server.Core/Extensions/DateTimeExtensions.cs
@@ -0,0 +1,85 @@
+namespace SPTarkov.Server.Core.Extensions
+{
+ public static class DateTimeExtensions
+ {
+ ///
+ /// Formats the time part of a date as a UTC string.
+ ///
+ /// The date to format in UTC.
+ /// The formatted time as 'HH-MM-SS'.
+ public static string FormatToBsgTime(this DateTimeOffset dateTimeOffset)
+ {
+ var universalTime = dateTimeOffset.ToUniversalTime();
+ var hour = Pad(universalTime.Hour);
+ var minute = Pad(universalTime.Minute);
+ var second = Pad(universalTime.Second);
+
+ return $"{hour}-{minute}-{second}";
+ }
+
+ ///
+ /// Formats the time part of a date as a UTC string.
+ ///
+ /// The date to format in UTC.
+ /// The formatted time as 'HH-MM-SS'.
+ public static string FormatToBsgTime(this DateTime dateTime)
+ {
+ var universalTime = dateTime.ToUniversalTime();
+ var hour = Pad(universalTime.Hour);
+ var minute = Pad(universalTime.Minute);
+ var second = Pad(universalTime.Second);
+
+ return $"{hour}-{minute}-{second}";
+ }
+
+ ///
+ /// Formats the date part of a date as a UTC string.
+ ///
+ /// The date to format in UTC.
+ /// The formatted date as 'YYYY-MM-DD'.
+ public static string FormatToBsgDate(this DateTimeOffset dateTimeOffset)
+ {
+ var universalTime = dateTimeOffset.ToUniversalTime();
+ var day = Pad(universalTime.Day);
+ var month = Pad(universalTime.Month);
+ var year = Pad(universalTime.Year);
+
+ return $"{year}-{month}-{day}";
+ }
+
+ ///
+ /// Formats the date part of a date as a UTC string.
+ ///
+ /// The date to format in UTC.
+ /// The formatted date as 'YYYY-MM-DD'.
+ public static string FormatToBsgDate(this DateTime dateTime)
+ {
+ var universalTime = dateTime.ToUniversalTime();
+ var day = Pad(universalTime.Day);
+ var month = Pad(universalTime.Month);
+ var year = Pad(universalTime.Year);
+
+ return $"{year}-{month}-{day}";
+ }
+
+ ///
+ /// Pads a number with a leading zero if it is less than 10.
+ ///
+ /// The number to pad.
+ /// The padded number as a string.
+ private static string Pad(int number)
+ {
+ return number.ToString().PadLeft(2, '0');
+ }
+
+ ///
+ /// Get current time formatted to fit BSGs requirement
+ ///
+ /// Date to format into bsg style
+ /// Time formatted in BSG format
+ public static string GetBsgFormattedWeatherTime(this DateTime date)
+ {
+ return date.FormatToBsgTime().Replace("-", ":").Replace("-", ":");
+ }
+ }
+}
diff --git a/Libraries/SPTarkov.Server.Core/Generators/WeatherGenerator.cs b/Libraries/SPTarkov.Server.Core/Generators/WeatherGenerator.cs
index f4964117..7e017d20 100644
--- a/Libraries/SPTarkov.Server.Core/Generators/WeatherGenerator.cs
+++ b/Libraries/SPTarkov.Server.Core/Generators/WeatherGenerator.cs
@@ -1,4 +1,5 @@
using SPTarkov.DI.Annotations;
+using SPTarkov.Server.Core.Extensions;
using SPTarkov.Server.Core.Helpers;
using SPTarkov.Server.Core.Models.Eft.Weather;
using SPTarkov.Server.Core.Models.Enums;
@@ -29,7 +30,7 @@ public class WeatherGenerator(
public void CalculateGameTime(WeatherData data)
{
var computedDate = _timeUtil.GetDateTimeNow();
- var formattedDate = _timeUtil.FormatDate(computedDate);
+ var formattedDate = computedDate.FormatToBsgDate();
data.Date = formattedDate;
data.Time = GetBsgFormattedInRaidTime();
@@ -45,19 +46,7 @@ public class WeatherGenerator(
/// Formatted time as String
protected string GetBsgFormattedInRaidTime()
{
- var clientAcceleratedDate = _weatherHelper.GetInRaidTime();
-
- return GetBsgFormattedTime(clientAcceleratedDate);
- }
-
- ///
- /// Get current time formatted to fit BSGs requirement
- ///
- /// Date to format into bsg style
- /// Time formatted in BSG format
- protected string GetBsgFormattedTime(DateTime date)
- {
- return _timeUtil.FormatTime(date).Replace("-", ":").Replace("-", ":");
+ return _weatherHelper.GetInRaidTime().GetBsgFormattedWeatherTime();
}
///
@@ -150,12 +139,12 @@ public class WeatherGenerator(
var inRaidTime = timestamp is null
? _weatherHelper.GetInRaidTime()
: _weatherHelper.GetInRaidTime(timestamp.Value);
- var normalTime = GetBsgFormattedTime(inRaidTime);
- var formattedDate = _timeUtil.FormatDate(
+ var normalTime = inRaidTime.GetBsgFormattedWeatherTime();
+ var formattedDate = (
timestamp.HasValue
? _timeUtil.GetDateTimeFromTimeStamp(timestamp.Value)
: DateTime.UtcNow
- );
+ ).FormatToBsgDate();
var datetimeBsgFormat = $"{formattedDate} {normalTime}";
weather.Timestamp = timestamp ?? _timeUtil.GetTimeStamp(); // matches weather.date
diff --git a/Libraries/SPTarkov.Server.Core/Services/InsuranceService.cs b/Libraries/SPTarkov.Server.Core/Services/InsuranceService.cs
index 49581e1b..82c0f0cd 100644
--- a/Libraries/SPTarkov.Server.Core/Services/InsuranceService.cs
+++ b/Libraries/SPTarkov.Server.Core/Services/InsuranceService.cs
@@ -105,8 +105,8 @@ public class InsuranceService(
var systemData = new SystemData
{
- Date = _timeUtil.GetDateMailFormat(),
- Time = _timeUtil.GetTimeMailFormat(),
+ Date = _timeUtil.GetBsgDateMailFormat(),
+ Time = _timeUtil.GetBsgTimeMailFormat(),
Location = mapId,
};
diff --git a/Libraries/SPTarkov.Server.Core/Utils/TimeUtil.cs b/Libraries/SPTarkov.Server.Core/Utils/TimeUtil.cs
index 513c9fc6..8d69b1be 100644
--- a/Libraries/SPTarkov.Server.Core/Utils/TimeUtil.cs
+++ b/Libraries/SPTarkov.Server.Core/Utils/TimeUtil.cs
@@ -1,4 +1,5 @@
using SPTarkov.DI.Annotations;
+using SPTarkov.Server.Core.Extensions;
namespace SPTarkov.Server.Core.Utils;
@@ -7,41 +8,13 @@ public class TimeUtil
{
public const int OneHourAsSeconds = 3600;
- ///
- /// Formats the time part of a date as a UTC string.
- ///
- /// The date to format in UTC.
- /// The formatted time as 'HH-MM-SS'.
- public string FormatTime(DateTimeOffset dateTime)
- {
- var hour = Pad(dateTime.ToUniversalTime().Hour);
- var minute = Pad(dateTime.ToUniversalTime().Minute);
- var second = Pad(dateTime.ToUniversalTime().Second);
-
- return $"{hour}-{minute}-{second}";
- }
-
- ///
- /// Formats the date part of a date as a UTC string.
- ///
- /// The date to format in UTC.
- /// The formatted date as 'YYYY-MM-DD'.
- public string FormatDate(DateTimeOffset dateTime)
- {
- var day = Pad(dateTime.ToUniversalTime().Day);
- var month = Pad(dateTime.ToUniversalTime().Month);
- var year = Pad(dateTime.ToUniversalTime().Year);
-
- return $"{year}-{month}-{day}";
- }
-
///
/// Gets the current date as a formatted UTC string.
///
/// The current date as 'YYYY-MM-DD'.
public string GetDate()
{
- return FormatDate(DateTimeOffset.UtcNow);
+ return DateTimeOffset.UtcNow.FormatToBsgDate();
}
public DateTime GetDateTimeNow()
@@ -55,7 +28,7 @@ public class TimeUtil
/// The current time as 'HH-MM-SS'.
public string GetTime()
{
- return FormatTime(DateTimeOffset.UtcNow);
+ return DateTimeOffset.UtcNow.FormatToBsgTime();
}
///
@@ -107,7 +80,7 @@ public class TimeUtil
///
/// The current time as 'HH:MM' in UTC.
/// GetTimeMailFormat
- public string GetTimeMailFormat()
+ public string GetBsgTimeMailFormat()
{
return DateTimeOffset.UtcNow.ToString("HH:mm");
}
@@ -116,7 +89,7 @@ public class TimeUtil
/// Gets the current date in UTC in a format suitable for emails in EFT.
///
/// The current date as 'DD.MM.YYYY' in UTC.
- public string GetDateMailFormat()
+ public string GetBsgDateMailFormat()
{
return DateTimeOffset.UtcNow.ToString("dd.MM.yyyy");
}
@@ -171,16 +144,6 @@ public class TimeUtil
return ((DateTimeOffset)lastFullHour).ToUnixTimeSeconds();
}
- ///
- /// Pads a number with a leading zero if it is less than 10.
- ///
- /// The number to pad.
- /// The padded number as a string.
- private static string Pad(int number)
- {
- return number.ToString().PadLeft(2, '0');
- }
-
///
/// Takes a timestamp and converts to its date with Epoch
///