UNPKG

@hebcal/core

Version:

A perpetual Jewish Calendar API

51 lines (50 loc) 1.91 kB
import { HDate, Locale, months } from '@hebcal/hdate'; import { Event, flags } from './event'; import { Molad } from './molad'; import './locale'; // Adds Hebrew and Ashkenazic translations const mevarchimChodeshStr = 'Shabbat Mevarchim Chodesh'; /** Represents Mevarchim haChodesh, the announcement of the new month */ export class MevarchimChodeshEvent extends Event { /** * Constructs Mevarchim haChodesh event * @param date Hebrew date event occurs * @param monthName Hebrew month name (not translated) * @param [memo] * @param locale Optional locale name */ constructor(date, monthName, memo, locale) { super(date, `${mevarchimChodeshStr} ${monthName}`, flags.SHABBAT_MEVARCHIM); this.monthName = Locale.gettext(monthName, locale); if (memo) { this.memo = memo; } else { const hyear = date.getFullYear(); const hmonth = date.getMonth(); const monNext = hmonth === HDate.monthsInYear(hyear) ? months.NISAN : hmonth + 1; const molad = new Molad(hyear, monNext); this.memo = molad.render('en', { hour12: false }); } } basename() { return this.getDesc(); } /** * Returns (translated) description of this event * @param [locale] Optional locale name (defaults to empty locale) */ render(locale) { const monthName0 = Locale.gettext(this.monthName, locale); const monthName = monthName0.replace(/'/g, '’'); return Locale.gettext(mevarchimChodeshStr, locale) + ' ' + monthName; } /** * Returns (translated) description of this event * @param [locale] Optional locale name (defaults to empty locale) */ renderBrief(locale) { const str = this.render(locale); const space = str.indexOf(' '); return str.substring(space + 1); } }