Skip to content

Instantly share code, notes, and snippets.

@indexzero
Last active February 4, 2023 18:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save indexzero/8f36e36afabfff2c28eb706aa7011dd0 to your computer and use it in GitHub Desktop.
Save indexzero/8f36e36afabfff2c28eb706aa7011dd0 to your computer and use it in GitHub Desktop.
Simple Yahrzeit calculator using Hebcal package
# Ignore things not in the gist
*
!facade.js
!hebcal.js
!README.md
!temporal.js
!why.png

Exploring Temporal API with Yahrzeit conversion

  • hebcal.js: uses hebcal package from npm (GPL v3).
  • temporal.js: uses proposal-temporal from TC-39 proposal (MIT)
    • facade.js: implements Temporal.Calendar using hebcal (GPL v3).

Installation

# Bootstrap example
git clone git@gist.github.com:8f36e36afabfff2c28eb706aa7011dd0.git yahrzeit
cd yahrzeit
mv .gitignore.yahrzeit .gitignore
npm install hebcal proposal-temporal

# Run hebcal-based conversion
node ./hebcal.js 

# Run proposal-temporal based conversion using
# a specified Temporal.Calendar-compliant API
CALENDAR_FACADE_PATH='./facade.js' node ./temporal.js

Why?

/**
*
* As per [Hebcal License](https://github.com/hebcal/hebcal-js/blob/master/COPYING)
* the code in this file is provided under the terms of GNU General Public License v3.0
*
*/
const Hebcal = require('hebcal');
const { Temporal, Intl } = require('proposal-temporal');
module.exports = class HebrewCalendar extends Temporal.Calendar {
constructor() {
super();
}
}
/**
*
* As per [Hebcal License](https://github.com/hebcal/hebcal-js/blob/master/COPYING)
* the code in this file is provided under the terms of GNU General Public License v3.0
*
*/
const Hebcal = require('hebcal');
function observeOn(d, conj = '<––>') {
return `${d.year}/${d.month}/${d.day} ${conj} ${d.greg().toDateString()}`;
}
function getYahrzeitDates(hdate, futureYears = 10) {
const iter = new Hebcal.HDate(hdate);
const honor = iter.year;
return [...Array(futureYears + 1).keys()]
.slice(1)
.map(away => {
iter.setFullYear(honor + away);
return new Hebcal.HDate(iter);
});
}
function remember(then, futureYears) {
const yahrzeits = getYahrzeitDates(then, futureYears);
return [
`🕯 Remembering ${observeOn(then)}`,
...yahrzeits.map((remember, away) => {
return `🕐 [+${away + 1}] ${observeOn(remember, 'should be remembered on')}`;
})
];
}
//
// A Jewish individual who is mourning the loss of a loved one typically sits
// shiva.In Judaism, you are considered a mourner when your spouse, mother,
// father, brother, sister or child passes away.Often, other relatives also
// “sit shiva” and mourn with you
//
const remembered = [
remember(new Hebcal.HDate(new Date(2009, 02, 03)), 20),
remember(new Hebcal.HDate(new Date(2016, 06, 02))),
remember(new Hebcal.HDate(new Date(2021, 01, 18)))
];
console.log(
remembered
.map(r => r.join('\n'))
.join('\n\n')
);
/**
*
* (C) Charlie Robbins, 2020
* LICENSE: MIT
*
*/
const { Temporal, Intl } = require('proposal-temporal');
const HebrewCalendar = require(process.env.CALENDAR_FACADE_PATH);
function observeOn(greg, conj = '<––>') {
//
// n.b. this will throw until `facade.js` is fully
// implemented
//
const heb = greg.withCalendar('hebrew')
return `${heb.toDateString()} ${conj} ${d.greg().toDateString()}`;
}
const then = Temporal.Date.from('2016-07-02');
console.log(`🕯 Remembering ${observeOn(then)}`);
const yahrzeitDates = getYahrzeitDates(then)
.forEach((remember, away) => {
console.log(`🕐 [+${away}] ${observeOn(remember, 'should be remembered on')}`);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment