Skip to content

Commit

Permalink
Show Hebrew year in hebdate objects on the 1st of each month
Browse files Browse the repository at this point in the history
  • Loading branch information
mjradwin committed Oct 29, 2021
1 parent ad8dc64 commit d6e413d
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 24 deletions.
30 changes: 15 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hebcal/rest-api",
"version": "3.8.5",
"version": "3.8.6",
"author": "Michael J. Radwin (https://github.com/mjradwin)",
"keywords": [
"hebcal"
Expand All @@ -21,7 +21,7 @@
"url": "https://github.com/hebcal/hebcal-rest-api/issues"
},
"dependencies": {
"@hebcal/core": "^3.26.7",
"@hebcal/core": "^3.27.0",
"@hebcal/leyning": "^4.10.2"
},
"scripts": {
Expand Down
4 changes: 4 additions & 0 deletions rest-api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ declare module '@hebcal/rest-api' {
* Appends utm_source and utm_medium parameters to a URL
*/
export function appendIsraelAndTracking(url: string, il: boolean, utmSource: string, utmMedium: string, utmCampaign?: string): string;
/**
* @private
*/
export function shouldRenderBrief(ev: Event): boolean;
/**
* @param [lang] - language such as 'he' (default 'en-US')
* @param [evPubDate] - if true, use event time as pubDate (false uses lastBuildDate)
Expand Down
5 changes: 2 additions & 3 deletions src/classic-rest-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
getEventCategories,
toISOString,
appendIsraelAndTracking,
shouldRenderBrief,
} from './common';
import countryNames from './countryNames.json';
import holidayDescription from './holidays.json';
Expand Down Expand Up @@ -44,8 +45,6 @@ export function eventsToClassicApi(events, options, leyning=true) {
return result;
}

const BRIEF_FLAGS = flags.DAF_YOMI | flags.HEBREW_DATE;

/**
* Converts a Hebcal event to a classic Hebcal.com JSON API object
* @param {Event} ev
Expand All @@ -63,7 +62,7 @@ export function eventToClassicApiObject(ev, options, leyning=true) {
toISOString(dt);
const categories = getEventCategories(ev);
const mask = ev.getFlags();
let title = timed || (mask & BRIEF_FLAGS) ? ev.renderBrief(options.locale) : ev.render(options.locale);
let title = shouldRenderBrief(ev) ? ev.renderBrief(options.locale) : ev.render(options.locale);
const desc = ev.getDesc();
const candles = desc === 'Havdalah' || desc === 'Candle lighting';
if (candles) {
Expand Down
18 changes: 18 additions & 0 deletions src/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,3 +276,21 @@ export function appendIsraelAndTracking(url, il, utmSource, utmMedium, utmCampai
const campaign = utmCampaign ? `&utm_campaign=${utmCampaign}` : '';
return url + sep + utm + campaign;
}

/**
* @private
* @param {Event} ev
* @return {boolean}
*/
export function shouldRenderBrief(ev) {
if (typeof ev.eventTime !== 'undefined') return true;
const mask = ev.getFlags();
if (mask & flags.HEBREW_DATE) {
const hd = ev.getDate();
return (hd.getDate() === 1) ? false : true;
} else if (mask & flags.DAF_YOMI) {
return true;
} else {
return false;
}
}
6 changes: 2 additions & 4 deletions src/fullcalendar.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import {Locale, flags, Zmanim} from '@hebcal/core';
import {getEventCategories, makeTorahMemoText, toISOString,
appendIsraelAndTracking} from './common';
appendIsraelAndTracking, shouldRenderBrief} from './common';
import holidayDescription from './holidays.json';

const BRIEF_FLAGS = flags.DAF_YOMI | flags.HEBREW_DATE;

/**
* Converts a Hebcal event to a FullCalendar.io object
* @param {Event} ev
Expand All @@ -19,7 +17,7 @@ export function eventToFullCalendar(ev, tzid, il) {
classes.push('yomtov');
}
const timed = Boolean(ev.eventTime);
const title = timed || (mask & BRIEF_FLAGS) ? ev.renderBrief() : ev.render();
const title = shouldRenderBrief(ev) ? ev.renderBrief() : ev.render();
const start = timed ?
Zmanim.formatISOWithTimeZone(tzid, ev.eventTime) :
toISOString(ev.getDate().greg());
Expand Down

0 comments on commit d6e413d

Please sign in to comment.