deno.land / std@0.173.0 / datetime / day_of_year.ts

day_of_year.ts
نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.import { DAY } from "./constants.ts";
/** * Returns the number of the day in the year. * * @example * ```ts * import { dayOfYear } from "https://deno.land/std@$STD_VERSION/datetime/mod.ts"; * * dayOfYear(new Date("2019-03-11T03:24:00")); // output: 70 * ``` * * @return Number of the day in year */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.setUTCFullYear(date.getUTCFullYear(), 0, 0); const diff = date.getTime() - yearStart.getTime();
return Math.floor(diff / DAY);}
std

Version Info

Tagged at
a year ago