react-native-jewish-calendar
Version:
jewish calendar for react native apps
71 lines • 2.68 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Common_1 = require("./Common");
const HebrewDay_1 = require("./HebrewDay");
function findRoshHashana(d) {
let r = Common_1.dayOfRoshHashana(d.getFullYear());
if (r.getTime() - d > 0)
r = Common_1.dayOfRoshHashana(d.getFullYear() - 1);
return r;
}
function findRoshHashanaForNextYear(d) {
const r = Common_1.dayOfRoshHashana(d.getFullYear() + 1);
return Common_1.gimatria(r.getDay() + 1);
}
class HebrewYear {
constructor(date) {
this.createYear(date);
}
createYear(date) {
this.rosh = findRoshHashana(Common_1.fixedDate(new Date(date)));
this.nextRoshHashanaDay = findRoshHashanaForNextYear(this.rosh);
this.hebYear = this.rosh.getFullYear() + Common_1.YEARBETWEENGEROGIANTOJEWISH;
this.daysInYear = Common_1.daysInYear(this.hebYear);
this.leap = this.daysInYear > 380;
this.type = new Common_1.YearType(this.rosh, this.daysInYear, this.leap);
this.days = new Map();
this.weeksWithParash = 0;
let day = new Date(this.rosh);
for (let m = 1; m <= Common_1.MONTHES.length - 1; m++) {
const month = Common_1.MONTHES[m];
if (month === Common_1.YEAR_MONTHS.ADARB && !this.leap)
continue;
let _daysInMonth = Common_1.daysInMonth(month, this.leap, this.daysInYear);
for (let i = 1; i <= _daysInMonth; i++) {
const hebDay = new HebrewDay_1.HebrewDay(day, i, m, this);
this.days.set(day.toLocaleDateString(), hebDay);
day.setDate(day.getDate() + 1);
}
}
}
getDay(date) {
if (typeof date === 'string') {
date = new Date(date);
}
if (!this.days.has(date.toLocaleDateString())) {
this.createYear(date);
}
return this.days.get(date.toLocaleDateString());
}
getPesahDay() {
return this.type.getPesahDayInWeek();
}
getRoshHashanaDay() {
return this.type.getRoshHashanaDayInWeek();
}
getNextYearRoshHashana() {
return this.nextRoshHashanaDay;
}
getYearLength() {
return this.type.getYearLength();
}
checkIfMonthIsFull(month) {
if (month < 1 || month > 13) {
throw new Error('no such month');
}
let _daysInMonth = Common_1.daysInMonth(Common_1.MONTHES[month], this.leap, this.daysInYear);
return _daysInMonth === 30;
}
}
exports.default = HebrewYear;
//# sourceMappingURL=HebrewYear.js.map