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.
This commit is contained in:
@@ -16,7 +16,10 @@ public sealed class PowerOutageLogService : IPowerOutageLogService
|
|||||||
|
|
||||||
public async Task LogPowerChangeAsync(int deviceId, byte previousPower, byte currentPower, DateTime timestampUtc, CancellationToken cancellationToken)
|
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
|
var log = new Domain.PowerOutageLog
|
||||||
{
|
{
|
||||||
@@ -133,7 +136,8 @@ public sealed class PowerOutageLogService : IPowerOutageLogService
|
|||||||
if (previousLog != null && previousLog.CurrentPower != record.Power)
|
if (previousLog != null && previousLog.CurrentPower != record.Power)
|
||||||
{
|
{
|
||||||
// Power status changed - insert a log
|
// 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
|
var log = new Domain.PowerOutageLog
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user