hebcal / hebcal-es6

perpetual Jewish Calendar with holidays, Shabbat and holiday candle lighting and havdalah times, Torah readings, and more
https://hebcal.github.io/api/core/
GNU General Public License v2.0
98 stars 14 forks source link

HDate static functions #443

Closed PupaRebbe closed 3 months ago

PupaRebbe commented 3 months ago

When i run any of these functions it throws a TypeError: hd.[funcName] is not a function. The functions do exist in the source code, but seem to be private. Am i missing something?

var hd = new HDate();
console.log(hd.monthsInYear(hd.getFullYear()));
console.log(hd.monthNum(3));
console.log(hd.daysInYear(hd.getFullYear()));
console.log(hd.longCheshvan(hd.getFullYear()));
console.log(hd.shortKislev(hd.getFullYear()));
console.log(hd.monthFromName("SIVAN"));
console.log(hd.isHDate(hd));
mjradwin commented 3 months ago

Static functions should be called on the HDate class itself and not on an instance of the class.

const {HDate} = require('@hebcal/core');

const year = 5784;
console.log(HDate.monthsInYear(year));
console.log(HDate.monthNum(3));
console.log(HDate.daysInYear(year));
console.log(HDate.longCheshvan(year));
console.log(HDate.shortKislev(year));
console.log(HDate.monthFromName('SIVAN'));
console.log(HDate.isHDate(new HDate()));
console.log(HDate.isHDate(new Date()));
console.log(HDate.isHDate(12345));
console.log(HDate.isHDate('Hello'));
PupaRebbe commented 3 months ago

Interesting because there are other functions categorized as static in the readme and they work on an instance.

const hd = new HDate();
console.log(hd.isLeapYear(hd.getFullYear()));
console.log(hd.daysInMonth(hd.getMonth(), hd.getFullYear()));
console.log(hd.getMonthName(hd.getMonth(), hd.getFullYear()));
mjradwin commented 3 months ago

Please note carefully that for some functions like isLeapYear, there are both instance and static class functions. If you read carefully, you will also note that there is a difference in how many parameters each function accepts

https://github.com/hebcal/hebcal-es6/blob/main/README.md#HDate+isLeapYear

hDate.isLeapYear() ⇒ boolean

Tests if this date occurs during a leap year

Kind: instance method of HDate

https://github.com/hebcal/hebcal-es6/blob/main/README.md#HDate.isLeapYear

HDate.isLeapYear(year) ⇒ boolean

Returns true if Hebrew year is a leap year

Kind: static method of HDate

Param Type Description
year number Hebrew year