From 28c9d90b4bbd8af50092cbf1c12a3e818e117fb0 Mon Sep 17 00:00:00 2001 From: Tim Reichen Date: Tue, 15 Sep 2020 16:09:40 +0200 Subject: fix(std/datetime): timezone bug (#7466) --- std/datetime/mod.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'std/datetime/mod.ts') 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 -- cgit v1.2.3