Live data from Hacker News

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

news.ycombinator.com

231–240 of 498 posts

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

#231

Unless you're in your 70's, YouTube doesn't allow you to buy premium if you were born on a leap year, because their age calculation is broken, and it thinks you're under 18. Google One works fine. Support will suggest that you change the birthday on your Google account, which breaks account recovery processes that depend on you furnishing matching identity documentation. Mind-boggling. Because nobody at YouTube has a…

I wouldn't expect google to mess this up but then again someone probably calculated value produced vs project cost and tossed this one at the bottom of the pile 10 times already. 66/100k people (0.066%, close to the definition for a rare disease) would be born on 29th of feb on a uniform distribution, probably minus another 5% or so because february is in many places the least likely month to be born into. And out of those people how many actually put in their real birthday? Still odd to mess up a subtraction though.

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

#232
post #223

Earlier quoted context omitted.

Interesting... But that isn't exactly true! Centuries that are not divisible by 4 don't count!

I've yet to come across a form of 100 that isn't divisible by 4... since 25 usually still exists! But I do remember there being some weird niche rules about which years are or aren't leap years, so I'm guessing your comment is basically right just wrongly worded?

The rule is that leap years are the ones divisible by 4. Unless it’s also divisible by 100. Unless unless it’s divisible by 400.

So 2000 was leap, but 2100, 2200, and 2300 won’t be, but 2400 will be.

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

#233

Earlier quoted context omitted.

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

365 days ago was March 1, 2023

In 365 days, it will be February 28, 2025

Which is more important, the past or the future?

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

#234
post #232
post #223

Earlier quoted context omitted.

I've yet to come across a form of 100 that isn't divisible by 4... since 25 usually still exists! But I do remember there being some weird niche rules about which years are or aren't leap years, so I'm guessing your comment is basically right just wrongly worded?

The rule is that leap years are the ones divisible by 4. Unless it’s also divisible by 100. Unless unless it’s divisible by 400. So 2000 was leap, but 2100, 2200, and 2300 won’t be, but 2400 will be.

Ahh, so it's centuries that aren't divisible by 400 rather than that aren't divisible by 4, that makes more sense!

Thanks for answering

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

#235
post #187

Earlier quoted context omitted.

> now.replace(year=now.year-1) Yeah but this is bad code. Python certainly does have a "clean" way to subtract a year, you subtract a datetime.timedelta object.

timedelta doesn't take "years" as a parameter, for the reasons others have listed here. It's ambiguous what subtracting by a year means, and there's no real sensible default either.

relativedelta will do it:

  from dateutil.relativedelta import relativedelta
  one_year = relativedelta(years=1)

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

#236
We have a rails 6 app, and there's a test that essentially expects time_ago_in_words(1.year.from_now) to return "about 1 year" (as part of a user facing message). The test failed. I thought it's a flaky test but i was able to reproduce it locally. Turns out executing that code on a leap day returns "almost 1 year" instead. Can test it in rails console if you are interested:

  irb(main):001:0> include ActionView::Helpers::DateHelper
  => Object
  irb(main):002:0> distance_of_time_in_words(Date.new(2025, 2, 28), Date.new(2024, 2, 29))
  => "almost 1 year"
  irb(main):003:0> distance_of_time_in_words(Date.new(2025, 3, 1), Date.new(2024, 2, 29))
  => "about 1 year"
  irb(main):004:0> distance_of_time_in_words(Date.new(2025, 2, 28), Date.new(2024, 2, 28))
  => "about 1 year"

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

#237
post #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?

Sadly, I can say from experience the American draft does not count the number of birthdays celebrated to figure out if you're eligible to serve.

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

#238

Earlier quoted context omitted.

ChatGPT thinks today is March 1. Go ahead and ask it what today’s date is.

> No, 2024 is not a leap year. Leap years are years divisible by 4, except for years that are divisible by 100 unless they are also divisible by 400. Therefore, the next leap year will be 2024.

As the proud new owner of a leap day baby, I find this to be extra hilarious

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

#239

We have a rails 6 app, and there's a test that essentially expects time_ago_in_words(1.year.from_now) to return "about 1 year" (as part of a user facing message). The test failed. I thought it's a flaky test but i was able to reproduce it locally. Turns out executing that code on a leap day returns "almost 1 year" instead. Can test it in rails console if you are interested: irb(main):001:0> include ActionView::Helper…

> distance_of_time_in_words(Date.new(2025, 2, 28), Date.new(2024, 2, 28))

Curiously, this is also not quite a year, even though the days and months are the same.

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

#240
post #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?

Both Feb 28 and Mar 1 are commonly used to celebrate birthdays.

AFAIK there is no firm convention. Feb is more natural ("My birthday is in February"), Mar is more logical (the 60th days of the year).

Post reply on HN