diff --git a/common/src/mayan.test.ts b/common/src/mayan.test.ts index 9f475a0..b25708e 100644 --- a/common/src/mayan.test.ts +++ b/common/src/mayan.test.ts @@ -1,4 +1,4 @@ -import {formatTzolkin, jdnTzolkin, TzolkinName, tzolkinName} from './mayan'; +import {formatHaab, formatTzolkin, jdnTzolkin, TzolkinName, tzolkinName} from './mayan'; describe('tzolkinName', () => { it('should return correct name for IMIX', () => { @@ -80,3 +80,18 @@ describe('jdnTzolkin', () => { expect(results.size).toBe(260); }); }); + +describe('formatHaab', () => { + it('formats normal month and day', () => { + expect(formatHaab(1, 5)).toBe('5 Pop'); + expect(formatHaab(7, 12)).toBe('12 Yaxkʼin'); + }); + + it('formats Wayeb month', () => { + expect(formatHaab(19, 4)).toBe('4 Wayebʼ'); + }); + + it('formats zero day', () => { + expect(formatHaab(3, 0)).toBe('0 Sip'); + }); +}); diff --git a/common/src/mayan.ts b/common/src/mayan.ts index 1058d5c..fe4822d 100644 --- a/common/src/mayan.ts +++ b/common/src/mayan.ts @@ -65,3 +65,32 @@ export function jdnTzolkin(jdn: number): Tzolkin { name: (jdn % 20 + 36) % 20, }; } + +export type HaabMonth = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19; +export type HaabDay = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19; + +const haabNames: Record = { + 1: 'Pop', + 2: 'Woʼ', + 3: 'Sip', + 4: 'Sotzʼ', + 5: 'Sek', + 6: 'Xul', + 7: 'Yaxkʼin', + 8: 'Mol', + 9: 'Chʼen', + 10: 'Yax', + 11: 'Sakʼ', + 12: 'Keh', + 13: 'Mak', + 14: 'Kʼankʼin', + 15: 'Muwan', + 16: 'Pax', + 17: 'Kʼayabʼ', + 18: 'Kumkʼu', + 19: 'Wayebʼ', +}; + +export function formatHaab(month: HaabMonth, day: HaabDay): string { + return `${day} ${haabNames[month]}`; +}