Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

_localTimezoneOffset #94

Merged
merged 1 commit into from
Oct 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Templates/Pages/.razor.txt
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@
[CascadingParameter]
private UserProfile? UserProfile { get; set; }
[CascadingParameter(Name = "LocalTimezoneOffset")]
private int _localTimezoneOffset { get; set; }
private TimeSpan _localTimezoneOffset { get; set; }

private {nameofPlural}WithPaginationQuery Query { get; set; } = new();
[Inject]
Expand Down
2 changes: 1 addition & 1 deletion src/Templates/Queries/Pagination/.cs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class {nameofPlural}WithPaginationQuery : {itemname}AdvancedFilter, ICach
{
public override string ToString()
{
return $"Listview:{ListView}-{LocalTimezoneOffset}, Search:{Keyword}, {OrderBy}, {SortDirection}, {PageNumber}, {PageSize}";
return $"Listview:{ListView}-{LocalTimezoneOffset.TotalHours}, Search:{Keyword}, {OrderBy}, {SortDirection}, {PageNumber}, {PageSize}";
}
public string CacheKey => {itemname}CacheKey.GetPaginationCacheKey($"{this}");
public MemoryCacheEntryOptions? Options => {itemname}CacheKey.MemoryCacheEntryOptions;
Expand Down
6 changes: 3 additions & 3 deletions src/Templates/Specifications/AdvancedFilter.cs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ public enum {itemname}ListView
[Description("My")]
My,
[Description("Created Toady")]
CreatedToday,
TODAY,
[Description("Created within the last 30 days")]
Created30Days
LAST_30_DAYS
}
/// <summary>
/// A class for applying advanced filtering options to {itemname} lists.
/// </summary>
public class {itemname}AdvancedFilter: PaginationFilter
{
public int LocalTimezoneOffset { get; set; }
public TimeSpan LocalTimezoneOffset { get; set; }
public {itemname}ListView ListView { get; set; } = {itemname}ListView.All;
public UserProfile? CurrentUser { get; set; }
}
23 changes: 6 additions & 17 deletions src/Templates/Specifications/AdvancedSpecification.cs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,15 @@ public class {itemname}AdvancedSpecification : Specification<{itemname}>
{
public {itemname}AdvancedSpecification({itemname}AdvancedFilter filter)
{
var timezoneOffset = filter.LocalTimezoneOffset;
var utcNow = DateTime.UtcNow;
// Corrected: Add the time zone offset to UTC time to get local time
var localNow = utcNow.AddHours(timezoneOffset);
DateTime today = DateTime.UtcNow;
var todayrange = today.GetDateRange({itemname}ListView.TODAY.ToString(), filter.LocalTimezoneOffset);
var last30daysrange = today.GetDateRange({itemname}ListView.LAST_30_DAYS.ToString(),filter.LocalTimezoneOffset);

// 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)
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 >= startOfLast30DaysLocalAsUtc, filter.ListView == {itemname}ListView.Created30Days);
.Where(x => x.Created >= todayrange.Start && x.Created < todayrange.End.AddDays(1), filter.ListView == {itemname}ListView.TODAY)
.Where(x => x.Created >= last30daysrange.Start, filter.ListView == {itemname}ListView.LAST_30_DAYS);

}
}
Loading