π Getting Started
Kenat helps you create and manipulate Ethiopian dates using the intuitive Kenat
class. It supports creating dates from various sources and lets you easily switch between Ethiopian and Gregorian formats.
ποΈ Creating a New Date Instance
The Kenat
constructor is flexible. Here are the ways you can create a new date.
From the Current Date
If you create a Kenat
instance with no arguments, it will automatically represent the current system date.
undefined
import Kenat from 'kenat';
const today = new Kenat();
console.log('ET:', today.getEthiopian());
// Example Output ET: { year: 2017, month: 10, day: 5 }
console.log('GC:', today.getGregorian());
// Example Output GC: { year: 2025, month: 6, 13 }
From a String
You can create a date from a string in YYYY/MM/DD
or YYYY-MM-DD
format.
undefined
const customDate = new Kenat('2016/10/05');
console.log(customDate.getGregorian());
// Output: { year: 2024, month: 6, day: 13 }
From a JavaScript Date
Object
You can pass a native JavaScript Date
object directly to the constructor.
undefined
const gcDate = new Date('2024-08-22');
const fromDate = new Kenat(gcDate);
console.log(fromDate.getEthiopian());
// Output: { year: 2016, month: 12, day: 13 }
From Individual Components
You can create a date by passing the year, month, and day as separate numbers.
undefined
const fromComponents = new Kenat(2016, 1, 1);
console.log(fromComponents.getGregorian());
// Output: { year: 2023, month: 9, day: 11 }
π Working with Holidays
Kenat also provides functions to get holidays for a given year.
undefined
import { getHolidaysForYear, HolidayTags } from 'kenat';
const year = 2017; // E.C.
// Get only public holidays by passing a single tag.
const publicHolidays = getHolidaysForYear(year, {
filter: HolidayTags.PUBLIC
});
console.log(`Found ${publicHolidays.length} public holidays in ${year} E.C.`);
// Expected: Lists all holidays tagged as 'public'.
Last updated on