UNPKG

@calj.net/jdates

Version:

The Jewish Dates library from https://CalJ.net

61 lines (60 loc) 2.92 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Anniversary = void 0; const HDate_1 = require("./HDate"); const Rite_1 = require("./Rite"); const AnniversaryType_1 = require("./AnniversaryType"); class Anniversary { constructor(date, type, rite = Rite_1.Rite.SEFARADI) { this.type = type; this.rite = rite; this.hdate = HDate_1.HDate.make(date); } calc(hyear) { // Can't travel back in time if (hyear <= this.hdate.getYear()) { return null; } // Source date on 30 Cheshvan, target year Cheshvan has only 29 days if (this.hdate.getMonth() === HDate_1.HDateMonth.CHESHVAN && this.hdate.getDay() === 30 && HDate_1.HDate.monthLength(hyear, HDate_1.HDateMonth.CHESHVAN) === 29) { if (this.type === AnniversaryType_1.AnniversaryType.BIRTHDAY) { return HDate_1.HDate.make(1, HDate_1.HDateMonth.KISLEV, hyear); } // If on the year that followed the Petira, Cheshvan had 30 days -> 1Kislev: if (HDate_1.HDate.monthLength(this.hdate.getYear() + 1, HDate_1.HDateMonth.CHESHVAN) == 30) { return HDate_1.HDate.make(1, HDate_1.HDateMonth.KISLEV, hyear); } else { return HDate_1.HDate.make(29, HDate_1.HDateMonth.CHESHVAN, hyear); } } // Source date on 30 Kislev, target year Kislev has only 29 days if (this.hdate.getMonth() === HDate_1.HDateMonth.KISLEV && this.hdate.getDay() === 30 && HDate_1.HDate.monthLength(hyear, HDate_1.HDateMonth.KISLEV) === 29) { if (this.type === AnniversaryType_1.AnniversaryType.BIRTHDAY) { return HDate_1.HDate.make(1, HDate_1.HDateMonth.TEVET, hyear); } // If on the year that followed the Petira, Kislev had 30 days -> 1Tevet: if (HDate_1.HDate.monthLength(this.hdate.getYear() + 1, HDate_1.HDateMonth.KISLEV) == 30) { return HDate_1.HDate.make(1, HDate_1.HDateMonth.TEVET, hyear); } else { return HDate_1.HDate.make(29, HDate_1.HDateMonth.KISLEV, hyear); } } //Source date Adar simple year, target leap year -> Adar2 if (this.hdate.getMonth() === HDate_1.HDateMonth.ADAR && !this.hdate.isEmbolismic() && HDate_1.HDate.embolismicYear(hyear)) { return this.type === AnniversaryType_1.AnniversaryType.AZCARA && this.rite === Rite_1.Rite.ASHKENAZI ? HDate_1.HDate.make(this.hdate.getDay(), HDate_1.HDateMonth.ADAR, hyear) : HDate_1.HDate.make(this.hdate.getDay(), HDate_1.HDateMonth.ADAR2, hyear); } return HDate_1.HDate.make(this.hdate.getDay(), this.hdate.getMonth(), hyear); } } exports.Anniversary = Anniversary;