Skip to content

Commit

Permalink
fix(datetime): fix dayOfYear when the timezone has DST (#3668)
Browse files Browse the repository at this point in the history
  • Loading branch information
kt3k authored Sep 26, 2023
1 parent 2884033 commit c5515cd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
7 changes: 7 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ jobs:
- name: Run tests canary
run: deno task test

- name: Run timezone-dependent tests
run: |
TZ=Australia/Sydney deno test datetime
TZ=Europe/London deno test datetime
TZ=America/Toronto deno test datetime
if: matrix.os == 'ubuntu-22.04'

- name: Type check browser compatible modules
shell: bash
run: deno task test:browser
Expand Down
3 changes: 2 additions & 1 deletion datetime/day_of_year.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ export function dayOfYear(date: Date): number {
const yearStart = new Date(date);

yearStart.setFullYear(date.getFullYear(), 0, 0);
const diff = date.getTime() - yearStart.getTime();
const diff = (date.getTime() - date.getTimezoneOffset() * 60 * 1000) -
(yearStart.getTime() - yearStart.getTimezoneOffset() * 60 * 1000);

return Math.floor(diff / DAY);
}
Expand Down

0 comments on commit c5515cd

Please sign in to comment.