UNPKG

ethio-date-time

Version:

45 lines (44 loc) 1.68 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.EthiopianCalendar = void 0; class EthiopianCalendar { static toEthiopianDate(date) { const jd = this.gregorianDateToJulianDays(date.getFullYear(), date.getMonth() + 1, date.getDate()); return this.julianDaysToEthiopianDate(jd); } static gregorianDateToJulianDays(y, m, d) { return (Math.floor(365.25 * (y + 4716)) + Math.floor(30.6001 * (m + 1)) + d - 1524.5); } static julianDaysToGregorianDate(jd) { const z = Math.floor(jd + 0.5); const a = z; const b = a + 1524; const c = Math.floor((b - 122.1) / 365.25); const d = Math.floor(365.25 * c); const e = Math.floor((b - d) / 30.6001); const day = b - d - Math.floor(30.6001 * e); const month = e < 14 ? e - 1 : e - 13; const year = month > 2 ? c - 4716 : c - 4715; return new Date(year, month - 1, day); } static ethiopianDateToJulianDays(year, month, day) { return (1723856 + 365 * (year - 1) + Math.floor(year / 4) + 30 * (month - 1) + day - 1); } static julianDaysToEthiopianDate(jd) { const r = jd - 1723856; const year = Math.floor(r / 1461) * 4 + Math.floor((r % 1461) / 365) + 1; const yOffset = this.ethiopianDateToJulianDays(year, 1, 1); const month = Math.floor((jd - yOffset) / 30) + 1; const day = jd - this.ethiopianDateToJulianDays(year, month, 1) + 1; return { year, month, day }; } } exports.EthiopianCalendar = EthiopianCalendar;