QENJS is a library for working with Ethiopian Dates, providing convenient methods for creating, formatting, manipulating, and converting Ethiopian dates. This README will guide you through various examples and functionalities available in the QENJS library. Check out the live demo of the qenjs: Qenjs Demo
- Convert between Ethiopian and Gregorian dates.
- Format ethiopian dates in Amharic and latin.
- Format gregorian dates
- Calculate date difference and relative time
You can install qenjs via npm:
npm install qenjsAlternatively, if you're using Yarn:
yarn add qenjsHere's how you can start using MiniDayjs in your project:
You can create an Ethiopian date using the following methods:
const ethiopianDate = qenjs();
console.log(ethiopianDate.toString()); // Outputs current ethiopian date
const ethiopianDate2 = qenjs(2017, 1, 1);
console.log(ethiopianDate2.toString()); // Outputs 01/01/2017
const ethiopianDate3 = qenjs("2017-01-29");
console.log(ethiopianDate3.format("DDDD, MMMM dd YYYY")); // Outputs: ረቡዕ, መስከረም 29 2017
const ethiopianDate4= qenjs({ year: 2017, month: 4, day: 15 });
console.log(ethiopianDate4.toString("DDDD, MMMM dd YYYY", "eng")); // Maksegno, Tahsas 15 2017
const ethiopianDate4= qenjs.fromGregorianDate(new Date());
console.log(ethiopianDate4.toString("DDDD, MMMM dd YYYY")); // Outputs current ethiopian date
const ethiopianNightDate = qenjs("2017-01-29", { isNight: true });
console.log(ethiopianNightDate.toString("dd/MM/YYYY HH:mm:ss A")); // 29/01/2017 01:00:00 ምሽትYou can format Ethiopian dates using custom patterns. The default language is Amharic, but you can specify another language if needed.
const ethiopianDate = qenjs({ year: 2017, month: 4, day: 15 });
console.log(ethiopianDate.format("MMMM dd, YYYY", "amh")); // ታኅሣሥ 15, 2017
console.log(ethiopianDate4.toString("DDDD, MMMM dd YYYY", "eng")); // Maksegno, Tahsas 15 2017
console.log(qenjs.format(ethiopianDate3, "MMMM d, YYYY")); // ታኅሣሥ 15, 2017You can manipulate Ethiopian dates by adding or subtracting days.
Example: Adding Days
const ethiopianDate = qenjs(2017, 1, 1);
const newDate = ethiopianDate.addDays(700);
console.log(newDate.toString("DDDD, MMMM dd, YYYY")); // Add 700 days to the dateExample: Subtracting Days
const ethiopianDate = qenjs(2017, 1, 1);
const previousDate = ethiopianDate.subtractDays(5);
console.log(previousDate.toString()); // Subtract 5 days from the dateQENJS provides methods to compare Ethiopian dates (e.g., checking if a date is before or after another date).
Example: Check if Date is Before
const date1 = qenjs(2025, 1, 29);
const date2 = qenjs(2024, 1, 29);
console.log(date1.isBefore(date2)); // Should print false
console.log(date1.isAfter(date2)); // Should print false
console.log(date1.isSame(date2)); // Should print trueQENJS supports converting Ethiopian dates to Gregorian dates.
Example: Convert Ethiopian Date to Gregorian Date
const ethiopianDate = qenjs({ year: 2017, month: 4, day: 15 });
const gregorianDate = qenjs.toGregorianDate(ethiopianDate);
console.log(gregorianDate.toISOString()); // Outputs the Gregorian equivalentQENJS supports relative time, showing how much time has passed since or until a certain date.
Example: Get Relative Time
Copy
const ethiopianDate = qenjs(2017, 4, 15);
console.log(ethiopianDate.fromNow()); // Outputs relative time like "X days ago" QENJS provides methods to calculate the difference between two Ethiopian dates.
Example: Date Difference
const date1 = qenjs(2017, 1, 1);
const date2 = qenjs(2017, 13, 5);
console.log(qenjs.diff(date1, date2)); // Outputs the difference in days, months, or years
console.log(qenjs.diff(date1, date2, "days")); // Difference in daysWe welcome contributions to qenjs! If you'd like to help improve the Ethiopian Date Converter or suggest new features, feel free to fork the repository and submit a pull request.
How to Contribute:
- Fork the repository.
- Create a new branch for your feature or fix.
- Make your changes and commit them.
- Push to your fork and create a pull request.
Please make sure to follow the coding style and include tests for new features or bug fixes.
Thank you for exploring this repository! Your interest and support mean a lot. I hope this project provides value to you. If you find it useful, feel free to explore the code, report issues, or contribute!
Happy coding! 🚀