Skip to content

Commit

Permalink
Update AdvancedSpecification.cs.txt
Browse files Browse the repository at this point in the history
  • Loading branch information
neozhu committed Oct 3, 2024
1 parent 64bc852 commit df6e916
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/Templates/Specifications/AdvancedSpecification.cs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,23 @@ public class {itemname}AdvancedSpecification : Specification<{itemname}>
{
var timezoneOffset = filter.LocalTimezoneOffset;
var utcNow = DateTime.UtcNow;
var localNow = utcNow.Date.AddHours(timezoneOffset);
var startOfTodayLocalAsUtc = localNow;
var endOfTodayLocalAsUtc = localNow.AddDays(1);
var startOfLast30DaysLocalAsUtc = localNow.AddDays(-30);
// Corrected: Add the time zone offset to UTC time to get local time
var localNow = utcNow.AddHours(timezoneOffset);

// Calculate the start and end of today in local time
var startOfTodayLocal = localNow.Date;
var endOfTodayLocal = startOfTodayLocal.AddDays(1);
var startOfLast30DaysLocal = startOfTodayLocal.AddDays(-30);

// Convert local times back to UTC to match the TimeStamp's time zone
var startOfTodayLocalAsUtc = startOfTodayLocal.AddHours(-timezoneOffset);
var endOfTodayLocalAsUtc = endOfTodayLocal.AddHours(-timezoneOffset);
var startOfLast30DaysLocalAsUtc = startOfLast30DaysLocal.AddHours(-timezoneOffset);

Query.Where(q => q.Name != null)
.Where(filter.Keyword,!string.IsNullOrEmpty(filter.Keyword))
.Where(q => q.CreatedBy == filter.CurrentUser.UserId, filter.ListView == {itemname}ListView.My && filter.CurrentUser is not null)
.Where(q => q.Created >= startOfTodayLocalAsUtc && q.Created <= endOfTodayLocalAsUtc, filter.ListView == {itemname}ListView.CreatedToday)
.Where(q => q.Created >= startOfTodayLocalAsUtc && q.Created < endOfTodayLocalAsUtc, filter.ListView == {itemname}ListView.CreatedToday)
.Where(q => q.Created >= startOfLast30DaysLocalAsUtc, filter.ListView == {itemname}ListView.Created30Days);

}
Expand Down

0 comments on commit df6e916

Please sign in to comment.