π 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.
Supported Input Types & Error Handling
Kenat automatically detects the type of input you provide:
- No arguments: Uses the current system date.
- String: Accepts
YYYY/MM/DD
orYYYY-MM-DD
format (Ethiopian or Gregorian). - Date object: Accepts native JavaScript
Date
or Pythondatetime
objects. - Numbers: Pass year, month, and day as separate numbers.
If you provide an invalid date (e.g., out-of-range month/day, wrong format), Kenat will throw an error describing the issue.
Time Support
You can optionally pass time information (hour, minute, period) when creating a date:
undefined
// Use 'day' or 'night' for the period property
const withTime = new Kenat(2017, 10, 5, { hour: 3, minute: 30, period: 'day' });
// or
const withTimeNight = new Kenat(2017, 10, 5, { hour: 3, minute: 30, period: 'night' });
Language Option
Most methods accept a lang
option to choose between Amharic and English output. Example:
undefined
today.getEthiopian({ lang: 'english' })
Output Types
Date methods like getEthiopian()
and getGregorian()
return plain objects, not Kenat instances.
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'.