Live data from Hacker News

Ask HN: Did you encounter any leap year bugs today?

news.ycombinator.com

131–140 of 498 posts

Re: Ask HN: Did you encounter any leap year bugs today?

#131
I had a unit tests for a Java LocalDate that was being increased by one year. It checked whether the month and day were the same, and failed because the current day (29) didn't equal the year-hence one (28). I changed it to check that the difference between the days was less than two.

Re: Ask HN: Did you encounter any leap year bugs today?

#132
post #69

Why are there so many stories about leap year bugs?

Because programmers take shortcuts. Its easier to type x - 365 than to import Calendar and then date(x) - timedelta(1 year).

And standard library design errors also.

Properly designed date/time API invented relatively recently.

System.DateTime (.NET) - 2002 | System.DateTimeOffset - 2005

Joda time (JVM) - 2005 | java.time - 2014

Temporal (JavaScript) - still experimental

Re: Ask HN: Did you encounter any leap year bugs today?

#133
post #48

I can understand getting the years 2000 (leap), 2100 (not leap), 2200 (not leap), and 2300 (not leap) wrong. But getting the year 2024 wrong is, disappointing, to put it diplomatically.

Those are harder to get wrong, since leap year bugs are almost always from consumers of dates. To screw up a not-a-leap-year-year you'd need to produce a bogus February 29 on a real March 1. Date producers tend to understand how the calendar works better than that.

Re: Ask HN: Did you encounter any leap year bugs today?

#134

The other way around! Today a few services that don't congratulate me on my birthday (on non-leap years) did. I was born on February 29th.

...it occurs to me, when should those services congratulate you? Should it be on February 28 or March 1?

Re: Ask HN: Did you encounter any leap year bugs today?

#136
post #23

Heard from a friend in China: the age calculation portion of the app to schedule a marriage certificate had a bug where they subtracted 22 (legal minimum age) from the year, which resulted in 2002-02-29 which doesn't exist. The app intends to compare this against the user's birth date. The error handling code assumes all errors are from the comparison. The app then rejected all marriage certificate appointments by co…

Haha, that would be quite the appropriate place to put one of those "Please wait and try again" error messages.

"look, today the math just doesn't work out, try tomorrow"

Re: Ask HN: Did you encounter any leap year bugs today?

#137
post #131

I had a unit tests for a Java LocalDate that was being increased by one year. It checked whether the month and day were the same, and failed because the current day (29) didn't equal the year-hence one (28). I changed it to check that the difference between the days was less than two.

Previously your unit test was broken one day every four ish years. Now it's broken every day :)

Re: Ask HN: Did you encounter any leap year bugs today?

#139

The other way around! Today a few services that don't congratulate me on my birthday (on non-leap years) did. I was born on February 29th.

...it occurs to me, when should those services congratulate you? Should it be on February 28 or March 1?

According to the government, Mar 1. Anything that is based on your birthday (driver's license, drinking, signing contracts, etc) all happen on March 1 if there is no Feb 29 that year.

Which makes sense since then it is "after" your birthday.

Post reply on HN