๐งฐ 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 }
๐จ Print Calendar (Console Grid)
const k = new Kenat();
k.printThisMonth(); // Default
k.printThisMonth(true); // Use Geez numerals
Example Output:
แแแฆแต แณแปแฒแฏ
Mo Tu We Th Fr Sa Su
1 2 3 4 5
6 7 8 9 10 11 12
...
๐ง Format in Geez
const k = new Kenat('2016/10/5');
console.log(k.formatInGeezAmharic());
// โ แแตแจแจแ แญ แณแปแฒแฎ
๐งฎ Date Arithmetic
const k = new Kenat('2015/6/10');
k.addDays(5);
k.addMonths(-1);
k.addYears(2);
console.log(k.getEthiopian());
// โ { year: 2017, month: 5, day: 15 }
๐ Difference Between Dates
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
const grid = Kenat.getMonthGrid({ year: 2017, month: 9, useGeez: true });
console.log(grid.headers);
// โ [ "แฅแแต", "แฐแ", "แแญแฐแ", ... ]
console.log(grid.days[0]);
// โ { ethiopian: { day: 1 }, gregorian: { day: 9 }, holiday: null }
๐ Built-in Holidays
import { getHoliday } from 'kenat';
console.log(getHoliday({ year: 2017, month: 1, day: 1 }));
// โ { name: 'แ แฒแต แแแต', type: 'national', lang: { am: 'แ แฒแต แแแต', en: 'New Year' } }
Last updated on