Skip to content

Commit

Permalink
Merge pull request #153 from appwrite/fix-datetime-hour-cycle
Browse files Browse the repository at this point in the history
fix: datetime hourcycle formatting
  • Loading branch information
TorstenDittmann authored Nov 17, 2022
2 parents 2ba5825 + e8ff05c commit f89584b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/lib/helpers/date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const toLocaleDateTime = (datetime: string | number) => {
day: 'numeric',
hour: 'numeric',
minute: 'numeric',
hour12: false
hourCycle: 'h23'
};

return date.toLocaleDateString('en', options);
Expand Down
24 changes: 24 additions & 0 deletions tests/unit/helpers/date.test.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});
});

1 comment on commit f89584b

@vercel
Copy link

@vercel vercel bot commented on f89584b Nov 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.