fix: normalize DateTimeOffset to UTC in DashboardService to fix Npgsql offset rejection
DashboardService was constructing 'today in Beijing' bounds with a +08:00 offset, which Npgsql rejects when binding to a timestamp with time zone column. Added .ToUniversalTime() to normalize to UTC (same instant, offset 0), matching the existing pattern in SessionAnalyticsService.GetUtcWindow.
This commit is contained in:
@@ -40,8 +40,10 @@ public sealed class DashboardService
|
||||
var now = DateTimeOffset.UtcNow;
|
||||
var beijingNow = ChinaTime.ToBeijingTime(now);
|
||||
var todayBeijingDate = DateOnly.FromDateTime(beijingNow.DateTime);
|
||||
var todayUtcStart = new DateTimeOffset(todayBeijingDate.ToDateTime(TimeOnly.MinValue), ChinaTime.Zone.GetUtcOffset(beijingNow.DateTime));
|
||||
var todayUtcEnd = new DateTimeOffset(todayBeijingDate.ToDateTime(TimeOnly.MaxValue), ChinaTime.Zone.GetUtcOffset(beijingNow.DateTime));
|
||||
// Bound "today in Beijing" but normalize to UTC — Npgsql only accepts offset 0
|
||||
// when writing to a `timestamp with time zone` column.
|
||||
var todayUtcStart = new DateTimeOffset(todayBeijingDate.ToDateTime(TimeOnly.MinValue), ChinaTime.Zone.GetUtcOffset(beijingNow.DateTime)).ToUniversalTime();
|
||||
var todayUtcEnd = new DateTimeOffset(todayBeijingDate.ToDateTime(TimeOnly.MaxValue), ChinaTime.Zone.GetUtcOffset(beijingNow.DateTime)).ToUniversalTime();
|
||||
var recentErrorSince = now.AddHours(-24);
|
||||
|
||||
// Run queries sequentially — DbContext is not thread-safe
|
||||
|
||||
Reference in New Issue
Block a user