Skip to content

Commit

Permalink
Support new Fast begins / Fast ends
Browse files Browse the repository at this point in the history
  • Loading branch information
mjradwin committed Nov 24, 2020
1 parent 7cc71ef commit d841e63
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 19 deletions.
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hebcal/icalendar",
"version": "2.7.0",
"version": "2.8.0",
"author": "Michael J. Radwin (https://github.com/mjradwin)",
"keywords": [
"ical",
Expand All @@ -23,8 +23,8 @@
"url": "https://github.com/hebcal/hebcal-icalendar/issues"
},
"dependencies": {
"@hebcal/core": "^2.6.1",
"@hebcal/rest-api": "^2.7.2",
"@hebcal/core": "^2.7.0",
"@hebcal/rest-api": "^2.8.0",
"md5": "^2.3.0"
},
"scripts": {
Expand Down Expand Up @@ -55,19 +55,19 @@
},
"devDependencies": {
"@ava/babel": "^1.0.1",
"@babel/core": "^7.12.3",
"@babel/core": "^7.12.8",
"@babel/polyfill": "^7.12.1",
"@babel/preset-env": "^7.12.1",
"@babel/preset-env": "^7.12.7",
"@babel/register": "^7.12.1",
"@rollup/plugin-babel": "^5.2.1",
"@rollup/plugin-commonjs": "^15.1.0",
"@rollup/plugin-commonjs": "^16.0.0",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^9.0.0",
"@rollup/plugin-node-resolve": "^10.0.0",
"ava": "^3.13.0",
"eslint": "^7.12.0",
"eslint": "^7.14.0",
"eslint-config-google": "^0.14.0",
"jsdoc": "^3.6.6",
"jsdoc-to-markdown": "^6.0.1",
"rollup": "^2.32.1"
"rollup": "^2.33.3"
}
}
14 changes: 4 additions & 10 deletions src/icalendar.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/* eslint-disable max-len */
import {flags, Locale} from '@hebcal/core';
import md5 from 'md5';
import {pad2, getCalendarTitle, makeAnchor, getHolidayDescription, makeTorahMemoText} from '@hebcal/rest-api';
import {pad2, getCalendarTitle, renderTitleWithoutTime, makeAnchor,
getHolidayDescription, makeTorahMemoText} from '@hebcal/rest-api';
import fs from 'fs';
import {Readable} from 'stream';
import {version} from '../package.json';
Expand Down Expand Up @@ -87,10 +88,10 @@ function appendTrackingToUrl(url, il) {
*/
export function eventToIcal(e, options) {
const dtstamp = options.dtstamp || makeDtstamp(new Date());
let subj = e.render();
const timed = Boolean(e.eventTime);
let subj = timed ? renderTitleWithoutTime(e) : e.render();
const desc = e.getDesc(); // original untranslated
const mask = e.getFlags();
const timed = Boolean(e.eventTime);
const candles = (desc === 'Havdalah' || desc === 'Candle lighting');
let location;
if (timed && options.location.name) {
Expand Down Expand Up @@ -119,13 +120,6 @@ export function eventToIcal(e, options) {
startDate += 'T' + pad2(hour) + pad2(minute) + '00';
endDate = startDate;
dtargs = `;TZID=${options.location.tzid}`;
// replace "Candle lighting: 15:34" with shorter title
if (candles) {
const colon = subj.indexOf(': ');
if (colon != -1) {
subj = subj.substring(0, colon);
}
}
} else {
endDate = formatYYYYMMDD(e.getDate().next().greg());
// for all-day untimed, use DTEND;VALUE=DATE intsead of DURATION:P1D.
Expand Down
18 changes: 18 additions & 0 deletions src/icalendar.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -356,3 +356,21 @@ test('relcalid', async (t) => {
];
t.deepEqual(lines, expected);
});

test('fastStartEnd', (t) => {
const options = {
start: new Date(2021, 5, 27),
end: new Date(2021, 5, 27),
location: Location.lookup('Providence'),
candlelighting: true,
};
const events = HebrewCalendar.calendar(options);
const icals = events.map((ev) => icalendar.eventToIcal(ev, options));
const summary = icals.map((i) => i.split('\r\n').find((s) => s.startsWith('SUMMARY')));
const expected = [
'SUMMARY:Fast begins',
'SUMMARY:Tzom Tammuz',
'SUMMARY:Fast ends',
];
t.deepEqual(summary, expected);
});

0 comments on commit d841e63

Please sign in to comment.