Ask HN: Did you encounter any leap year bugs today?
524 pointsAfter a frantic scramble this morning, our billing team has finished patching a bug which erroneously was charging our monthly subscribers for an extra day.
All test suites are passing now, and SRE has scheduled a postmortem after the QA confirms the fix in 2028.
Comments (481) 159 threads
Earlier commentsThen today I get home from work, un-suspend that same laptop and the time and date are both wrong now. It has it as around 10pm last night. Turn off auto updates and turn that back on, and nothing happens. Wait 4 or 5 minutes, nothing happens. So I finally decided to reboot, which does indeed clear things up. Only then did I remember that today is Feb 29th and make the connection that this might be related to the leap year.
Can't say for 100% certain that it was, but it would be one hell of a coincidence otherwise.
Given how many devs/techies/linux users/(and even non-techy users of tech) will encounter random time or date related bugs and problems every year, it would be surprising if there weren't a few people getting that coincidence every time a Feb 29th rolls round (or put another way, it seems likely that there's more than one person in the world having a similar "no idea what caused that" date/time bug every day of the year, including this one). So maybe related, but I wouldn't call it one hell of a coincidence if it's not related.
If you just take the naive approach and calculate everything as unix timestamp deltas, “yesterday” in human terms will still be 86400 seconds ago. No difference leap day or not.
If you use a date library with fancy “subtract one day” functions, it should also be handled automatically. Just like you don’t have to care that March has 31 days and April 30? No difference if leap day or not.
Someone must have spent a lot of effort to manually create date logic, hard coding the number of days in a month or something?
Only other edge case is if someone takes a 2024-02-29 timestamp and modify the year part, without using date library to do so. That should be rare, only use case is a yearly report. That’s not something that should take down the whole billing system.
Date library does not help here, for example, both Python and Java's date library [0][1] have only "days" in their timedelta/Duration constructor. Month and year are ambiguous. What would you do if you want someone's birthday this year? The most obvious way:
is just broken. The second line throws.[0] https://docs.python.org/3/library/datetime.html#datetime.tim...
[1] https://docs.oracle.com/javase/8/docs/api/java/time/Duration...
It may not have the convenient "years" method directly, but you can add an arbitrary unit of time quite easily
Example with datetime: It even supports decades, centuries, eras and half days :-)Example with duration:
For those curious about how it handles leap years:
Another use case: you create a pair of cryptographic certificates with a validity period of 1 year. The other side rejects the certificate because of an invalid date. This happened 12 years ago to Azure: https://azure.microsoft.com/en-us/blog/summary-of-windows-az...
All comments shown.
Couldn't load more comments. Check your connection and try again.