Skip to Content
Kenat is a work in progress project ๐Ÿ‘จ๐Ÿปโ€๐Ÿ’ป
Documentation๐Ÿงฐ Usage Examples

๐Ÿงฐ 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