fix(app): дата без времени парсится как UTC, а не в локальной зоне

DateTime.tryParse("2026-09-18") в Dart возвращает локальное время, не UTC —
на MSK (UTC+3) это трёхчасовой сдвиг относительно того, что сервер имел
в виду датой без времени. asDate() перетэговывает те же значения полей как
UTC вместо доверия tryParse; настоящий таймстемп с "Z"/смещением проходит
насквозь без изменений.
This commit is contained in:
Dmitry
2026-09-19 10:56:42 +03:00
parent baac83149f
commit df49d99af4
+17 -1
View File
@@ -29,7 +29,23 @@ bool asBool(Object? v) => v == true;
DateTime? asDate(Object? v) {
final s = asString(v);
if (s == null || s.isEmpty) return null;
return DateTime.tryParse(s);
final parsed = DateTime.tryParse(s);
if (parsed == null) return null;
// A plain date ("2026-09-18") has no timezone of its own; `DateTime.tryParse` still
// tags it local, which silently shifts it by the machine's offset. Re-tag the same
// wall-clock fields as UTC so the date this API meant is the date callers get, on any
// machine — a full timestamp (already carrying "Z"/an offset) is left untouched.
if (parsed.isUtc) return parsed;
return DateTime.utc(
parsed.year,
parsed.month,
parsed.day,
parsed.hour,
parsed.minute,
parsed.second,
parsed.millisecond,
parsed.microsecond,
);
}
/// A list of JSON objects; anything else (including null) becomes an empty list.