n8n-nodes-hebrew-calendar
Version:
n8n community node for Hebrew Calendar operations - check if dates are Shabbat, holidays, or Chol Hamoed
279 lines • 13.2 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.HebrewCalendar = void 0;
const n8n_workflow_1 = require("n8n-workflow");
const HebrewCalendarDescription_1 = require("./HebrewCalendarDescription");
class HebrewCalendar {
constructor() {
this.description = {
displayName: 'Hebrew Calendar',
name: 'hebrewCalendar',
icon: { light: 'file:hebrew-calendar.svg', dark: 'file:hebrew-calendar.svg' },
group: ['transform'],
version: 1,
subtitle: '={{$parameter["operation"]}}',
description: 'Check Hebrew calendar dates, Shabbat times, and Jewish holidays',
defaults: {
name: 'Hebrew Calendar',
},
inputs: ["main"],
outputs: ["main"],
usableAsTool: true,
properties: [
{
displayName: 'Operation',
name: 'operation',
type: 'options',
noDataExpression: true,
options: [
{
name: 'Check Date Status',
value: 'checkDateStatus',
description: 'Check if a date is Shabbat, holiday, or Chol Hamoed',
action: 'Check if date is shabbat or holiday',
},
{
name: 'Get Shabbat Times',
value: 'getShabbatTimes',
description: 'Get candle lighting and Havdalah times for Shabbat',
action: 'Get shabbat candle lighting and havdalah times',
},
{
name: 'Get Holiday Info',
value: 'getHolidayInfo',
description: 'Get detailed information about Jewish holidays in a date range',
action: 'Get jewish holiday information',
},
],
default: 'checkDateStatus',
},
...HebrewCalendarDescription_1.hebrewCalendarOperations,
...HebrewCalendarDescription_1.hebrewCalendarFields,
],
};
}
async execute() {
const items = this.getInputData();
const returnData = [];
const getGeonameId = (location) => {
const locationMap = {
'Tel Aviv': '293397',
'Jerusalem': '281184',
'Haifa': '294801',
'Netanya': '293286',
'Ashdod': '295620',
'Rishon LeZion': '293308',
'Petah Tikva': '293359',
'Beersheba': '295530',
'Holon': '294421',
'Bnei Brak': '295432'
};
return locationMap[location] || '293397';
};
const makeHebcalRequest = async (url) => {
const options = {
method: 'GET',
url: url,
headers: {
'Accept': 'application/json',
'User-Agent': 'n8n-hebrew-calendar-node/1.0'
},
timeout: 10000,
};
try {
const response = await this.helpers.httpRequest(options);
return response;
}
catch (error) {
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Failed to fetch Hebrew calendar data: ${error.message}`);
}
};
const isTimeWithinShabbat = (targetDateTime, candleLighting, havdalah) => {
if (!candleLighting || !havdalah) {
return false;
}
const candleTime = new Date(candleLighting);
const havdalahTime = new Date(havdalah);
return targetDateTime >= candleTime && targetDateTime <= havdalahTime;
};
for (let i = 0; i < items.length; i++) {
try {
const operation = this.getNodeParameter('operation', i);
const checkTime = this.getNodeParameter('checkTime', i, false);
const includeCholHamoed = this.getNodeParameter('includeCholHamoed', i, true);
const location = this.getNodeParameter('location', i, 'Tel Aviv');
let responseData = {};
if (operation === 'checkDateStatus') {
const targetDate = this.getNodeParameter('targetDate', i);
const targetTime = this.getNodeParameter('targetTime', i, '12:00');
const geonameid = getGeonameId(location);
const hebcalUrl = `https://www.hebcal.com/hebcal?v=1&cfg=json&maj=on&min=on&mod=on&nx=on&i=on&leyning=off&start=${targetDate}&end=${targetDate}&geo=geoname&geonameid=${geonameid}&c=on&M=on&s=on`;
const response = await makeHebcalRequest(hebcalUrl);
const targetDateTime = new Date(`${targetDate}T${targetTime}`);
const items = response.items || [];
responseData = {
date: targetDate,
time: targetTime,
location: location,
isShabbat: false,
isHoliday: false,
isCholHamoed: false,
isSpecialDay: false,
eventType: 'weekday',
events: [],
candleLighting: null,
havdalah: null,
checkTime: checkTime,
timeBasedResult: null
};
for (const item of items) {
const itemDate = new Date(item.date);
const itemDateStr = itemDate.toISOString().split('T')[0];
if (itemDateStr === targetDate) {
responseData.events.push({
title: item.title,
category: item.category,
subcat: item.subcat,
hebrew: item.hebrew,
date: item.date
});
if (item.category === 'holiday') {
responseData.isHoliday = true;
responseData.eventType = 'holiday';
if (item.title.includes('Chol Hamoed') || item.title.includes('חול המועד')) {
responseData.isCholHamoed = true;
responseData.eventType = 'chol-hamoed';
}
}
if (item.category === 'parashat' || item.title.includes('Shabbat')) {
responseData.isShabbat = true;
if (responseData.eventType === 'weekday') {
responseData.eventType = 'shabbat';
}
}
if (item.category === 'candles') {
responseData.candleLighting = item.date;
}
if (item.category === 'havdalah') {
responseData.havdalah = item.date;
}
}
}
if (checkTime && responseData.isShabbat) {
responseData.timeBasedResult = isTimeWithinShabbat(targetDateTime, responseData.candleLighting, responseData.havdalah);
}
responseData.isSpecialDay = responseData.isHoliday || responseData.isShabbat ||
(includeCholHamoed && responseData.isCholHamoed);
}
else if (operation === 'getShabbatTimes') {
const targetDate = this.getNodeParameter('targetDate', i);
const geonameid = getGeonameId(location);
const hebcalUrl = `https://www.hebcal.com/hebcal?v=1&cfg=json&maj=on&min=on&mod=on&nx=on&i=on&leyning=off&start=${targetDate}&end=${targetDate}&geo=geoname&geonameid=${geonameid}&c=on&M=on&s=on`;
const response = await makeHebcalRequest(hebcalUrl);
const items = response.items || [];
responseData = {
date: targetDate,
location: location,
candleLighting: null,
havdalah: null,
parashat: null,
events: []
};
for (const item of items) {
if (item.category === 'candles') {
responseData.candleLighting = {
time: item.date,
title: item.title,
hebrew: item.hebrew
};
}
else if (item.category === 'havdalah') {
responseData.havdalah = {
time: item.date,
title: item.title,
hebrew: item.hebrew
};
}
else if (item.category === 'parashat') {
responseData.parashat = {
title: item.title,
hebrew: item.hebrew
};
}
responseData.events.push({
title: item.title,
category: item.category,
date: item.date,
hebrew: item.hebrew
});
}
}
else if (operation === 'getHolidayInfo') {
const startDate = this.getNodeParameter('startDate', i);
const endDate = this.getNodeParameter('endDate', i);
const geonameid = getGeonameId(location);
const hebcalUrl = `https://www.hebcal.com/hebcal?v=1&cfg=json&maj=on&min=on&mod=on&nx=on&i=on&leyning=off&start=${startDate}&end=${endDate}&geo=geoname&geonameid=${geonameid}`;
const response = await makeHebcalRequest(hebcalUrl);
const items = response.items || [];
let holidays = [];
let shabbatot = [];
let cholHamoed = [];
let other = [];
for (const item of items) {
if (item.category === 'holiday') {
if (item.title.includes('Chol Hamoed') || item.title.includes('חול המועד')) {
if (includeCholHamoed) {
cholHamoed.push(item);
}
}
else {
holidays.push(item);
}
}
else if (item.category === 'parashat') {
shabbatot.push(item);
}
else {
other.push(item);
}
}
responseData = {
dateRange: {
start: startDate,
end: endDate
},
location: location,
summary: {
totalEvents: items.length,
holidays: holidays.length,
shabbatot: shabbatot.length,
cholHamoed: cholHamoed.length,
other: other.length
},
holidays: holidays,
shabbatot: shabbatot,
cholHamoed: cholHamoed,
other: other
};
}
returnData.push({
json: responseData,
pairedItem: { item: i },
});
}
catch (error) {
if (this.continueOnFail()) {
returnData.push({
json: { error: error.message },
pairedItem: { item: i },
});
continue;
}
throw error;
}
}
return [returnData];
}
}
exports.HebrewCalendar = HebrewCalendar;
//# sourceMappingURL=HebrewCalendar.node.js.map