Skip to content

Instantly share code, notes, and snippets.

@mjradwin
Last active April 24, 2023 15:56
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 mjradwin/0b7c4f2a33acfc30cf8d6235c173187f to your computer and use it in GitHub Desktop.
Save mjradwin/0b7c4f2a33acfc30cf8d6235c173187f to your computer and use it in GitHub Desktop.
Displaying today's omer count
<div id="hebcal-omer"></div>
<script defer>
function pad2(number) {
if (number < 10) {
return '0' + number;
}
return '' + number;
}
let dt = new Date();
if (dt.getHours() > 19) {
dt.setDate(dt.getDate() + 1);
}
const isoDate = [dt.getFullYear(), pad2(dt.getMonth() + 1), pad2(dt.getDate())].join('-');
const url = `https://www.hebcal.com/hebcal?v=1&cfg=json&o=on&lg=s&start=${isoDate}&end=${isoDate}`;
fetch(url, {method: 'GET', credentials: 'omit'})
.then(response => response.json())
.then(data => {
if (data.items && data.items.length) {
for (const item of data.items) {
if (item.category === 'omer') {
console.log(item);
// You might also choose to display item.omer.count.en or item.omer.sefira.he
document.getElementById('hebcal-omer').innerText = item.title;
}
}
}
});
</script>
@mjradwin
Copy link
Author

Thanks for the feedback. We've updated the gist to use the local date/time object instead of the toISOString() function

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment