Skip to content

Commit

Permalink
Add Shabbat Shirah
Browse files Browse the repository at this point in the history
  • Loading branch information
mjradwin committed Mar 14, 2021
1 parent 6690f93 commit 9577ac8
Show file tree
Hide file tree
Showing 11 changed files with 279 additions and 241 deletions.
11 changes: 10 additions & 1 deletion hebcal.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -524,11 +524,20 @@ declare module '@hebcal/core' {
function calendar(options: Options): Event[];

/**
* Returns a Map for the year indexed by HDate.toString()
* Lower-level holidays interface, which returns a `Map` of `Event`s indexed by
* `HDate.toString()`. These events must filtered especially for `flags.IL_ONLY`
* or `flags.CHUL_ONLY` depending on Israel vs. Diaspora holiday scheme
* @param year - Hebrew year
*/
function getHolidaysForYear(year: number): Map<string, Event[]>;

/**
* Returns an array of holidays for the year
* @param year - Hebrew year
* @param il - use the Israeli schedule for holidays
*/
function getHolidaysForYearArray(year: number, il: boolean): Event[];

/**
* Returns an array of Events on this date (or undefined if no events)
* @param date - Hebrew Date, Gregorian date, or absolute R.D. day number
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hebcal/core",
"version": "3.9.1",
"version": "3.10.0",
"author": "Michael J. Radwin (https://github.com/mjradwin)",
"contributors": [
"Eyal Schachter (https://github.com/Scimonster)",
Expand Down Expand Up @@ -70,8 +70,8 @@
},
"devDependencies": {
"@ava/babel": "^1.0.1",
"@babel/core": "^7.12.16",
"@babel/preset-env": "^7.12.16",
"@babel/core": "^7.13.10",
"@babel/preset-env": "^7.13.10",
"@babel/register": "^7.12.13",
"@hebcal/solar-calc": "^1.0.6",
"@rollup/plugin-babel": "^5.3.0",
Expand All @@ -80,13 +80,13 @@
"@rollup/plugin-node-resolve": "^11.2.0",
"ava": "^3.15.0",
"core-js": "^3.8.3",
"eslint": "^7.20.0",
"eslint": "^7.22.0",
"eslint-config-google": "^0.14.0",
"gematriya": "^2.0.0",
"jsdoc": "^3.6.6",
"jsdoc-to-markdown": "^7.0.0",
"nyc": "^15.1.0",
"rollup": "^2.39.0",
"rollup": "^2.41.2",
"rollup-plugin-terser": "^7.0.2",
"tsd-jsdoc": "^2.5.0",
"ttag-cli": "^1.9.1"
Expand Down
3 changes: 3 additions & 0 deletions po/ashkenazi.po
Original file line number Diff line number Diff line change
Expand Up @@ -202,3 +202,6 @@ msgstr "Leil Selichos"

msgid "Shabbat Mevarchim Chodesh"
msgstr "Shabbos Mevorchim Chodesh"

msgid "Shabbat Shirah"
msgstr "Shabbos Shirah"
3 changes: 3 additions & 0 deletions po/he.po
Original file line number Diff line number Diff line change
Expand Up @@ -807,3 +807,6 @@ msgstr "תִּשְׁעָה בְּאָב נִדחֶה"

msgid "Shabbat Mevarchim Chodesh"
msgstr "שַׁבָּת מברכים חוֹדֶשׁ"

msgid "Shabbat Shirah"
msgstr "שַׁבָּת שִׁירָה"
2 changes: 1 addition & 1 deletion src/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export class Event {
this.date = date;
this.desc = desc;
this.mask = +mask;
if (typeof attrs === 'object') {
if (typeof attrs === 'object' && attrs !== null) {
Object.keys(attrs).forEach((k) => this[k] = attrs[k]);
}
}
Expand Down
27 changes: 27 additions & 0 deletions src/hebcal.js
Original file line number Diff line number Diff line change
Expand Up @@ -934,10 +934,37 @@ export const HebrewCalendar = {
add(new MevarchimChodeshEvent(new HDate(29, month, year).onOrBefore(SAT), nextMonthName));
}

const sedra = new Sedra(year, false);
const beshalachIdx = sedra.getSedraArray().indexOf(15);
const beshalachHd = new HDate(sedra.getFirstSaturday() + (beshalachIdx * 7));
add(new HolidayEvent(beshalachHd, 'Shabbat Shirah', SPECIAL_SHABBAT));

__cache[year] = h;
return h;
},

/**
* Returns an array of holidays for the year
* @param {number} year Hebrew year
* @param {boolean} il use the Israeli schedule for holidays
* @return {Event[]}
*/
getHolidaysForYearArray: function(year, il) {
const yearMap = HebrewCalendar.getHolidaysForYear(year);
const startAbs = HDate.hebrew2abs(year, TISHREI, 1);
const endAbs = HDate.hebrew2abs(year + 1, TISHREI, 1) - 1;
const events = [];
for (let absDt = startAbs; absDt <= endAbs; absDt++) {
const hd = new HDate(absDt);
const holidays = yearMap.get(hd.toString());
if (holidays) {
const filtered = holidays.filter((ev) => (il && ev.observedInIsrael()) || (!il && ev.observedInDiaspora()));
filtered.forEach((ev) => events.push(ev));
}
}
return events;
},

/**
* Returns an array of Events on this date (or undefined if no events)
* @param {HDate|Date|number} date Hebrew Date, Gregorian date, or absolute R.D. day number
Expand Down
18 changes: 9 additions & 9 deletions src/hebcal.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ test('greg-year', (t) => {
year: 1993,
};
const events = HebrewCalendar.calendar(options);
t.is(events.length, 82);
t.is(events.length, 83);
t.is(events[0].getDesc(), 'Asara B\'Tevet');
t.is(gregDtString(events[0]), '1/3/1993');
t.is(events[70].getDesc(), 'Chanukah: 1 Candle');
t.is(gregDtString(events[70]), '12/8/1993');
t.is(events[81].getDesc(), 'Asara B\'Tevet');
t.is(gregDtString(events[81]), '12/24/1993');
t.is(events[71].getDesc(), 'Chanukah: 1 Candle');
t.is(gregDtString(events[71]), '12/8/1993');
t.is(events[events.length - 1].getDesc(), 'Asara B\'Tevet');
t.is(gregDtString(events[events.length - 1]), '12/24/1993');
});

test('getStartAndEnd-2digit', (t) => {
Expand Down Expand Up @@ -84,7 +84,7 @@ test('heb-year', (t) => {
isHebrewYear: true,
};
const events = HebrewCalendar.calendar(options);
t.is(events.length, 83);
t.is(events.length, 84);
t.is(events[0].getDesc(), 'Erev Rosh Hashana');
t.is(gregDtString(events[0]), '9/11/1988');
t.is(events[1].getDesc(), 'Rosh Hashana 5749');
Expand All @@ -93,8 +93,8 @@ test('heb-year', (t) => {
t.is(gregDtString(events[2]), '9/13/1988');
t.is(events[5].getDesc(), 'Erev Yom Kippur');
t.is(gregDtString(events[5]), '9/20/1988');
t.is(events[82].getDesc(), 'Erev Rosh Hashana');
t.is(gregDtString(events[82]), '9/29/1989');
t.is(events[events.length - 1].getDesc(), 'Erev Rosh Hashana');
t.is(gregDtString(events[events.length - 1]), '9/29/1989');
});

test('no-options', (t) => {
Expand Down Expand Up @@ -413,7 +413,7 @@ test('molad', (t) => {

test('year2', (t) => {
const events = HebrewCalendar.calendar({year: 2});
t.is(events.length, 79);
t.is(events.length, 80);
});

test('year1', (t) => {
Expand Down
Loading

0 comments on commit 9577ac8

Please sign in to comment.