Skip to content

Commit

Permalink
fix. plus since this is a negative offset, the date time needs to be …
Browse files Browse the repository at this point in the history
…adjusted to dec 31s 1999 in this test example
  • Loading branch information
Marc Lundgren committed Mar 30, 2024
1 parent a729582 commit b69f06b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ test('formatting a time in Cananda, Newfoundland timezone', () => {
const date = new Date(Date.UTC(2000, 0, 1, 0, 12, 34, 567));
const actual = dateToLocaleISOString(date);

expect(actual).toMatchInlineSnapshot(`"2000-01-01T09:12:34.567-03:30"`);
expect(actual).toMatchInlineSnapshot(`"1999-12-31T20:42:34.567-03:30"`);
});
4 changes: 3 additions & 1 deletion packages/core/src/utils/dateToLocaleISOString.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@ export default function dateToLocaleISOString(date: Date): string {
// "yyyy-MM-DDTHH:mm:ss.fff+08:00" for GMT+08
// "yyyy-MM-DDTHH:mm:ss.fffZ" for UTC

const absoluteTimezoneOffset = ~~Math.abs(timezoneOffset);

return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}T${pad(date.getHours())}:${pad(
date.getMinutes()
)}:${pad(date.getSeconds())}.${pad(date.getMilliseconds(), 3)}${
timezoneOffset ? `${timezoneSign}${pad(~~(Math.abs(timezoneOffset) / 60))}:${pad(timezoneOffset % 60)}` : 'Z'
timezoneOffset ? `${timezoneSign}${pad(~~(absoluteTimezoneOffset / 60))}:${pad(absoluteTimezoneOffset % 60)}` : 'Z'
}`;
}

0 comments on commit b69f06b

Please sign in to comment.