Last active
April 24, 2023 15:56
-
-
Save mjradwin/0b7c4f2a33acfc30cf8d6235c173187f to your computer and use it in GitHub Desktop.
Displaying today's omer count
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
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
let me start by thanking yall so much for making the amazing api available!!! Chazak u'Baruch
the example code is problematic because it uses ISO dates which changes sooner than our local because of timezones.
I instead wrote this code to yield a true to local time count with a daily text of
Sunday night is 18 days, which is 2 weeks and 4 days of the Omer