mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-13 07:40:59 +00:00
44c6fbf372
Every date in TREK was written in the interface language's format, and English is en-US, so an English interface always showed and read mm/dd/yyyy with no way to change it. A few native date inputs followed the browser instead, so one screen could mix two formats. date_format is now a user setting with an admin default, next to the time format: automatic (the language's format, as before), YYYY-MM-DD, YYYY/MM/DD, DD.MM.YYYY, DD/MM/YYYY or MM/DD/YYYY. The date picker shows, pre-fills, hints and reads typed dates in it, and every date written in numbers across the app (lists, cards, admin panels, CSV and PDF exports) goes through one formatter. Dates written with a month name keep the language's wording. The remaining native date inputs are the shared picker now. The display settings MCP tool reads and writes the key. Closes #2971
20 lines
960 B
TypeScript
20 lines
960 B
TypeScript
import { dateLayout } from './dateFormat';
|
||
|
||
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. A chosen date
|
||
* format (#2971) is its own pattern.
|
||
*/
|
||
export function dateInputPattern(locale: string, format?: string | null): string {
|
||
if (dateLayout(format)) return String(format);
|
||
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('');
|
||
}
|