From e4500bdbc4e1f857a61a99329e3319c0fd263473 Mon Sep 17 00:00:00 2001 From: Rafi Strauss Date: Fri, 27 Mar 2026 13:57:15 -0400 Subject: [PATCH] fix: implement correct clone for JewishCalendar The getUpcomingParsha function called clone, which created a new JewishDate object instead of a JewishCalendar object. The former lacks the necessary getParsha function causing an error when called: TypeError: clone.getParsha is not a function. (In 'clone.getParsha()', 'clone.getParsha' is undefined) --- src/hebrewcalendar/HebrewDateFormatter.ts | 2 +- src/hebrewcalendar/JewishCalendar.ts | 21 ++++++++++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/hebrewcalendar/HebrewDateFormatter.ts b/src/hebrewcalendar/HebrewDateFormatter.ts index ab39a3e..bb21ec0 100644 --- a/src/hebrewcalendar/HebrewDateFormatter.ts +++ b/src/hebrewcalendar/HebrewDateFormatter.ts @@ -487,7 +487,7 @@ export class HebrewDateFormatter { // This method is only about formatting, so we shouldn't make any changes to the params passed in... // eslint-disable-next-line @typescript-eslint/naming-convention - const _jewishCalendar = jewishCalendar.clone() as JewishCalendar; + const _jewishCalendar = jewishCalendar.clone(); _jewishCalendar.setJewishMonth(month); formattedRoshChodesh = this.hebrewFormat ? HebrewDateFormatter.hebrewHolidays[JewishCalendar.ROSH_CHODESH] : this.transliteratedHolidays[JewishCalendar.ROSH_CHODESH]; diff --git a/src/hebrewcalendar/JewishCalendar.ts b/src/hebrewcalendar/JewishCalendar.ts index 9f19cdf..c59bd42 100644 --- a/src/hebrewcalendar/JewishCalendar.ts +++ b/src/hebrewcalendar/JewishCalendar.ts @@ -594,7 +594,7 @@ export class JewishCalendar extends JewishDate { * @return the upcoming parsha. */ public getUpcomingParsha(): Parsha { - const clone: JewishCalendar = this.clone() as JewishCalendar; + const clone: JewishCalendar = this.clone(); const daysToShabbos: number = (Calendar.SATURDAY - this.getDayOfWeek() + 7) % 7; if (this.getDayOfWeek() !== Calendar.SATURDAY) { clone.forward(Calendar.DATE, daysToShabbos); @@ -1270,8 +1270,8 @@ export class JewishCalendar extends JewishDate { */ public isPurim(): boolean { return this.isMukafChoma - ? this.getYomTovIndex() === JewishCalendar.SHUSHAN_PURIM - : this.getYomTovIndex() === JewishCalendar.PURIM; + ? this.getYomTovIndex() === JewishCalendar.SHUSHAN_PURIM + : this.getYomTovIndex() === JewishCalendar.PURIM; } /** @@ -1503,6 +1503,21 @@ export class JewishCalendar extends JewishDate { return holidayIndex === JewishCalendar.ISRU_CHAG; } + /** + * A method that creates a deep copy of the object. + * + * @see Object#clone() + */ + public clone(): JewishCalendar { + const clone: JewishCalendar = new JewishCalendar(this.getJewishYear(), this.getJewishMonth(), this.getJewishDayOfMonth()); + clone.setMoladHours(this.getMoladHours()); + clone.setMoladMinutes(this.getMoladMinutes()); + clone.setMoladChalakim(this.getMoladChalakim()); + clone.setInIsrael(this.getInIsrael()); + clone.setIsMukafChoma(this.getIsMukafChoma()); + return clone; + } + /** * Indicates whether some other object is "equal to" this one. * @see Object#equals(Object)