-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1e602d9
commit 3b127a4
Showing
4 changed files
with
25 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/** | ||
* Returns a number 1-366 representing how far through the year the date is. | ||
* Ideally port this to Temporal when it comes out. | ||
* | ||
* Credit to https://stackoverflow.com/a/26426761 | ||
*/ | ||
export function getDayOfYear(date: Date): number { | ||
// Get Day of Year | ||
var dayCount = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334]; | ||
var mn = date.getMonth(); | ||
var dn = date.getDate(); | ||
var dayOfYear = dayCount[mn] + dn; | ||
if (mn > 1 && isLeapYear(date)) dayOfYear++; | ||
return dayOfYear; | ||
} | ||
|
||
function isLeapYear(date: Date): boolean { | ||
const year = date.getFullYear(); | ||
if ((year & 3) != 0) return false; | ||
return year % 100 != 0 || year % 400 == 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters