From f8abae0a7a774022e9875febb95f5b83757b4f33 Mon Sep 17 00:00:00 2001 From: nanxun Date: Sun, 21 Jun 2026 00:01:03 +0800 Subject: [PATCH] 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. --- src/LiveRecorder.Application/Services/DashboardService.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/LiveRecorder.Application/Services/DashboardService.cs b/src/LiveRecorder.Application/Services/DashboardService.cs index 681d9ba..789d97a 100644 --- a/src/LiveRecorder.Application/Services/DashboardService.cs +++ b/src/LiveRecorder.Application/Services/DashboardService.cs @@ -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