From 92ba3544caf3c079fedaf27d74a49f3dde70d3aa Mon Sep 17 00:00:00 2001 From: "Michael J. Radwin" Date: Mon, 23 Dec 2024 15:17:31 -0800 Subject: [PATCH] Fix translations for Yom Kippur Katan --- package-lock.json | 4 ++-- package.json | 2 +- size-demo/rollup.config.ts | 8 -------- src/HolidayEvent.ts | 8 ++------ src/calendar.ts | 6 +++++- src/candles.ts | 38 ++++++++++++++++++++++---------------- src/event.ts | 8 ++------ test/hebcal.spec.ts | 4 ++++ 8 files changed, 38 insertions(+), 40 deletions(-) diff --git a/package-lock.json b/package-lock.json index a2b9117..3a7dc3f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@hebcal/core", - "version": "5.8.6", + "version": "5.8.8", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@hebcal/core", - "version": "5.8.6", + "version": "5.8.8", "license": "GPL-2.0", "dependencies": { "@babel/runtime": "^7.26.0", diff --git a/package.json b/package.json index 9ca7b99..4476005 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@hebcal/core", - "version": "5.8.7", + "version": "5.8.8", "author": "Michael J. Radwin (https://github.com/mjradwin)", "contributors": [ "Eyal Schachter (https://github.com/Scimonster)", diff --git a/size-demo/rollup.config.ts b/size-demo/rollup.config.ts index 6411159..1ae9baa 100644 --- a/size-demo/rollup.config.ts +++ b/size-demo/rollup.config.ts @@ -2,7 +2,6 @@ import prettyBytes from 'pretty-bytes'; import {defineConfig, OutputChunk, Plugin, RollupOptions} from 'rollup'; import {nodeResolve} from '@rollup/plugin-node-resolve'; import commonjs from '@rollup/plugin-commonjs'; -import babel from '@rollup/plugin-babel'; import bundleSize from 'rollup-plugin-bundle-size'; import json from '@rollup/plugin-json'; import terser from '@rollup/plugin-terser'; @@ -11,13 +10,6 @@ import {appendFileSync, readdirSync, writeFileSync} from 'fs'; import {basename} from 'path'; import {visualizer} from 'rollup-plugin-visualizer'; -const TARGETS_BROWSER = { - chrome: '103', - firefox: '91', - edge: '84', - safari: '15.6', -}; - const sizeFile = './size-demo/sizes.md'; writeFileSync(sizeFile, '# Bundle sizes\n\n'); diff --git a/src/HolidayEvent.ts b/src/HolidayEvent.ts index aed9489..38da757 100644 --- a/src/HolidayEvent.ts +++ b/src/HolidayEvent.ts @@ -104,12 +104,8 @@ export class HolidayEvent extends Event { */ clone(): HolidayEvent { const ev = new HolidayEvent(this.date, this.desc, this.mask); - for (const property in this) { - // eslint-disable-next-line no-prototype-builtins - if (this.hasOwnProperty(property)) { - Object.defineProperty(ev, property, {value: this[property]}); - } - } + // overwrite all enumerable properties + Object.assign(ev, this); return ev; } } diff --git a/src/calendar.ts b/src/calendar.ts index a7f6fcd..62342cd 100644 --- a/src/calendar.ts +++ b/src/calendar.ts @@ -597,7 +597,11 @@ function appendHolidayAndRelated( const isMajorFast = Boolean(eFlags & MAJOR_FAST); const isMinorFast = Boolean(eFlags & MINOR_FAST); let fastEv; - if (options.candlelighting && (isMajorFast || isMinorFast)) { + if ( + options.candlelighting && + (isMajorFast || isMinorFast) && + ev.getDesc() !== 'Yom Kippur' + ) { ev = fastEv = makeFastStartEnd(ev, options); if ( fastEv.startEvent && diff --git a/src/candles.ts b/src/candles.ts index 5dacab3..3603cba 100644 --- a/src/candles.ts +++ b/src/candles.ts @@ -1,5 +1,5 @@ /* eslint-disable max-len */ -import {HDate, months, isoDateString} from '@hebcal/hdate'; +import {HDate, months} from '@hebcal/hdate'; import {CalOptions} from './CalOptions'; import {Location} from './location'; import {Event, flags} from './event'; @@ -72,33 +72,39 @@ const FAST_ENDS = 'Fast ends'; /** A fast day also contains a start and end time */ export class FastDayEvent extends HolidayEvent { + /** original event */ + readonly linkedEvent: HolidayEvent; /** this will be a "Fast begins" event */ readonly startEvent?: TimedEvent; /** this will be a "Fast ends" event */ readonly endEvent?: TimedEvent; constructor( - date: HDate, - desc: string, - mask: number, + linkedEvent: HolidayEvent, startEvent?: TimedEvent, endEvent?: TimedEvent ) { - super(date, desc, mask); + super(linkedEvent.getDate(), linkedEvent.getDesc(), linkedEvent.getFlags()); + this.linkedEvent = linkedEvent; this.startEvent = startEvent; this.endEvent = endEvent; } + render(locale?: string): string { + return this.linkedEvent.render(locale); + } + renderBrief(locale?: string): string { + return this.linkedEvent.renderBrief(locale); + } urlDateSuffix(): string { - if (this.getDesc() === "Asara B'Tevet") { - const isoDate = isoDateString(this.getDate().greg()); - return isoDate.replace(/-/g, ''); - } - return super.urlDateSuffix(); + return this.linkedEvent.urlDateSuffix(); } url(): string | undefined { - if (this.getFlags() & flags.YOM_KIPPUR_KATAN) { - return undefined; - } - return super.url(); + return this.linkedEvent.url(); + } + getEmoji(): string { + return this.linkedEvent.getEmoji(); + } + getCategories(): string[] { + return this.linkedEvent.getCategories(); } } @@ -112,7 +118,7 @@ export function makeFastStartEnd( ): FastDayEvent { const desc = ev.getDesc(); if (desc === 'Yom Kippur') { - return ev; + throw new RangeError('YK does not require this function'); } const hd = ev.getDate(); const dt = hd.greg(); @@ -147,7 +153,7 @@ export function makeFastStartEnd( } } } - const ev2 = new FastDayEvent(hd, desc, ev.getFlags(), startEvent, endEvent); + const ev2 = new FastDayEvent(ev, startEvent, endEvent); // copy properties such as memo or emoji Object.assign(ev2, ev); return ev2; diff --git a/src/event.ts b/src/event.ts index df7ca4a..dfb6542 100644 --- a/src/event.ts +++ b/src/event.ts @@ -236,12 +236,8 @@ export class Event { */ clone(): Event { const ev = new Event(this.date, this.desc, this.mask); - for (const property in this) { - // eslint-disable-next-line no-prototype-builtins - if (this.hasOwnProperty(property)) { - Object.defineProperty(ev, property, {value: this[property]}); - } - } + // overwrite all enumerable properties + Object.assign(ev, this); return ev; } /** diff --git a/test/hebcal.spec.ts b/test/hebcal.spec.ts index b9691ac..171a6ec 100644 --- a/test/hebcal.spec.ts +++ b/test/hebcal.spec.ts @@ -591,6 +591,8 @@ test('ykk-only', () => { expect(ev).toBeInstanceOf(YomKippurKatanEvent); expect(ev.url()).toBeUndefined(); expect(ev.memo).toBe('Minor Day of Atonement on the day preceeding Rosh Chodesh Kislev'); + expect(ev.render('en')).toBe('Yom Kippur Katan Kislev'); + expect(ev.render('he')).toBe('יוֹם כִּפּוּר קָטָן כִּסְלֵו'); }); test('ykk with location copies attributes from src', () => { @@ -614,6 +616,8 @@ test('ykk with location copies attributes from src', () => { expect(ev).toBeInstanceOf(FastDayEvent); expect(ev.url()).toBeUndefined(); expect(ev.memo).toBe('Minor Day of Atonement on the day preceeding Rosh Chodesh Adar'); + expect(ev.render('en')).toBe('Yom Kippur Katan Adar'); + expect(ev.render('he')).toBe('יוֹם כִּפּוּר קָטָן אַדָר'); }); test('hallel', () => {