Skip to content

Commit

Permalink
Fix timestamp generation on non-windows
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanmoffat committed May 9, 2023
1 parent 8e05a27 commit 2ff8af3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
7 changes: 1 addition & 6 deletions EOLib/GameStartTimeRepository.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
using AutomaticTypeMapper;
using System;
using System.Diagnostics;

namespace EOLib
{
public interface IGameStartTimeProvider
{
DateTime StartTime { get; }

Stopwatch Elapsed { get; }

int TimeStamp { get; }
Expand All @@ -16,10 +13,8 @@ public interface IGameStartTimeProvider
[AutoMappedType(IsSingleton = true)]
public class GameStartTimeRepository : IGameStartTimeProvider
{
public DateTime StartTime { get; } = DateTime.UtcNow;

public Stopwatch Elapsed { get; } = Stopwatch.StartNew();

public int TimeStamp => StartTime.ToEOTimeStamp(Elapsed.ElapsedTicks);
public int TimeStamp => Elapsed.ToEOTimeStamp();
}
}
7 changes: 4 additions & 3 deletions EOLib/misc.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Diagnostics;

namespace EOLib
{
Expand All @@ -20,10 +21,10 @@ public static T[] SubArray<T>(this T[] arr, int offset, int count)

public static class DateTimeExtension
{
public static int ToEOTimeStamp(this DateTime dt, long elapsedTicks)
public static int ToEOTimeStamp(this Stopwatch sw)
{
dt = dt.Add(TimeSpan.FromTicks(elapsedTicks));
return dt.Hour * 360000 + dt.Minute * 6000 + dt.Second * 100 + dt.Millisecond / 10;
var elapsedHundreths = Math.Round(sw.ElapsedTicks / (Stopwatch.Frequency / 100.0));
return (int)elapsedHundreths;
}
}

Expand Down

0 comments on commit 2ff8af3

Please sign in to comment.