fix(ui): DatePicker off-by-one в TZ != UTC

This commit is contained in:
Александр Зимин
2026-06-20 21:37:05 +00:00
parent b28c0f6ede
commit a82b520952
@@ -1,6 +1,7 @@
import * as React from 'react'
import { Input } from './input'
import { FieldLabel, FieldHint, FieldError } from './field'
import { formatIsoDate, parseFormDate } from '@/lib/dates'
import { cn } from '@/lib/utils'
/**
@@ -32,10 +33,13 @@ export type DatePickerProps = {
inputClassName?: string
}
// Local-TZ форматирование. toISOString().slice(0,10) на Date в TZ != UTC
// даёт day-shift (например, 21.06 MSK → "2026-06-20"), что выглядит как
// «picker показывает на день меньше».
const toIso = (v: Date | string | null | undefined): string => {
if (!v) return ''
if (typeof v === 'string') return v.slice(0, 10)
if (v instanceof Date && !isNaN(v.getTime())) return v.toISOString().slice(0, 10)
if (v instanceof Date && !isNaN(v.getTime())) return formatIsoDate(v)
return ''
}
@@ -64,8 +68,7 @@ export function DatePicker({
onChange?.(null)
return
}
const d = new Date(raw + 'T00:00:00')
onChange?.(isNaN(d.getTime()) ? null : d)
onChange?.(parseFormDate(raw))
}
return (