Skip to content
This repository has been archived by the owner on Apr 8, 2023. It is now read-only.

Commit

Permalink
Change dates to be timezone aware. (#195)
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminsampica authored Mar 17, 2023
1 parent ff44afe commit 2839ca7
Show file tree
Hide file tree
Showing 30 changed files with 783 additions and 81 deletions.
4 changes: 2 additions & 2 deletions src/Client/Features/FreeAgents/Detail/BidCountdown.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace DynamoLeagueBlazor.Client.Features.FreeAgents.Detail;

public partial class BidCountdown
{
[Parameter, EditorRequired] public DateTime DateTime { get; set; }
[Parameter, EditorRequired] public DateTimeOffset DateTime { get; set; }

private readonly Timer _timer = new(1000);
private string _remainingTime = string.Empty;
Expand All @@ -21,7 +21,7 @@ protected override void OnInitialized()

private void CountDown(object? source, ElapsedEventArgs e)
{
var remainingTime = DateTime - DateTime.Now;
var remainingTime = DateTime - DateTimeOffset.UtcNow;

if (remainingTime <= TimeSpan.FromDays(1))
{
Expand Down
2 changes: 1 addition & 1 deletion src/Client/Features/FreeAgents/List.razor
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
<MudTd DataLabel="Player Position">@context.Position</MudTd>
<MudTd DataLabel="Player Team">@context.Team</MudTd>
<MudTd DataLabel="Bidding Ends">
@context.BiddingEnds.ToShortDateString()
@context.BiddingEnds.LocalDateTime.ToShortDateString()
</MudTd>
<MudTd DataLabel="Highest Bid">
<span>
Expand Down
2 changes: 1 addition & 1 deletion src/Client/Features/Rules/Cost.razor
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Dues <b>must</b> be paid by January 1st each season. If an owner does not pay by one week before the season, that owner will be removed from the league.
<br /><br />
<MudGrid Spacing=1>
@foreach(var year in Enumerable.Range(DateTime.Today.Year, 5))
@foreach(var year in Enumerable.Range(DateTimeOffset.UtcNow.Year, 5))
{
var date = new DateOnly(year, 1, 1);

Expand Down
10 changes: 5 additions & 5 deletions src/Server/Features/Admin/StartSeason.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ public record StartSeasonCommand : IRequest { }
public class StartSeasonHandler : IRequestHandler<StartSeasonCommand>
{
private readonly ApplicationDbContext _dbContext;
private readonly DateTime _boundaryStartDate = new(DateTime.Today.Year, 6, 25);
private readonly DateTime _boundaryEndDate = new(DateTime.Today.Year, 8, 20);
private readonly DateTimeOffset _boundaryStartDate = new(DateTimeOffset.UtcNow.Year, 6, 25, 0, 0, 0, TimeSpan.Zero);
private readonly DateTimeOffset _boundaryEndDate = new(DateTimeOffset.UtcNow.Year, 8, 20, 0, 0, 0, TimeSpan.Zero);

public StartSeasonHandler(ApplicationDbContext dbContext)
{
Expand All @@ -66,7 +66,7 @@ public async Task Handle(StartSeasonCommand request, CancellationToken cancellat
var random = new Random();

var players = _dbContext.Players
.Where(p => p.YearContractExpires < DateTime.Today.Year)
.Where(p => p.YearContractExpires < DateTimeOffset.UtcNow.Year)
.AsTracking();

foreach (var player in players)
Expand All @@ -76,14 +76,14 @@ public async Task Handle(StartSeasonCommand request, CancellationToken cancellat
player.BeginNewSeason(endOfFreeAgency);
}

var startOfTheCurrentYear = new DateTime(DateTime.Today.Year, 1, 1);
var startOfTheCurrentYear = new DateTimeOffset(DateTimeOffset.UtcNow.Year, 1, 1, 0, 0, 0, TimeSpan.Zero);
var fines = _dbContext.Fines.Where(f => f.CreatedOn < startOfTheCurrentYear);
_dbContext.Fines.RemoveRange(fines);

await _dbContext.SaveChangesAsync(cancellationToken);
}

private static DateTime GetRandomBoundariedDate(Random seed, DateTime boundaryStartDate, DateTime boundaryEndDate)
private static DateTimeOffset GetRandomBoundariedDate(Random seed, DateTimeOffset boundaryStartDate, DateTimeOffset boundaryEndDate)
{
var maximumDaysToAdd = (boundaryEndDate - boundaryStartDate).Days;
var daysToAdd = seed.Next(maximumDaysToAdd);
Expand Down
2 changes: 1 addition & 1 deletion src/Server/Features/FreeAgents/Detail/AddBid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public async Task<bool> HasNotEndedAsync(AddBidRequest request, CancellationToke
{
var player = await _dbContext.Players.FindAsync(new object[] { request.PlayerId }, cancellationToken);

var hasNotEnded = player!.EndOfFreeAgency > DateTime.Now;
var hasNotEnded = player!.EndOfFreeAgency > DateTimeOffset.UtcNow;

return hasNotEnded;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Server/Features/FreeAgents/EndBidding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public async Task Invoke()
var players = await _dbContext.Players
.AsTracking()
.Where(p => p.State == PlayerState.FreeAgent
&& p.EndOfFreeAgency <= DateTime.Now)
&& p.EndOfFreeAgency <= DateTimeOffset.UtcNow)
.ToListAsync();

if (!players.Any()) return;
Expand Down
2 changes: 1 addition & 1 deletion src/Server/Features/OfferMatching/ExpireOfferMatching.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public async Task Invoke()
.AsTracking()
.Include(p => p.Bids)
.Where(p => p.State == PlayerState.OfferMatching
&& p.EndOfFreeAgency!.Value.AddDays(3) <= DateTime.Today)
&& p.EndOfFreeAgency!.Value.AddDays(3) <= DateTimeOffset.UtcNow)
.ToListAsync();

if (!players.Any()) return;
Expand Down
2 changes: 1 addition & 1 deletion src/Server/Features/Teams/List.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ await Parallel.ForEachAsync(teams, async (team, cancellationToken) =>

var unsignedPlayersContractValue = await unsignedPlayersQuery.SumAsync(rp => rp.ContractValue, cancellationToken);

team.CapSpace = CapSpaceUtilities.GetRemainingCapSpace(DateOnly.FromDateTime(DateTime.Today), rosteredPlayersContractValue, unrosteredPlayersContractValue, unsignedPlayersContractValue).ToString("C0");
team.CapSpace = CapSpaceUtilities.GetRemainingCapSpace(DateOnly.FromDateTime(DateTimeOffset.UtcNow.DateTime), rosteredPlayersContractValue, unrosteredPlayersContractValue, unsignedPlayersContractValue).ToString("C0");
});

return new TeamListResult
Expand Down
Loading

0 comments on commit 2839ca7

Please sign in to comment.