Skip to Content
Kenat is a work in progress project
Documentation Formatting

Formatting Ethiopian Dates with Kenat

The kenat.formatting module provides a collection of functions to format Kenat date objects into various string representations. You can combine these with the Time class for time-aware formatting.

You can format dates in two ways:

  • Using instance methods on a Kenat object (e.g., date.format(...), date.formatInGeezAmharic(), date.toISOString()).
  • Using named formatting functions (e.g., formatStandard(date), formatWithWeekday(date), etc.) imported from kenat.

All formatting functions return strings suitable for display. Invalid date or time objects will throw an error (e.g., InvalidEthiopianDateError, InvalidTimeError).



Formatting Functions

Here are the primary functions available for formatting dates in JavaScript. All formatting functions can be used as instance methods on a Kenat object or as named functions imported from kenat. Invalid date or time objects will throw an error (e.g., InvalidEthiopianDateError, InvalidTimeError).

Standard Date Format

Formats a date into a standard “Month Day Year” string.

undefined

import { Kenat, formatStandard } from 'kenat'; // Kenat constructor supports string/object/Date const today = new Kenat('2016/1/10'); // or: new Kenat({ year: 2016, month: 1, day: 10 }) // or: new Kenat(new Date(2016, 0, 10)) // Using Kenat instance method (default Amharic) console.log(today.format()); // Output: መስከረም 10 2016 // Using Kenat instance method (English) console.log(today.format({ lang: 'english' })); // Output: Meskerem 10 2016 // Using named formatting function console.log(formatStandard(today)); // Output: መስከረም 10 2016 console.log(formatStandard(today, 'english')); // Output: Meskerem 10 2016

Date Format with Weekday

Includes the day of the week in the output.

import { Kenat, formatWithWeekday } from 'kenat'; const today = new Kenat('2016/1/10'); // Using Kenat instance method console.log(today.formatWithWeekday()); // Output: ማክሰኞ, መስከረም 10 2016 console.log(today.formatWithWeekday('english', true)); // Output: Tuesday, Meskerem ፲ ፳፻፲፮ // Using named formatting function console.log(formatWithWeekday(today)); // Output: ማክሰኞ, መስከረም 10 2016 console.log(formatWithWeekday(today, 'english', true)); // Output: Tuesday, Meskerem ፲ ፳፻፲፮ // Options: lang ('amharic'|'english'), useGeez (boolean)

Date Format with Time

Combines a date and a Time object into a single string.

import { Kenat, Time, formatWithTime } from 'kenat'; const today = new Kenat('2016/1/10'); const time = new Time(8, 30, 'day'); // Using Kenat instance method console.log(today.formatWithTime(time)); // Output: መስከረም 10 2016 8:30 ቀን // Using named formatting function console.log(formatWithTime(today, time)); // Output: መስከረም 10 2016 8:30 ቀን // Options: lang ('amharic'|'english'), useGeez (boolean)

Geez Numeral Date Format

Formats the date using Ge’ez numerals for the day and year.

import { Kenat, formatInGeezAmharic } from 'kenat'; const today = new Kenat('2016/1/10'); // Using Kenat instance method console.log(today.formatInGeezAmharic()); // Output: መስከረም ፲ ፳፻፲፮ // Using named formatting function console.log(formatInGeezAmharic(today)); // Output: መስከረም ፲ ፳፻፲፮

Short Date Format

Returns the date in a compact YYYY/MM/DD format.

import { Kenat, formatShort } from 'kenat'; const today = new Kenat('2016/1/10'); // Using Kenat instance method console.log(today.formatShort()); // Output: 2016/01/10 // Using named formatting function console.log(formatShort(today)); // Output: 2016/01/10

ISO Date String Format

Returns an ISO-like string, with optional time.

import { Kenat, Time, toISODateString } from 'kenat'; // Date only const today = new Kenat('2016/1/10'); console.log(today.toISOString()); // Output: 2016-01-10 console.log(toISODateString(today)); // Output: 2016-01-10 // With time const time = new Time(8, 30, 'day'); // Kenat does not accept time in constructor, set time via setTime today.setTime(8, 30, 'day'); console.log(today.toISOString()); // Output: 2016-01-10T08:30 console.log(toISODateString(today, time)); // Output: 2016-01-10T08:30
Last updated on