<?xml version='1.0' encoding='utf-8' ?>

<rss version='2.0' xmlns:lj='http://www.livejournal.org/rss/lj/1.0/' xmlns:atom10='http://www.w3.org/2005/Atom'>
<channel>
  <title>Monica</title>
  <link>https://cellio.dreamwidth.org/</link>
  <description>Monica - Dreamwidth Studios</description>
  <lastBuildDate>Wed, 02 Jun 2021 02:33:45 GMT</lastBuildDate>
  <generator>LiveJournal / Dreamwidth Studios</generator>
  <lj:journal>cellio</lj:journal>
  <lj:journaltype>personal</lj:journaltype>
  <image>
    <url>https://v.dreamwidth.org/63765/58489</url>
    <title>Monica</title>
    <link>https://cellio.dreamwidth.org/</link>
    <width>96</width>
    <height>96</height>
  </image>

<item>
  <guid isPermaLink='true'>https://cellio.dreamwidth.org/2099761.html</guid>
  <pubDate>Wed, 02 Jun 2021 02:33:45 GMT</pubDate>
  <title>Oh for crying out loud (thank you Javascript!)</title>
  <link>https://cellio.dreamwidth.org/2099761.html</link>
  <description>&lt;p&gt;We have a widget on our site that displays the current Hebrew date.  We&apos;re using HebCal&apos;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&apos;s date, extract a string of the right format from that, and look up &quot;today&quot; 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.&lt;/p&gt;

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

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;Guess what.  Date.toISOString &lt;em&gt;does not use the local time&lt;/em&gt;.  FFS.  I&apos;ve been banging my head against a wall for two hours thinking it was something more esoteric, maybe having to do with that &quot;start at 8PM&quot; 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&apos;s June 2 but today.getDay() says it&apos;s June 1.&lt;/p&gt;

&lt;p&gt;So now I have to &lt;s&gt;write&lt;/s&gt; Google for code that constructs the proper format for the &lt;em&gt;local&lt;/em&gt; 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!)&lt;/p&gt;
&lt;br /&gt;&lt;br /&gt;&lt;img src=&quot;https://www.dreamwidth.org/tools/commentcount?user=cellio&amp;ditemid=2099761&quot; width=&quot;30&quot; height=&quot;12&quot; alt=&quot;comment count unavailable&quot; style=&quot;vertical-align: middle;&quot;/&gt; comments</description>
  <comments>https://cellio.dreamwidth.org/2099761.html</comments>
  <category>programming</category>
  <lj:security>public</lj:security>
  <lj:reply-count>1</lj:reply-count>
</item>
</channel>
</rss>
