Subject: | Julian Day implementation flaw |
The current "julian_day" implementation is flawed due to first converting to gmtime before performing the operation. The algorithm for calculating the julian day is pre-designed to normalize across all longitudes/timezones (hence all the int() or floor() statements). So "a day", wherever that day resides, regardless of timezone, maps to a particular julian day. By first converting gmtime, for x hours of the day (where x is the gmt offset of your timezone), you will actually be cast into a *different* julian day. Think about it -- for a certain number of hours each day, unless you live in GMT, it will actually be a different date in GMT.
This is easily fixed by removing the first line of the julian_day() procedure, the one that converts to gmtime().
I examined several other implementations of julian_day calculations. With the fix above, your implementation matches these other examples. Otherwise, it's off for x hours of the day.
Thanks!
Matt Sisk