common: define haabMonthDays helper

This commit is contained in:
Quantum 2025-07-12 19:57:00 -04:00
parent 785f89bf6c
commit 15129bdde0
2 changed files with 17 additions and 1 deletions

View file

@ -1,7 +1,7 @@
import { import {
formatHaab, formatHaab,
formatLordOfNight, formatLordOfNight,
formatTzolkin, formatTzolkin, HaabMonth, haabMonthDays,
jdnHaab, jdnHaabExt, jdnHaab, jdnHaabExt,
jdnLordOfNight, jdnLordOfNight,
jdnTzolkin, jdnTzolkin,
@ -163,6 +163,18 @@ describe('jdnHaab', () => {
}); });
}); });
describe('haabMonthDays', () => {
it('returns 20 days for months 1-18', () => {
for (let month = 1; month <= 18; month++) {
expect(haabMonthDays(month as HaabMonth)).toBe(20);
}
});
it('returns 5 days for month 19 (Wayeb)', () => {
expect(haabMonthDays(19)).toBe(5);
});
});
describe('jdnHaabExt', () => { describe('jdnHaabExt', () => {
it('handles creation correctly', () => { it('handles creation correctly', () => {
expect(jdnHaabExt(583934)).toEqual({year: -1, month: 19, day: 4}); // end of the year before creation expect(jdnHaabExt(583934)).toEqual({year: -1, month: 19, day: 4}); // end of the year before creation

View file

@ -108,6 +108,10 @@ export function jdnHaab(jdn: number): Haab {
}; };
} }
export function haabMonthDays(month: HaabMonth): number {
return month === 19 ? 5 : 20;
}
export type HaabYear = number; export type HaabYear = number;
export type HaabExt = Haab & { export type HaabExt = Haab & {