Skip to content

Commit

Permalink
Fix DateTimeOffset.DateTime UTC bug (akkadotnet#7349)
Browse files Browse the repository at this point in the history
Co-authored-by: Aaron Stannard <aaron@petabridge.com>
  • Loading branch information
Arkatufus and Aaronontheweb authored Sep 30, 2024
1 parent c295010 commit 33fd92d
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,7 @@ namespace Akka.Actor
[System.ObsoleteAttribute("This class will be removed in Akka.NET v1.6.0 - use the IScheduler instead.")]
public class DateTimeOffsetNowTimeProvider : Akka.Actor.IDateTimeOffsetNowTimeProvider, Akka.Actor.ITimeProvider
{
public System.DateTime DateTimeNow { get; }
public System.TimeSpan HighResMonotonicClock { get; }
public static Akka.Actor.DateTimeOffsetNowTimeProvider Instance { get; }
public System.TimeSpan MonotonicClock { get; }
Expand Down Expand Up @@ -932,6 +933,7 @@ namespace Akka.Actor
public sealed class HashedWheelTimerScheduler : Akka.Actor.SchedulerBase, Akka.Actor.IDateTimeOffsetNowTimeProvider, Akka.Actor.ITimeProvider, System.IDisposable
{
public HashedWheelTimerScheduler(Akka.Configuration.Config scheduler, Akka.Event.ILoggingAdapter log) { }
protected override System.DateTime DateTimeNow { get; }
public override System.TimeSpan HighResMonotonicClock { get; }
public override System.TimeSpan MonotonicClock { get; }
protected override System.DateTimeOffset TimeNow { get; }
Expand Down Expand Up @@ -1172,6 +1174,7 @@ namespace Akka.Actor
}
public interface ITimeProvider
{
System.DateTime DateTimeNow { get; }
System.TimeSpan HighResMonotonicClock { get; }
System.TimeSpan MonotonicClock { get; }
System.DateTimeOffset Now { get; }
Expand Down Expand Up @@ -1622,6 +1625,7 @@ namespace Akka.Actor
protected readonly Akka.Event.ILoggingAdapter Log;
protected readonly Akka.Configuration.Config SchedulerConfig;
protected SchedulerBase(Akka.Configuration.Config scheduler, Akka.Event.ILoggingAdapter log) { }
protected abstract System.DateTime DateTimeNow { get; }
public abstract System.TimeSpan HighResMonotonicClock { get; }
public abstract System.TimeSpan MonotonicClock { get; }
protected abstract System.DateTimeOffset TimeNow { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,7 @@ namespace Akka.Actor
[System.ObsoleteAttribute("This class will be removed in Akka.NET v1.6.0 - use the IScheduler instead.")]
public class DateTimeOffsetNowTimeProvider : Akka.Actor.IDateTimeOffsetNowTimeProvider, Akka.Actor.ITimeProvider
{
public System.DateTime DateTimeNow { get; }
public System.TimeSpan HighResMonotonicClock { get; }
public static Akka.Actor.DateTimeOffsetNowTimeProvider Instance { get; }
public System.TimeSpan MonotonicClock { get; }
Expand Down Expand Up @@ -930,6 +931,7 @@ namespace Akka.Actor
public sealed class HashedWheelTimerScheduler : Akka.Actor.SchedulerBase, Akka.Actor.IDateTimeOffsetNowTimeProvider, Akka.Actor.ITimeProvider, System.IDisposable
{
public HashedWheelTimerScheduler(Akka.Configuration.Config scheduler, Akka.Event.ILoggingAdapter log) { }
protected override System.DateTime DateTimeNow { get; }
public override System.TimeSpan HighResMonotonicClock { get; }
public override System.TimeSpan MonotonicClock { get; }
protected override System.DateTimeOffset TimeNow { get; }
Expand Down Expand Up @@ -1170,6 +1172,7 @@ namespace Akka.Actor
}
public interface ITimeProvider
{
System.DateTime DateTimeNow { get; }
System.TimeSpan HighResMonotonicClock { get; }
System.TimeSpan MonotonicClock { get; }
System.DateTimeOffset Now { get; }
Expand Down Expand Up @@ -1620,6 +1623,7 @@ namespace Akka.Actor
protected readonly Akka.Event.ILoggingAdapter Log;
protected readonly Akka.Configuration.Config SchedulerConfig;
protected SchedulerBase(Akka.Configuration.Config scheduler, Akka.Event.ILoggingAdapter log) { }
protected abstract System.DateTime DateTimeNow { get; }
public abstract System.TimeSpan HighResMonotonicClock { get; }
public abstract System.TimeSpan MonotonicClock { get; }
protected abstract System.DateTimeOffset TimeNow { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,7 @@ namespace Akka.TestKit
{
public TestScheduler(Akka.Configuration.Config schedulerConfig, Akka.Event.ILoggingAdapter log) { }
public Akka.Actor.IAdvancedScheduler Advanced { get; }
public System.DateTime DateTimeNow { get; }
public System.TimeSpan HighResMonotonicClock { get; }
public System.TimeSpan MonotonicClock { get; }
public System.DateTimeOffset Now { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,7 @@ namespace Akka.TestKit
{
public TestScheduler(Akka.Configuration.Config schedulerConfig, Akka.Event.ILoggingAdapter log) { }
public Akka.Actor.IAdvancedScheduler Advanced { get; }
public System.DateTime DateTimeNow { get; }
public System.TimeSpan HighResMonotonicClock { get; }
public System.TimeSpan MonotonicClock { get; }
public System.DateTimeOffset Now { get; }
Expand Down
2 changes: 1 addition & 1 deletion src/core/Akka.Persistence/Eventsourced.cs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ public void LoadSnapshot(string persistenceId, SnapshotSelectionCriteria criteri
/// <param name="snapshot">TBD</param>
public void SaveSnapshot(object snapshot)
{
SnapshotStore.Tell(new SaveSnapshot(new SnapshotMetadata(SnapshotterId, SnapshotSequenceNr, Context.System.Scheduler.Now.Date), snapshot));
SnapshotStore.Tell(new SaveSnapshot(new SnapshotMetadata(SnapshotterId, SnapshotSequenceNr, Context.System.Scheduler.DateTimeNow), snapshot));
}

/// <summary>
Expand Down
4 changes: 4 additions & 0 deletions src/core/Akka.TestKit/TestScheduler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,10 @@ public void ScheduleRepeatedly(TimeSpan initialDelay, TimeSpan interval, Action
/// <summary>
/// TBD
/// </summary>
public DateTime DateTimeNow { get { return DateTime.SpecifyKind(_now.DateTime, DateTimeKind.Utc); } }
/// <summary>
/// TBD
/// </summary>
public TimeSpan MonotonicClock { get { return Util.MonotonicClock.Elapsed; } }
/// <summary>
/// TBD
Expand Down
1 change: 1 addition & 0 deletions src/core/Akka.Tests/Actor/ActorSystemSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,7 @@ public void ScheduleTellRepeatedly(TimeSpan initialDelay, TimeSpan interval, ICa
}

public DateTimeOffset Now { get; private set; }
public DateTime DateTimeNow { get; private set; }
public TimeSpan MonotonicClock { get; private set; }
public TimeSpan HighResMonotonicClock { get; private set; }
public IAdvancedScheduler Advanced { get; private set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ private class ShutdownScheduler : SchedulerBase, IDisposable


protected override DateTimeOffset TimeNow { get; }
protected override DateTime DateTimeNow { get; }
public override TimeSpan MonotonicClock { get; }
public override TimeSpan HighResMonotonicClock { get; }

Expand Down
2 changes: 2 additions & 0 deletions src/core/Akka/Actor/Scheduler/DateTimeNowTimeProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ private DateTimeOffsetNowTimeProvider() { }

public DateTimeOffset Now { get { return DateTimeOffset.UtcNow; } }

public DateTime DateTimeNow => DateTime.UtcNow;

public TimeSpan MonotonicClock {get { return Util.MonotonicClock.Elapsed; }}

public TimeSpan HighResMonotonicClock{get { return Util.MonotonicClock.ElapsedHighRes; }}
Expand Down
5 changes: 5 additions & 0 deletions src/core/Akka/Actor/Scheduler/HashedWheelTimerScheduler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,11 @@ private void PlaceInBucket(SchedulerRegistration reg)
/// </summary>
protected override DateTimeOffset TimeNow => DateTimeOffset.UtcNow;

/// <summary>
/// TBD
/// </summary>
protected override DateTime DateTimeNow => DateTime.UtcNow;

/// <summary>
/// TBD
/// </summary>
Expand Down
6 changes: 5 additions & 1 deletion src/core/Akka/Actor/Scheduler/ITimeProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,14 @@ namespace Akka.Actor
public interface ITimeProvider
{
/// <summary>
/// Gets the scheduler's notion of current time.
/// Gets the scheduler's notion of current time in <see cref="DateTimeOffset"/>.
/// </summary>
DateTimeOffset Now { get; }
/// <summary>
/// Gets the scheduler's notion of current time in <see cref="DateTime"/>.
/// </summary>
DateTime DateTimeNow { get; }
/// <summary>
/// TBD
/// </summary>
TimeSpan MonotonicClock { get; }
Expand Down
9 changes: 8 additions & 1 deletion src/core/Akka/Actor/Scheduler/SchedulerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,18 @@ void IActionScheduler.ScheduleRepeatedly(TimeSpan initialDelay, TimeSpan interva
IAdvancedScheduler IScheduler.Advanced { get { return this; } }
DateTimeOffset ITimeProvider.Now { get { return TimeNow; } }

DateTime ITimeProvider.DateTimeNow => DateTime.SpecifyKind(TimeNow.DateTime, DateTimeKind.Utc);

/// <summary>
/// The current time in UTC.
/// The current time in <see cref="DateTimeOffset"/> UTC.
/// </summary>
protected abstract DateTimeOffset TimeNow { get; }

/// <summary>
/// The current time in <see cref="DateTime"/> UTC.
/// </summary>
protected abstract DateTime DateTimeNow { get; }

/// <summary>
/// The current time since startup, as determined by the monotonic clock implementation.
/// </summary>
Expand Down

0 comments on commit 33fd92d

Please sign in to comment.