hebcal/hebcal-js

Problem with day of year routine

Closed this issue · 2 comments

The day of year routine gives the wrong values for days in May, July, October, and December (all are one too large). Ran the following dates:
Date:

-  Jan 15 |   15   15
-  Feb 23 |   54   54
-  May 16 |  138  137
-  Jul  4 |  187  186
-  Oct 31 |  306  305
-  Dec 25 |  360  359
-  Dec 31 |  367  366

Issue is the value in the equation for tracking short months needs to be 27 instead of 23, ie
doy -= floor((4 * (date.getMonth() + 1) + 23) / 10);
should be
doy -= floor((4 * (date.getMonth() + 1) + 27) / 10);

If you have the extra day on purpose made up elsewhere, i apologize. I was looking for a javascript doy routine that didn't use (date2 - date1) / 86400000 and came across this one, realised Dec 31 was off by one and thought I'd share.

My bad. Apologies, accidentally edited out the +1 to getMonth when I did the testing.