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