diff options
author | Tim Reichen <timreichen@users.noreply.github.com> | 2020-09-15 16:09:40 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-15 10:09:40 -0400 |
commit | 28c9d90b4bbd8af50092cbf1c12a3e818e117fb0 (patch) | |
tree | 51af792e8ce64a3b022ea19b3f64f0912bdab6a2 /std/datetime/mod.ts | |
parent | 44343a8aee2c1194992f55624b45e69c458b177d (diff) |
fix(std/datetime): timezone bug (#7466)
Diffstat (limited to 'std/datetime/mod.ts')
-rw-r--r-- | std/datetime/mod.ts | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/std/datetime/mod.ts b/std/datetime/mod.ts index 6bc947648..2afddbe6f 100644 --- a/std/datetime/mod.ts +++ b/std/datetime/mod.ts @@ -49,15 +49,16 @@ export function format(date: Date, formatString: string): string { export function dayOfYear(date: Date): number { // Values from 0 to 99 map to the years 1900 to 1999. All other values are the actual year. (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/Date) // Using setFullYear as a workaround + const yearStart = new Date(date); - yearStart.setFullYear(date.getFullYear(), 0, 0); + yearStart.setUTCFullYear(date.getUTCFullYear(), 0, 0); const diff = date.getTime() - yearStart.getTime() + (yearStart.getTimezoneOffset() - date.getTimezoneOffset()) * 60 * 1000; + return Math.floor(diff / DAY); } - /** * Get number of the week in the year (ISO-8601) * @return Number of the week in year |