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 }

๐Ÿง  Format in Geez

const k = new Kenat('2016/10/5'); console.log(k.formatInGeezAmharic()); // โ†’ แˆ˜แˆตแŠจแˆจแˆ แญ แณแปแฒแฎ

๐Ÿงฎ Date Arithmetic

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

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

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

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