diff options
author | Tim Reichen <timreichen@users.noreply.github.com> | 2020-08-27 11:12:49 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-27 11:12:49 +0200 |
commit | 58bcb9880b5e9c85cfc67f7aa6601fd96822a580 (patch) | |
tree | e02ae23088dfa42e2572c71b79194876c7cc85b5 /std/datetime/mod.ts | |
parent | 81811e80e1c903d8f8baa305e2d0141d1b27a142 (diff) |
test(std/datetime): port golang dayOfYear tests (#7105)
Diffstat (limited to 'std/datetime/mod.ts')
-rw-r--r-- | std/datetime/mod.ts | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/std/datetime/mod.ts b/std/datetime/mod.ts index 64ca49196..a90d4b962 100644 --- a/std/datetime/mod.ts +++ b/std/datetime/mod.ts @@ -47,7 +47,11 @@ export function format(date: Date, formatString: string): string { * @return Number of the day in year */ export function dayOfYear(date: Date): number { - const yearStart = new Date(date.getFullYear(), 0, 0); + // 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); + const diff = date.getTime() - yearStart.getTime() + (yearStart.getTimezoneOffset() - date.getTimezoneOffset()) * 60 * 1000; |