Files
TREK/client/src/utils/dateInputPattern.ts
T
Maurice cb04ebe6d2 fix(trips): the trip form drops its complaint once you edit, and the typed date hint follows your language
"Title is required" stayed on screen after the title was typed, until the
next save. Any edit in the trip form, desktop and phone, now clears the
last save's complaint; the next save checks again.

The keyboard date field always hinted DD.MM.YYYY, while it was filled and
read back in the user's own order: a Korean user saw "2026. 12. 10." under
a German hint. The hint is now the locale's own pattern (YYYY. MM. DD. in
Korean, MM/DD/YYYY in US English), and the field's name is translated.

Refs #2604
2026-10-12 15:46:02 +02:00

16 lines
791 B
TypeScript
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
const LETTERS: Record<string, string> = { day: 'DD', month: 'MM', year: 'YYYY' };
/**
* How a typed date is written in `locale`, as letters (DD, MM, YYYY) between the
* locale's own separators. It is the hint of the manual date field, which is
* pre-filled and read back in this same order, so a Korean user sees
* "YYYY. MM. DD." rather than a German "DD.MM.YYYY". Direction marks are dropped:
* the hint shows the shape, the field itself carries the script.
*/
export function dateInputPattern(locale: string): string {
return new Intl.DateTimeFormat(locale, { day: '2-digit', month: '2-digit', year: 'numeric', timeZone: 'UTC' })
.formatToParts(new Date(Date.UTC(2001, 5, 15)))
.map((part) => LETTERS[part.type] ?? part.value.replace(/[؜‎‏]/g, ''))
.join('');
}