mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-21 19:40:34 +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
33 lines
1.5 KiB
TypeScript
33 lines
1.5 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
||
import { dateInputPattern } from './dateInputPattern';
|
||
|
||
// The manual date field's hint has to read the way the field is filled and
|
||
// parsed in the user's language; it used to say DD.MM.YYYY everywhere (#2604).
|
||
describe('dateInputPattern', () => {
|
||
it('follows the field order and separators of the locale', () => {
|
||
expect(dateInputPattern('de-DE')).toBe('DD.MM.YYYY');
|
||
expect(dateInputPattern('en-US')).toBe('MM/DD/YYYY');
|
||
expect(dateInputPattern('en-GB')).toBe('DD/MM/YYYY');
|
||
expect(dateInputPattern('ko-KR')).toBe('YYYY. MM. DD.');
|
||
});
|
||
|
||
it('takes the shape only, never the locale digits', () => {
|
||
expect(dateInputPattern('ar')).not.toMatch(/[٠-٩\d]/);
|
||
expect(dateInputPattern('ar')).toContain('YYYY');
|
||
});
|
||
|
||
it('writes a chosen date format (#2971) as its own pattern, whatever the language', () => {
|
||
expect(dateInputPattern('en-US', 'YYYY-MM-DD')).toBe('YYYY-MM-DD');
|
||
expect(dateInputPattern('en-US', 'DD.MM.YYYY')).toBe('DD.MM.YYYY');
|
||
expect(dateInputPattern('de-DE', 'MM/DD/YYYY')).toBe('MM/DD/YYYY');
|
||
expect(dateInputPattern('ko-KR', 'YYYY/MM/DD')).toBe('YYYY/MM/DD');
|
||
});
|
||
|
||
it('keeps the locale pattern for auto, an unknown value or none', () => {
|
||
expect(dateInputPattern('de-DE', 'auto')).toBe('DD.MM.YYYY');
|
||
expect(dateInputPattern('en-US', 'auto')).toBe('MM/DD/YYYY');
|
||
expect(dateInputPattern('en-GB', 'DD-MM-YY')).toBe('DD/MM/YYYY');
|
||
expect(dateInputPattern('en-GB', null)).toBe('DD/MM/YYYY');
|
||
});
|
||
});
|