diff --git a/src/Templates/Pages/.razor.txt b/src/Templates/Pages/.razor.txt index 2051e69..b166454 100644 --- a/src/Templates/Pages/.razor.txt +++ b/src/Templates/Pages/.razor.txt @@ -203,6 +203,8 @@ private Task AuthState { get; set; } = default!; [CascadingParameter] private UserProfile? UserProfile { get; set; } + [CascadingParameter(Name = "LocalTimezoneOffset")] + private int _localTimezoneOffset { get; set; } private {nameofPlural}WithPaginationQuery Query { get; set; } = new(); [Inject] @@ -235,6 +237,7 @@ Query.SortDirection = state.SortDefinitions.FirstOrDefault()?.Descending ?? true ? SortDirection.Descending.ToString() : SortDirection.Ascending.ToString(); Query.PageNumber = state.Page + 1; Query.PageSize = state.PageSize; + Query.LocalTimezoneOffset = _localTimezoneOffset; var result = await Mediator.Send(Query).ConfigureAwait(false); return new GridData<{itemname}Dto>() { TotalItems = result.TotalItems, Items = result.Items }; } diff --git a/src/Templates/Queries/Pagination/.cs.txt b/src/Templates/Queries/Pagination/.cs.txt index 7baf3a4..ca3bebd 100644 --- a/src/Templates/Queries/Pagination/.cs.txt +++ b/src/Templates/Queries/Pagination/.cs.txt @@ -11,7 +11,7 @@ public class {nameofPlural}WithPaginationQuery : {itemname}AdvancedFilter, ICach { public override string ToString() { - return $"Listview:{ListView}, Search:{Keyword}, {OrderBy}, {SortDirection}, {PageNumber}, {PageSize}"; + return $"Listview:{ListView}-{LocalTimezoneOffset}, Search:{Keyword}, {OrderBy}, {SortDirection}, {PageNumber}, {PageSize}"; } public string CacheKey => {itemname}CacheKey.GetPaginationCacheKey($"{this}"); public MemoryCacheEntryOptions? Options => {itemname}CacheKey.MemoryCacheEntryOptions; diff --git a/src/Templates/Specifications/AdvancedFilter.cs.txt b/src/Templates/Specifications/AdvancedFilter.cs.txt index 4f0ace9..7266b60 100644 --- a/src/Templates/Specifications/AdvancedFilter.cs.txt +++ b/src/Templates/Specifications/AdvancedFilter.cs.txt @@ -20,6 +20,7 @@ public enum {itemname}ListView /// public class {itemname}AdvancedFilter: PaginationFilter { + public int LocalTimezoneOffset { get; set; } public {itemname}ListView ListView { get; set; } = {itemname}ListView.All; public UserProfile? CurrentUser { get; set; } } \ No newline at end of file diff --git a/src/Templates/Specifications/AdvancedSpecification.cs.txt b/src/Templates/Specifications/AdvancedSpecification.cs.txt index 8b3f54d..00c1b92 100644 --- a/src/Templates/Specifications/AdvancedSpecification.cs.txt +++ b/src/Templates/Specifications/AdvancedSpecification.cs.txt @@ -7,20 +7,18 @@ public class {itemname}AdvancedSpecification : Specification<{itemname}> { public {itemname}AdvancedSpecification({itemname}AdvancedFilter filter) { - var today = DateTime.Now.ToUniversalTime().Date; - var start = Convert.ToDateTime(today.ToString("yyyy-MM-dd", CultureInfo.CurrentCulture) + " 00:00:00", - CultureInfo.CurrentCulture); - var end = Convert.ToDateTime(today.ToString("yyyy-MM-dd", CultureInfo.CurrentCulture) + " 23:59:59", - CultureInfo.CurrentCulture); - var last30day = Convert.ToDateTime( - today.AddDays(-30).ToString("yyyy-MM-dd", CultureInfo.CurrentCulture) + " 00:00:00", - CultureInfo.CurrentCulture); + 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); Query.Where(q => q.Name != null) - .Where(q => q.Name!.Contains(filter.Keyword) || q.Description!.Contains(filter.Keyword), !string.IsNullOrEmpty(filter.Keyword)) + .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 >= start && q.Created <= end, filter.ListView == {itemname}ListView.CreatedToday) - .Where(q => q.Created >= last30day, filter.ListView == {itemname}ListView.Created30Days); + .Where(q => q.Created >= startOfTodayLocalAsUtc && q.Created <= endOfTodayLocalAsUtc, filter.ListView == {itemname}ListView.CreatedToday) + .Where(q => q.Created >= startOfLast30DaysLocalAsUtc, filter.ListView == {itemname}ListView.Created30Days); } }