diff --git a/src/lib/helpers/date.ts b/src/lib/helpers/date.ts index 1a7693967..df25e9023 100644 --- a/src/lib/helpers/date.ts +++ b/src/lib/helpers/date.ts @@ -3,7 +3,8 @@ export const toLocaleDate = (datetime: string) => { const options: Intl.DateTimeFormatOptions = { year: 'numeric', month: 'short', - day: 'numeric' + day: 'numeric', + hourCycle: 'h23' }; return date.toLocaleDateString('en', options); @@ -17,7 +18,7 @@ export const toLocaleDateTime = (datetime: string | number) => { day: 'numeric', hour: 'numeric', minute: 'numeric', - hour12: false + hourCycle: 'h23' }; return date.toLocaleDateString('en', options); diff --git a/tests/unit/helpers/date.test.ts b/tests/unit/helpers/date.test.ts new file mode 100644 index 000000000..4b67f4f3d --- /dev/null +++ b/tests/unit/helpers/date.test.ts @@ -0,0 +1,24 @@ +import '@testing-library/jest-dom'; +import { toLocaleDate, toLocaleDateTime } from '$lib/helpers/date'; + +describe('local date', () => { + [ + ['2022-11-15 08:26:28', 'Nov 15, 2022'], + ['2022-11-15 00:26:28', 'Nov 15, 2022'] + ].forEach(([value, expected]) => { + it(value, () => { + expect(toLocaleDate(value)).toBe(expected); + }); + }); +}); + +describe('local date time', () => { + [ + ['2022-11-15 08:26:28', 'Nov 15, 2022, 08:26'], + ['2022-11-15 00:26:28', 'Nov 15, 2022, 00:26'] + ].forEach(([value, expected]) => { + it(value, () => { + expect(toLocaleDateTime(value)).toBe(expected); + }); + }); +});