Skip to content

Commit 184c2a3

Browse files
committed
fix
1 parent 3fad332 commit 184c2a3

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

web_src/js/webcomponents/absolute-date.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ test('toAbsoluteLocaleDate', () => {
1818
expect(toAbsoluteLocaleDate('10000-01-01', '', {})).toEqual('Invalid Date');
1919

2020
// test different timezone
21+
const oldTZ = process.env.TZ;
2122
process.env.TZ = 'America/New_York';
2223
expect(new Date('2024-03-15').toLocaleString()).toEqual('3/14/2024, 8:00:00 PM');
2324
expect(toAbsoluteLocaleDate('2024-03-15')).toEqual('3/15/2024, 12:00:00 AM');
25+
process.env.TZ = oldTZ;
2426
});

web_src/js/webcomponents/absolute-date.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
export function toAbsoluteLocaleDate(date: string, lang?: string, opts?: Intl.DateTimeFormatOptions) {
22
// only use the date part, it is guaranteed to be in ISO format (YYYY-MM-DDTHH:mm:ss.sssZ) or (YYYY-MM-DD)
33
// if there is an "Invalid Date" error, there must be something wrong in code and should be fixed.
4+
// TODO: there is a root problem in backend code: the date "YYYY-MM-DD" is passed to backend without timezone (eg: deadline),
5+
// then backend parses it in server's timezone and stores the parsed timestamp into database.
6+
// If the user's timezone is different from the server's, the date might be displayed in the wrong day.
47
const dateSep = date.indexOf('T');
58
date = dateSep === -1 ? date : date.substring(0, dateSep);
69
return new Date(`${date}T00:00:00`).toLocaleString(lang || [], opts);

0 commit comments

Comments
 (0)