Skip to content

Commit

Permalink
Time constants
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonsturges committed May 24, 2021
1 parent d169d3a commit b393aab
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/constants/Time.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export module Time {
/**
* Timestamp epoch, January 1, 1970.
* Timestamp epoch, January 1, 1970, in Julian Days.
*/
export const epoch: number = 2440587.5;

Expand Down
6 changes: 4 additions & 2 deletions src/model/JulianDay.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { Time } from "../constants/Time";

export module JulianDay {
/**
* Julian day from Gregorian date.
* @param date - Gregorian date to convert to Julian day.
*/
export const fromDate = (date: Date = new Date()): number => {
const time = date.getTime();
return time / 86400000 - date.getTimezoneOffset() / 1440 + 2440587.5;
return time / 86400000 - date.getTimezoneOffset() / 1440 + Time.epoch;
};

/**
Expand All @@ -14,7 +16,7 @@ export module JulianDay {
*/
export const toDate = (julian: number): Date => {
let date = new Date();
date.setTime((julian - 2440587.5 + date.getTimezoneOffset() / 1440) * 86400000);
date.setTime((julian - Time.epoch + date.getTimezoneOffset() / 1440) * 86400000);
return date;
};
}
2 changes: 1 addition & 1 deletion src/model/Moon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Time } from "../constants/Time";

export module Moon {
/**
* Moon's age, or days since the last new moon.
* Moon's age, or Earth days since the last new moon.
*
* @param date - Date used for calculation.
* @returns Age of the moon, normalized within a 29.53059 Earth days calendar.
Expand Down

0 comments on commit b393aab

Please sign in to comment.