Usage Examples
This page demonstrates common date operations using Kenat: conversion, formatting, calendar grids, holidays, and more.
Convert Dates (Gregorian ↔ Ethiopian)
undefined
import { toEC, toGC } from 'kenat';
const eth = toEC(2025, 6, 2);
console.log(eth);
// → { year: 2017, month: 9, day: 25 }
const gc = toGC(2017, 9, 25);
console.log(gc);
// → { year: 2025, month: 6, day: 2 }Format in Geez
undefined
const k = new Kenat('2016/10/5');
console.log(k.formatInGeezAmharic());
// → መስከረም ፭ ፳፻፲፮Date Arithmetic
undefined
const k = new Kenat('2015/6/10');
// These methods mutate the instance and are chainable
k.addDays(5).addMonths(-1).addYears(2);
console.log(k.getEthiopian());
// → { year: 2017, month: 5, day: 15 }Difference Between Dates
undefined
const a = new Kenat('2015/5/15');
const b = new Kenat('2012/5/15');
console.log(a.diffInDays(b)); // 1095
console.log(a.diffInMonths(b)); // 39
console.log(a.diffInYears(b)); // 3Generate a Month Grid
undefined
import { MonthGrid } from 'kenat';
const grid = new MonthGrid(2017, 9, { useGeez: true });
console.log(grid.headers);
// → [ "እሑድ", "ሰኞ", "ማክሰኞ", ... ]
console.log(grid.days[0]);
// → { ethiopian: { day: 1 }, gregorian: { day: 9 }, holiday: null }Built-in Holidays
undefined
import { getHoliday, getHolidaysForYear, getHolidaysInMonth, HolidayTags } from 'kenat';
// Get a holiday by key and year
const enkutatash = getHoliday('enkutatash', 2017);
console.log(enkutatash);
// → { key: 'enkutatash', tags: [...], name: 'አዲስ ዓመት', description: 'Ethiopian New Year', ethiopian: { year: 2017, month: 1, day: 1 } }
// Get all public holidays for a year
const publicHolidays = getHolidaysForYear(2017, { filter: HolidayTags.PUBLIC });
console.log(publicHolidays);
// Get holidays for a specific month
const monthHolidays = getHolidaysInMonth(2017, 1, { filter: HolidayTags.PUBLIC });
console.log(monthHolidays);
// Use language option
const meskelEn = getHoliday('meskel', 2017, { lang: 'english' });
console.log(meskelEn.name); // 'Meskel'Error Handling
If you provide an invalid key or date, the functions return null or throw an error.
Quick Reference: Named Exports
Kenat exports many useful functions and constants:
Kenat(default)MonthGridTimetoEC,toGC,toGeez,toArabicgetHolidaysForYear,getHolidaysInMonth,getHolidayHolidayTags,monthNamesgetBahireHasab,getFastingPeriod- Formatting:
formatStandard,formatWithWeekday,formatWithTime,formatInGeezAmharic,formatShort,toISODateString
PHP equivalent: same functionality, organized as static methods on
namespaced classes instead of top-level functions — Kenat, MonthGrid,
Time, Conversions::toEC/toGC, GeezConverter::toGeez/toArabic,
Holidays::getHolidaysForYear/getHolidaysInMonth/getHoliday, HolidayTags,
BahireHasab::calculate/getMovableHoliday, Fasting::getFastingPeriod, and
Formatting::formatStandard/formatWithWeekday/formatWithTime/formatInGeezAmharic/formatShort/toISODateString.
Last updated on