-
Notifications
You must be signed in to change notification settings - Fork 14
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
b8d8299
commit 572f310
Showing
2 changed files
with
139 additions
and
129 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,24 @@ | ||
import { EPOCH } from "./constants/Time"; | ||
|
||
/** | ||
* Julian day from Gregorian date. | ||
* Julian calendar, chronological days since noon Universal Time on January 1, 4713 BC | ||
*/ | ||
export const fromDate = (date = new Date()): number => { | ||
const time = date.getTime(); | ||
return time / 86400000 - date.getTimezoneOffset() / 1440 + EPOCH; | ||
}; | ||
export class Julian { | ||
/** | ||
* Julian day from Gregorian date. | ||
*/ | ||
static fromDate(date = new Date()): number { | ||
const time = date.getTime(); | ||
return time / 86400000 - date.getTimezoneOffset() / 1440 + EPOCH; | ||
} | ||
|
||
/** | ||
* Gregorian date from Julian day | ||
*/ | ||
export const toDate = (julian: number): Date => { | ||
const date = new Date(); | ||
date.setTime((julian - EPOCH + date.getTimezoneOffset() / 1440) * 86400000); | ||
/** | ||
* Gregorian date from Julian day | ||
*/ | ||
static toDate(julian: number): Date { | ||
const date = new Date(); | ||
date.setTime((julian - EPOCH + date.getTimezoneOffset() / 1440) * 86400000); | ||
|
||
return date; | ||
}; | ||
return date; | ||
} | ||
} |
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