@itc-smis/chhankitek
v1.0.1
Published
Convert AD (Gregorian) dates to Khmer lunar (Chhankitek) dates, and compute Khmer New Year moments.
Maintainers
Readme
ចន្ទគតិ[Chhankitek]
Convert AD (Gregorian) dates to Khmer lunar (Chhankitek) dates, and compute the exact Khmer New Year (Moha Sangkranta) moment. Learn more about the calendar.
Zero dependencies. TypeScript. Works in Node.js (ESM & CommonJS) and the browser.
Installation
npm install @itc-smis/chhankitekUsage
import { toLunarDate } from '@itc-smis/chhankitek';
const lunar = toLunarDate(new Date(2021, 5, 28));
lunar.toString();
// ថ្ងៃច័ន្ទ ៤ រោច ខែបឋមាសាឍ ឆ្នាំឆ្លូវ ត្រីស័ក ព.ស. ២៥៦៥You can also pass a plain object — recommended on servers whose local timezone is not Asia/Phnom_Penh, since a Date is read using its local calendar date:
toLunarDate({ year: 2021, month: 6, day: 28 }); // month is 1-12
toLunarDate(); // defaults to todayAvailable fields
const lunar = toLunarDate(new Date());
lunar.dayOfWeek; // អាទិត្យ, ច័ន្ទ, ...
lunar.lunarDay; // ១ កើត, ២ កើត, ..., ៤ រោច
lunar.lunarMonth; // មិគសិរ, បុស្ស, ..., បឋមាសាឍ
lunar.lunarZodiac; // ជូត, ឆ្លូវ, ...
lunar.lunarEra; // សំរឹទ្ធិស័ក, ឯកស័ក, ..., ត្រីស័ក
lunar.lunarYear; // ២៥៦៥, ២៥៦៦, ... (Buddhist Era, Khmer numerals)Raw numeric values are available under attributes for programmatic use:
lunar.attributes;
// {
// dayOfWeek: 1, // 0 = Sunday, matches Date#getDay()
// lunarDayCount: 4, // 1-15
// moonStatus: 1, // 0 = កើត (waxing), 1 = រោច (waning)
// lunarMonth: 12, // index into lunarMonthNames
// beYear: 2565, // ពុទ្ធសករាជ
// jolakSakarajYear: 1383,// ចុល្លសករាជ
// mohaSakarajYear: 1944, // មហាសករាជ
// animalYear: 1, // 0 = ជូត
// eraYear: 3, // 0 = សំរឹទ្ធិស័ក
// }Khmer New Year
import { khmerNewYearDateTime } from '@itc-smis/chhankitek';
khmerNewYearDateTime(2024);
// { year: 2024, month: 4, day: 13, hour: 22, minute: 24 }The result is wall-clock time in Cambodia (ICT). The traditional Soriyatra algorithm resolves time in libda steps (24 minutes), so the minute can differ slightly from officially published astronomical times; the date is exact.
Other helpers
import {
toKhmerNumber, // 2565 -> ២៥៦៥
visakhaBocheaJdnOf, // Julian Day Number of Visakha Bochea day
isKhmerLeapMonth, // អធិកមាស — 13-month year (384 days)
isKhmerLeapDay, // អធិកវារៈ — year with extra day in ជេស្ឋ (355 days)
lunarMonthNames, dayOfWeekNames, animalYearNames, eraYearNames,
} from '@itc-smis/chhankitek';