From 15129bdde0b640197b98bc6dbc0ab6faf4d404e9 Mon Sep 17 00:00:00 2001 From: Quantum Date: Sat, 12 Jul 2025 19:57:00 -0400 Subject: [PATCH] common: define haabMonthDays helper --- common/src/mayan.test.ts | 14 +++++++++++++- common/src/mayan.ts | 4 ++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/common/src/mayan.test.ts b/common/src/mayan.test.ts index 6b1fc36..d59aee3 100644 --- a/common/src/mayan.test.ts +++ b/common/src/mayan.test.ts @@ -1,7 +1,7 @@ import { formatHaab, formatLordOfNight, - formatTzolkin, + formatTzolkin, HaabMonth, haabMonthDays, jdnHaab, jdnHaabExt, jdnLordOfNight, 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', () => { it('handles creation correctly', () => { expect(jdnHaabExt(583934)).toEqual({year: -1, month: 19, day: 4}); // end of the year before creation diff --git a/common/src/mayan.ts b/common/src/mayan.ts index d4d19bd..9bca945 100644 --- a/common/src/mayan.ts +++ b/common/src/mayan.ts @@ -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 HaabExt = Haab & {