fix(admin-ui): pure-date парсинг как local midnight (защита TZ западнее UTC)
format=date поля приходят как 'YYYY-MM-DD' без времени. new Date(s) интерпретирует их как UTC-midnight. В TZ западнее UTC (UTC-5 etc.) local Date уезжает на день назад → getDate() возвращает (день-1). Сейчас pure-date строки регексим и собираем через Date(y, m-1, d) — всегда local midnight. Datetime строки парсятся как раньше.
This commit is contained in:
@@ -51,7 +51,12 @@ const humanize = (key: string): string =>
|
|||||||
|
|
||||||
const parseFormDate = (s: unknown): Date | null => {
|
const parseFormDate = (s: unknown): Date | null => {
|
||||||
if (typeof s !== 'string' || !s) return null
|
if (typeof s !== 'string' || !s) return null
|
||||||
const d = new Date(s)
|
// Pure date "YYYY-MM-DD" парсим как локальную полуночь, иначе для TZ западнее
|
||||||
|
// UTC new Date() уедет на день назад. Для строк с временем — стандартный парс.
|
||||||
|
const pureDate = /^(\d{4})-(\d{2})-(\d{2})$/.exec(s)
|
||||||
|
const d = pureDate
|
||||||
|
? new Date(Number(pureDate[1]), Number(pureDate[2]) - 1, Number(pureDate[3]))
|
||||||
|
: new Date(s)
|
||||||
if (Number.isNaN(d.getTime())) return null
|
if (Number.isNaN(d.getTime())) return null
|
||||||
if (d.getFullYear() >= 9999) return null
|
if (d.getFullYear() >= 9999) return null
|
||||||
return d
|
return d
|
||||||
|
|||||||
Reference in New Issue
Block a user