ethiopian-date-converter-lib
v1.0.1
Published
ethiopian date converter
Downloads
3
Readme
Here's the updated documentation for the EthiopianDate
class, including details on date-time conversion:
EthiopianDate Class Documentation
Overview
The EthiopianDate
class provides functionality to work with dates and times in the Ethiopian calendar system. This class allows you to create, convert, and manipulate Ethiopian dates and times, as well as interact with the Gregorian calendar.
This code provides a detailed implementation of the EthiopianDate
class, which models dates according to the Ethiopian calendar and provides methods to convert between the Ethiopian and Gregorian calendars. Here’s a brief overview of its features and functionality:
Constructor
constructor(year, month, date)
: Initializes anEthiopianDate
object and validates the provided date.
Conversion Methods
toGregorian()
: Converts the Ethiopian date to the corresponding Gregorian date.fromGregorian(gregorianDate)
: Static method to create anEthiopianDate
object from a Gregorian date.
Leap Year and Current Date
isLeapYear(year)
: Static method to check if a given Ethiopian year is a leap year.now()
: Static method to get the current Ethiopian date based on the current Gregorian date.
Formatting and Parsing
format(formatString)
: Formats the Ethiopian date as a string according to the specified format.parse(dateString, formatString)
: Static method to parse a formatted date string and create anEthiopianDate
object.
Validation and Date Manipulation
isValid()
: Validates whether the current Ethiopian date object is valid.nextMonth()
: Moves to the next month in the Ethiopian calendar.prevMonth()
: Moves to the previous month in the Ethiopian calendar.getMaxDaysInMonth(year, month)
: Static method to get the maximum number of days in a specified Ethiopian month.
Additional Utility Methods
calculateDaysInEthiopianCalendar()
: Calculates the number of days since the start of the Ethiopian calendar to the current date.compare(date1, date2)
: Static method to compare twoEthiopianDate
objects.toString()
: Returns a string representation of the Ethiopian date in the default format (YYYY-MM-DD
).
Example Usage
Here are a few examples of how to use the class:
// Creating an EthiopianDate object
const etDate = new EthiopianDate(2013, 1, 1);
// Converting to Gregorian date
const gregDate = etDate.toGregorian();
console.log(gregDate); // Outputs Gregorian date
// Parsing a formatted date string
const parsedDate = EthiopianDate.parse('2013-01-01', 'YYYY-MM-DD');
console.log(parsedDate); // Outputs EthiopianDate object
// Formatting the Ethiopian date
const formattedDate = etDate.format('YYYY-MM-DD');
console.log(formattedDate); // Outputs '2013-01-01'
// Moving to the next month
const nextMonthDate = etDate.nextMonth();
console.log(nextMonthDate); // Outputs the date in the next month
// Comparing two Ethiopian dates
const comparison = EthiopianDate.compare(etDate, new EthiopianDate(2013, 2, 1));
console.log(comparison); // Outputs -1, 0, or 1
Overall, this class should be quite useful for working with dates in the Ethiopian calendar and converting between Ethiopian and Gregorian systems. If you have specific questions or need further modifications, feel free to ask!