UNPKG

react-native-ethiopian-calendar-date-picker

Version:

A react native calendar component which is mainly intended for applications which require Ethiopian calendar.

43 lines (41 loc) 1.38 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.EthiopicCalendar = void 0; var _Core = require("../Core"); var _BasicDate = require("../Core/BasicDate"); const epoch = 1724220.5; class EthiopicCalendar { isLeap(year) { return (0, _Core.mod)(year, 4) === 3; } toJDN(year, month, day) { this.validator(year, month, day); return epoch - 1 + 365 * (year - 1) + Math.floor(year / 4) + 30 * (month - 1) + day; } fromJDN(jdn) { const year = Math.floor((4 * (jdn - epoch) + 1463) / 1461); const month = 1 + Math.floor((jdn - this.toJDN(year, 1, 1)) / 30); const day = jdn + 1 - this.toJDN(year, month, 1); return new _BasicDate.BasicDate(year, month, day, jdn); } validator(year, month, day) { // month cannot be more than 13 or less than 1. if (month < 1 || month > 13) { throw new _Core.CalendarError('INVALID_MONTH'); } // The 13th month cannot be more than 5 or 6 days. const leapMaxDays = this.isLeap(year) ? 6 : 5; if (month === 13 && day > leapMaxDays) { throw new _Core.CalendarError('INVALID_LEAP_DAY'); } // Days cannot be less than 1 or more than 30. if (day < 1 || day > 30) { throw new _Core.CalendarError('INVALID_DAY'); } return true; } } exports.EthiopicCalendar = EthiopicCalendar; //# sourceMappingURL=EthiopicCalendar.js.map