From 9cfa3a8cb16f70a9022381b092407dc7eecf07b3 Mon Sep 17 00:00:00 2001 From: Yoshiya Hinosawa Date: Fri, 22 Sep 2023 10:32:06 +0100 Subject: [PATCH] fix(datetime): fix dayOfYear when the timezone has DST --- .github/workflows/ci.yml | 7 +++++++ datetime/day_of_year.ts | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3b81b7f68048..de16f04ac67e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/datetime/day_of_year.ts b/datetime/day_of_year.ts index 8de69faf7785..4b1bb059f868 100644 --- a/datetime/day_of_year.ts +++ b/datetime/day_of_year.ts @@ -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); }