fix: datetime hourcycle formatting

This commit is contained in:
Torsten Dittmann
2022-11-16 10:22:31 +01:00
parent 04954c20ba
commit 5d3a406a31
2 changed files with 27 additions and 2 deletions
+3 -2
View File
@@ -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);
+24
View File
@@ -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);
});
});
});