UNPKG

@hebcal/core

Version:

A perpetual Jewish Calendar API

98 lines (95 loc) 3.39 kB
/*! @hebcal/core v5.10.1, distributed under GPLv2 https://www.gnu.org/licenses/gpl-2.0.txt */ import { Locale } from '@hebcal/hdate'; import { Event } from './event.js'; import { reformatTimeStr } from './reformatTimeStr.js'; import { Zmanim } from './zmanim.js'; import './locale.js'; /** An event that has an `eventTime` and `eventTimeStr` */ class TimedEvent extends Event { /** * @param desc Description (not translated) */ constructor(date, desc, mask, eventTime, location, linkedEvent, options) { super(date, desc, mask); this.eventTime = Zmanim.roundTime(eventTime); this.location = location; const timeFormat = location.getTimeFormatter(); this.eventTimeStr = Zmanim.formatTime(this.eventTime, timeFormat); const opts = Object.assign(Object.assign({}, options), { location }); this.fmtTime = reformatTimeStr(this.eventTimeStr, 'pm', opts); if (typeof linkedEvent !== 'undefined') { this.linkedEvent = linkedEvent; } } /** * @param [locale] Optional locale name (defaults to active locale). */ render(locale) { return Locale.gettext(this.getDesc(), locale) + ': ' + this.fmtTime; } /** * Returns translation of "Candle lighting" without the time. * @param [locale] Optional locale name (defaults to active locale). */ renderBrief(locale) { return Locale.gettext(this.getDesc(), locale); } getCategories() { const desc = this.getDesc(); switch (desc) { // LIGHT_CANDLES or LIGHT_CANDLES_TZEIS case 'Candle lighting': return ['candles']; // YOM_TOV_ENDS case 'Havdalah': return ['havdalah']; // flags.MINOR_FAST or flags.MAJOR_FAST case 'Fast begins': case 'Fast ends': return ['zmanim', 'fast']; } /* NOTREACHED */ return ['unknown']; } } /** Candle lighting before Shabbat or holiday */ class CandleLightingEvent extends TimedEvent { constructor(date, mask, eventTime, location, linkedEvent, options) { super(date, 'Candle lighting', mask, eventTime, location, linkedEvent, options); } getEmoji() { return '🕯️'; } } /** Havdalah after Shabbat or holiday */ class HavdalahEvent extends TimedEvent { constructor(date, mask, eventTime, location, havdalahMins, linkedEvent, options) { super(date, 'Havdalah', mask, eventTime, location, linkedEvent, options); if (havdalahMins) { this.havdalahMins = havdalahMins; } } /** * @param [locale] Optional locale name (defaults to active locale). */ render(locale) { return this.renderBrief(locale) + ': ' + this.fmtTime; } /** * Returns translation of "Havdalah" without the time. * @param [locale] Optional locale name (defaults to active locale). */ renderBrief(locale) { let str = Locale.gettext(this.getDesc(), locale); if (this.havdalahMins) { const min = Locale.gettext('min', locale); str += ` (${this.havdalahMins} ${min})`; } return str; } getEmoji() { return '✨'; } } export { CandleLightingEvent, HavdalahEvent, TimedEvent }; //# sourceMappingURL=TimedEvent.js.map