mirror of
https://github.com/quantum5/qcal.git
synced 2025-07-26 19:34:10 -04:00
common: define haabExtJDN helper
This commit is contained in:
parent
15129bdde0
commit
6bbd0d0ad9
|
@ -2,7 +2,7 @@ import {
|
||||||
formatHaab,
|
formatHaab,
|
||||||
formatLordOfNight,
|
formatLordOfNight,
|
||||||
formatTzolkin, HaabMonth, haabMonthDays,
|
formatTzolkin, HaabMonth, haabMonthDays,
|
||||||
jdnHaab, jdnHaabExt,
|
jdnHaab, jdnHaabExt, haabExtJDN,
|
||||||
jdnLordOfNight,
|
jdnLordOfNight,
|
||||||
jdnTzolkin,
|
jdnTzolkin,
|
||||||
TzolkinName,
|
TzolkinName,
|
||||||
|
@ -207,6 +207,38 @@ describe('jdnHaabExt', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('haabExtJDN', () => {
|
||||||
|
it('handles creation correctly', () => {
|
||||||
|
expect(haabExtJDN({year: -1, month: 19, day: 4})).toBe(583934); // end of the year before creation
|
||||||
|
expect(haabExtJDN({year: 0, month: 1, day: 0})).toBe(583935); // start of the year of creation
|
||||||
|
expect(haabExtJDN({year: 0, month: 18, day: 8})).toBe(584283); // creation
|
||||||
|
expect(haabExtJDN({year: 0, month: 19, day: 4})).toBe(584299); // end of the year of creation
|
||||||
|
expect(haabExtJDN({year: 1, month: 1, day: 0})).toBe(584300); // first 0 Pop after creation
|
||||||
|
});
|
||||||
|
|
||||||
|
it('handles 5141 cycles since creation correctly', () => {
|
||||||
|
expect(haabExtJDN({year: 5141, month: 18, day: 8})).toBe(2460748); // exactly 5141 years since creation
|
||||||
|
expect(haabExtJDN({year: 5141, month: 19, day: 4})).toBe(2460764); // end of that cycle
|
||||||
|
expect(haabExtJDN({year: 5142, month: 1, day: 0})).toBe(2460765); // start of the next cycle
|
||||||
|
});
|
||||||
|
|
||||||
|
it('converts sample dates from history correctly', () => {
|
||||||
|
expect(haabExtJDN({year: 0, month: 18, day: 8})).toBe(584283); // Mayan creation
|
||||||
|
expect(haabExtJDN({year: 3072, month: 11, day: 11})).toBe(1705426); // Ides of March
|
||||||
|
expect(haabExtJDN({year: 4609, month: 4, day: 16})).toBe(2266296); // Columbus reaches the Americas
|
||||||
|
expect(haabExtJDN({year: 5058, month: 12, day: 11})).toBe(2430336); // a date which will live in infamy
|
||||||
|
expect(haabExtJDN({year: 5086, month: 5, day: 18})).toBe(2440423); // Moon landing
|
||||||
|
expect(haabExtJDN({year: 5136, month: 18, day: 5})).toBe(2458920); // COVID-19 pandemic
|
||||||
|
});
|
||||||
|
|
||||||
|
it('handles negative JDN correctly', () => {
|
||||||
|
expect(haabExtJDN({year: -1601, month: 4, day: 5})).toBe(-365);
|
||||||
|
expect(haabExtJDN({year: -1601, month: 19, day: 4})).toBe(-66);
|
||||||
|
expect(haabExtJDN({year: -1600, month: 1, day: 0})).toBe(-65);
|
||||||
|
expect(haabExtJDN({year: -1600, month: 4, day: 4})).toBe(-1);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('formatLordOfNight', () => {
|
describe('formatLordOfNight', () => {
|
||||||
it('should format Lord of Night 1', () => {
|
it('should format Lord of Night 1', () => {
|
||||||
expect(formatLordOfNight(1)).toBe('G1');
|
expect(formatLordOfNight(1)).toBe('G1');
|
||||||
|
|
|
@ -125,6 +125,10 @@ export function jdnHaabExt(jdn: number): HaabExt {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function haabExtJDN({year, month, day}: HaabExt): number {
|
||||||
|
return 583935 + 365 * year + (month - 1) * 20 + day;
|
||||||
|
}
|
||||||
|
|
||||||
export type LordOfNight = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
|
export type LordOfNight = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
|
||||||
|
|
||||||
export function formatLordOfNight(lordOfNight: LordOfNight): string {
|
export function formatLordOfNight(lordOfNight: LordOfNight): string {
|
||||||
|
|
Loading…
Reference in a new issue