๐งฐ 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)); // 3
๐ Generate 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)MonthGrid
Time
toEC
,toGC
,toGeez
,toArabic
getHolidaysForYear
,getHolidaysInMonth
,getHoliday
HolidayTags
,monthNames
getBahireHasab
,getFastingPeriod
- Formatting:
formatStandard
,formatWithWeekday
,formatWithTime
,formatInGeezAmharic
,formatShort
,toISODateString
Last updated on