From 8eee6380e9da2c2e6987bfb354bb2e104b93d5df Mon Sep 17 00:00:00 2001 From: alireza Date: Sat, 17 Oct 2026 16:21:40 +0330 Subject: [PATCH] fix(poweroutage): derive Persian dates from the naive-UTC wall-clock PowerOutageLogService called ToPersianDate on Kind=Utc values, which converts to the machine-local timezone inside PersianDateHelper. That now also happens on the DB-read path because Postgres DateTime columns are timestamptz and read back as Kind=Utc. Normalize to Unspecified first - the rule TelemetryService already applies - so the stored PersianDate does not shift with the server timezone. --- .../Services/PowerOutage/PowerOutageLogService.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/GreenHome.Infrastructure/Services/PowerOutage/PowerOutageLogService.cs b/src/GreenHome.Infrastructure/Services/PowerOutage/PowerOutageLogService.cs index b19e0d0..cbd5024 100644 --- a/src/GreenHome.Infrastructure/Services/PowerOutage/PowerOutageLogService.cs +++ b/src/GreenHome.Infrastructure/Services/PowerOutage/PowerOutageLogService.cs @@ -16,7 +16,10 @@ public sealed class PowerOutageLogService : IPowerOutageLogService public async Task LogPowerChangeAsync(int deviceId, byte previousPower, byte currentPower, DateTime timestampUtc, CancellationToken cancellationToken) { - var (year, month, day, persianDate) = timestampUtc.ToPersianDate(); + // derive the Persian date from the naive-UTC wall-clock, not the machine-local time, + // so it does not shift with the server timezone (same rule as TelemetryService). + var (year, month, day, persianDate) = + DateTime.SpecifyKind(timestampUtc, DateTimeKind.Unspecified).ToPersianDate(); var log = new Domain.PowerOutageLog { @@ -133,7 +136,8 @@ public sealed class PowerOutageLogService : IPowerOutageLogService if (previousLog != null && previousLog.CurrentPower != record.Power) { // Power status changed - insert a log - var (year, month, day, persianDate) = record.TimestampUtc.ToPersianDate(); + var (year, month, day, persianDate) = + DateTime.SpecifyKind(record.TimestampUtc, DateTimeKind.Unspecified).ToPersianDate(); var log = new Domain.PowerOutageLog {