3 ms·
When I wrote my time and date library (luatz: https://github.com/daurnimator/luatz https://github.com/daurnimator/luatz ) I originally wrote an implementation o
by daurnimator 12y ago
When I wrote my time and date library (luatz: https://github.com/daurnimator/luatz https://github.com/daurnimator/luatz ) I originally wrote an implementation of the Doomsday rule to figure out the day of the week.
Turns out that sakamoto's algorithm (see https://en.wikipedia.org/wiki/Calculating_the_day_of_the_week#Implementation-dependent_methods_of_Sakamoto.2C_Lachman.2C_Keith_and_Craver https://en.wikipedia.org/wiki/Calculating_the_day_of_the_wee... ) was much faster to calculate and made for cleaner code.
https://github.com/daurnimator/luatz/blob/master/luatz/timetable.lua#L45 https://github.com/daurnimator/luatz/blob/master/luatz/timet...
- apaprocki 12y agoIIRC tzdata just acquired a new version (3) not too long ago and luatz would need to be updated to handle it. You'll only get the new files if they were compiled with a newish zic. This bit me because code I work with is also parsing them :)
- daurnimator 12y agoThanks for mentioning this, I had no idea... and documentation on this fact is sparse. It's not even mentioned on https://www.iana.org/time-zones/repository/tz-link.html https://www.iana.org/time-zones/repository/tz-link.html Created an issue at https://github.com/daurnimator/luatz/issues/2 https://github.com/daurnimator/luatz/issues/2
- rspeer 12y agoRight, the Doomsday Rule is optimized for humans, not computers.
- vorg 12y agoIt seems the algorithm would be better optimized for humans if January and February were always considered to be the last two months of the previous year. We're already used to doing this when working out birth years for Horoscopes and the Chinese calendar. Then we wouldn't need to memorize different dates for Doomsday in Jan and Feb, and instead remember Jan 2, Feb 6, etc.