Live data from Hacker News

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

news.ycombinator.com

151–160 of 498 posts

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

#151
post #100

Earlier quoted context omitted.

That makes it weird though, because 1900 was a leap year? I sort of get it, but it's a slightly odd and inconsistent decision. Edit: no it's not, it's absolutely correct, leap years just aren't as simple as I thought!

It wasn't. https://learn.microsoft.com/sl-SI/office/troubleshoot/excel/...

Crikey - more helpful to me is the page linked from there - https://learn.microsoft.com/sl-SI/office/troubleshoot/excel/...

> However, there is still a small error that must be accounted for. To eliminate this error, the Gregorian calendar stipulates that a year that is evenly divisible by 100 (for example, 1900) is a leap year only if it is also evenly divisible by 400.

> For this reason, the following years are not leap years:

> 1700, 1800, 1900, 2100, 2200, 2300, 2500, 2600

I had no idea!

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

#152
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 :)

A unit test shouldn’t even be depending on the current date in the first place

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

#153
Yes, an amusing one: the Android app for the Berlin public transport, on the 29th, listed the results with the date of the previous day (28th).

The funny thing is that the list is prefaced by a banner saying that this is a known bug, and the results actually refer to the 29th.

Interesting way to workaround a bug :)

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

#154
post #15

> A number of New Zealand petrol pumps stopped working on Thursday due to a "leap year glitch" in payment software, fuel stations and the payment service provider said. https://www.reuters.com/world/asia-pacific/leap-year-glitch-...

I'm sure it's more complicated than "we didn't think about leap years", but it certainly sounds pretty amateurish. Old programmer rant: In my day, we fixed the Y2K bug - we went to the future and back several times a day!

In your day people weren't doing everything with string ops in JavaScript.

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

#156
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…

How do leap day birthdays get handled in general? How is the right age iterated every year?

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

#158
post #95

Earlier quoted context omitted.

Moving bank/festive holidays, first Monday of the year(, first work day of the year not Monday if that's NYD and bank holiday), lunar occasions. 'subtract a year' is imprecise and has many meanings, if what you want is 'same day, same month, previous year' then say that and do that, that's conceptually `date.year -= 1` not `date -= 1 year`, and will have this bug.

You could subtract 365.25 days, but then you're left with a new problem: just because you can amortize a leap day over four years doesn't mean that you get an extra 6 hours each year.

And as I just learnt elsewhere in this thread, it would actually be three four-hundredths less than that anyway, i.e. 365.2425, since only one in four centenaries is a leap year.

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

#160
post #18
post #4

One cleanup script broke because Python doesn’t have a clean way to subtract a year, and if you do now.replace(year=now.year-1), you get a ValueError when now is 2/29. It’s easy enough to address. There are various StackOverflow posts on such things. Here is one: https://stackoverflow.com/questions/54394327/using-datetime-...

What is your definition of "subtracting a year"? Seems like that's a relatively ambiguous operation without more specification.

Plenty of thought has gone into this. Look at what database date functions do when you ask it to subtract 1 year. I will agree that there is not one answer.
Post reply on HN