Skip to content

Commit

Permalink
Tidy up from review
Browse files Browse the repository at this point in the history
  • Loading branch information
danielmackay committed May 5, 2024
1 parent e069e8f commit 2ffeafc
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 29 deletions.
10 changes: 10 additions & 0 deletions src/WebUI/Common/Services/SydneyTimeProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace WebUI.Common.Services;

public class SydneyTimeProvider : TimeProvider
{
private const string Timezone = "AUS Eastern Standard Time";

private readonly TimeZoneInfo _sydneyTimeZone = TimeZoneInfo.FindSystemTimeZoneById(Timezone);

public override TimeZoneInfo LocalTimeZone => _sydneyTimeZone;
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
namespace WebUI.Common.Services;

// Problem: Issue is that DateTime.Now could be different depending on where the code is running
// Solution: Force 'now' to be based on AEST, then converted to UTC

public class SydneyTimeProvider : TimeProvider
{
private const string Timezone = "AUS Eastern Standard Time";

private readonly TimeZoneInfo _sydneyTimeZone = TimeZoneInfo.FindSystemTimeZoneById(Timezone);

public override TimeZoneInfo LocalTimeZone => _sydneyTimeZone;
}

public static class TimeProviderExt
{
public static DateOnly GetToday(this TimeProvider timeProvider)
Expand Down Expand Up @@ -45,4 +33,4 @@ public static DateTime GetEndOfDayUtc(this TimeProvider timeProvider, DateOnly d

return endOfDayUtc;
}
}
}
3 changes: 0 additions & 3 deletions src/WebUI/Features/DailyScrum/Queries/GetDailyScrumQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@

namespace WebUI.Features.DailyScrum.Queries;

// TODO: Timezones are still not matching up. locally UTC times are working (i.e. in the middle of the day),
// But on docker they are from midnight to midnight (which is not correct)

public record GetDailyScrumQuery(string Name, int? ClientDays, DateOnly? LastWorkingDay)
: IRequest<DailyScrumViewModel>;

Expand Down
16 changes: 16 additions & 0 deletions tests/UnitTests/SydneyTimeProviderTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using FluentAssertions;
using WebUI.Common.Services;

namespace UnitTests;

public class SydneyTimeProviderTests
{
[Fact]
public void GetLocalNow_ReturnsSydneyTime()
{
var sut = new SydneyTimeProvider();
var localNow = DateTimeOffset.Now;
var result = sut.GetLocalNow();
result.Should().BeCloseTo(localNow, precision: TimeSpan.FromSeconds(5));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,6 @@

namespace UnitTests;

public class SydneyTimeProviderTests
{
[Fact]
public void GetLocalNow_ReturnsSydneyTime()
{
var sut = new SydneyTimeProvider();
var localNow = DateTimeOffset.Now;
var result = sut.GetLocalNow();
result.Should().BeCloseTo(localNow, precision: TimeSpan.FromSeconds(5));
}
}

public class TimeProviderExtTests
{
[Fact]
Expand Down Expand Up @@ -46,4 +34,4 @@ public void GetEndOfDayUtc_GivenSydneyTimeZone_ReturnsCorrectUtc()



}
}

0 comments on commit 2ffeafc

Please sign in to comment.