Summary
JewishDate.prototype.clone() constructs new JewishDate(...) rather than new this.constructor(...). Because JewishCalendar extends JewishDate and does not override clone(), calling clone() on a JewishCalendar instance returns a plain JewishDate — losing every JewishCalendar method. Any code that clones a calendar and then calls a subclass method (e.g. getParsha()) throws.
Source
dist/kosher-zmanim.js (v0.9.0), JewishDate.prototype.clone:
JewishDate.prototype.clone = function () {
var clone = new JewishDate(this.jewishYear, this.jewishMonth, this.jewishDay);
clone.setMoladHours(this.moladHours);
clone.setMoladMinutes(this.moladMinutes);
clone.setMoladChalakim(this.moladChalakim);
return clone;
};
Minimal reproduction
const KZ = require('kosher-zmanim');
const jc = new KZ.JewishCalendar(new Date('2026-07-25T12:00:00'));
jc.setInIsrael(false);
const c = jc.clone();
console.log(c instanceof KZ.JewishCalendar); // false (expected true)
console.log(typeof c.getParsha); // undefined
c.getParsha(); // TypeError: c.getParsha is not a function
Expected
clone() on a JewishCalendar should return a JewishCalendar (subclass-preserving), so inherited/consuming methods that rely on clone() don't break.
Suggested fix
Use the runtime constructor so subclasses are preserved, e.g.:
JewishDate.prototype.clone = function () {
var clone = new this.constructor(this.jewishYear, this.jewishMonth, this.jewishDay);
clone.setMoladHours(this.moladHours);
clone.setMoladMinutes(this.moladMinutes);
clone.setMoladChalakim(this.moladChalakim);
return clone;
};
(Alternatively override clone() in JewishCalendar to also carry inIsrael/useModernHolidays state.)
Found while building a daily-Chumash schedule that needed an upcoming-parsha forward search; worked around it by iterating over fresh JewishCalendar instances instead of cloning. Thanks for the library!
Summary
JewishDate.prototype.clone()constructsnew JewishDate(...)rather thannew this.constructor(...). BecauseJewishCalendar extends JewishDateand does not overrideclone(), callingclone()on aJewishCalendarinstance returns a plainJewishDate— losing everyJewishCalendarmethod. Any code that clones a calendar and then calls a subclass method (e.g.getParsha()) throws.Source
dist/kosher-zmanim.js(v0.9.0),JewishDate.prototype.clone:Minimal reproduction
Expected
clone()on aJewishCalendarshould return aJewishCalendar(subclass-preserving), so inherited/consuming methods that rely onclone()don't break.Suggested fix
Use the runtime constructor so subclasses are preserved, e.g.:
(Alternatively override
clone()inJewishCalendarto also carryinIsrael/useModernHolidaysstate.)Found while building a daily-Chumash schedule that needed an upcoming-parsha forward search; worked around it by iterating over fresh
JewishCalendarinstances instead of cloning. Thanks for the library!