Oh, for crying out loud (thank you Javascript)

We have a widget on our site that displays the current Hebrew date. We're using HebCal's REST API to get the data, which comes back a month at a time -- JSON blob that has one entry for each day, with the secular date, the Hebrew date, and some other information. We use the Javascript Date class to get today's date, extract a string of the right format from that, and look up "today" in that returned collection. Easy, right? The API documentation for Date makes a point of saying that it uses local time, not UTC, which is what we want.

(Because the Hebrew day actually starts at sundown the previous day, we've got some "best effort" code in there that starts the day at 8PM. Not ideal, but we're not looking up local sunsets and suchlike... We also display something like "22 Sivan (Tuesday night and Wednesday)" to make it clear.)

Yeah ok, so we have the local date, and we need to look up an entry in the calendar data. Dates there use ISO format (YYYY-MM-DD). So we get our Date object, which is supposed to be local, and call toISOString() on it.

Guess what. Date.toISOString does not use the local time. FFS. I've been banging my head against a wall for two hours thinking it was something more esoteric, maybe having to do with that "start at 8PM" code (which I had actually commented out to eliminate that possibility). I finally went to an online Javascript tester, one of those sites where you can type in code and run it, and confirmed that right now today.toISOString() says it's June 2 but today.getDay() says it's June 1.

So now I have to write Google for code that constructs the proper format for the local time, which is down to padding numbers with leading zeros if the month or day number is less than 10 and string-munging and...ugh. (Found it easily enough, but sheesh!)