common: implement formatHaab

This commit is contained in:
Quantum 2025-06-22 04:28:56 -04:00
parent eb4a7253f1
commit e32b4bf774
2 changed files with 45 additions and 1 deletions

View file

@ -1,4 +1,4 @@
import {formatTzolkin, jdnTzolkin, TzolkinName, tzolkinName} from './mayan'; import {formatHaab, formatTzolkin, jdnTzolkin, TzolkinName, tzolkinName} from './mayan';
describe('tzolkinName', () => { describe('tzolkinName', () => {
it('should return correct name for IMIX', () => { it('should return correct name for IMIX', () => {
@ -80,3 +80,18 @@ describe('jdnTzolkin', () => {
expect(results.size).toBe(260); 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');
});
});

View file

@ -65,3 +65,32 @@ export function jdnTzolkin(jdn: number): Tzolkin {
name: (jdn % 20 + 36) % 20, 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<HaabMonth, string> = {
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]}`;
}