Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Libraries/SPTarkov.Server.Core/Helpers/WeatherHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public DateTime GetInRaidTime(long timestamp)
var twentyFourHoursSeconds = timeUtil.GetHoursAsSeconds(24);
var currentTimestampSeconds = timestamp;

var tarkovTime = timeUtil.GetDateTimeFromTimeStamp(
var tarkovTime = timeUtil.GetUtcDateTimeFromTimeStamp(
(long)(russiaOffsetSeconds + currentTimestampSeconds * _weatherConfig.Acceleration) % twentyFourHoursSeconds
);

Expand Down
9 changes: 7 additions & 2 deletions Libraries/SPTarkov.Server.Core/Utils/TimeUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,14 @@ public DateTime GetDateTimeFromTimeStamp(long timeStamp)
return DateTimeOffset.FromUnixTimeSeconds(timeStamp).DateTime;
}

public int GetSecondsAsMilliseconds(int seconds)
/// <summary>
/// Takes a unix timestamp and converts to its UTC date
/// </summary>
/// <param name="timeStamp"></param>
/// <returns></returns>
public DateTime GetUtcDateTimeFromTimeStamp(long timeStamp)
{
return seconds * 60 * 1000;
return DateTimeOffset.FromUnixTimeSeconds(timeStamp).UtcDateTime;
}

/// <summary>
Expand Down
33 changes: 33 additions & 0 deletions Testing/UnitTests/Tests/Helpers/WeatherHelperTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using NUnit.Framework;
using SPTarkov.Server.Core.Helpers;

namespace UnitTests.Tests.Helpers;

[TestFixture]
public class WeatherHelperTests
{
private WeatherHelper _weatherHelper;

[OneTimeSetUp]
public void Initialize()
{
_weatherHelper = DI.GetInstance().GetService<WeatherHelper>();
}

[TestCase(1755621231, 22, 56, 57)]
[TestCase(1754120368, 8, 36, 16)]
[TestCase(1714120368, 14, 49, 36)]
[TestCase(1724120368, 19, 16, 16)]
public void GetInRaidTime_WithDifferentTimestamps_ExpectCorrectEFTTime(
long timestamp,
int expectedHour,
int expectedMinute,
int expectedSecond)
{
var timeOutput = _weatherHelper.GetInRaidTime(timestamp);

Assert.AreEqual(expectedHour, timeOutput.Hour, $"Unexpected hour! {timeOutput.Hour}");
Assert.AreEqual(expectedMinute, timeOutput.Minute, $"Unexpected minute! {timeOutput.Minute}");
Assert.AreEqual(expectedSecond, timeOutput.Second, $"Unexpected second! {timeOutput.Second}");
}
}
Loading