fix(app): дата без времени парсится как UTC, а не в локальной зоне
DateTime.tryParse("2026-09-18") в Dart возвращает локальное время, не UTC —
на MSK (UTC+3) это трёхчасовой сдвиг относительно того, что сервер имел
в виду датой без времени. asDate() перетэговывает те же значения полей как
UTC вместо доверия tryParse; настоящий таймстемп с "Z"/смещением проходит
насквозь без изменений.
This commit is contained in:
@@ -29,7 +29,23 @@ bool asBool(Object? v) => v == true;
|
|||||||
DateTime? asDate(Object? v) {
|
DateTime? asDate(Object? v) {
|
||||||
final s = asString(v);
|
final s = asString(v);
|
||||||
if (s == null || s.isEmpty) return null;
|
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.
|
/// A list of JSON objects; anything else (including null) becomes an empty list.
|
||||||
|
|||||||
Reference in New Issue
Block a user