Live data from Hacker News

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

news.ycombinator.com

431–440 of 498 posts

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

#432

One thing I have learned from HN is that datetime issues are hard, prolific, programming language agnostic, and not to trust myself to get the logic right. (The same applies to floats.)

Datetime and phonenumbers are two subjects that are notorious for how complex they are despite seemingly simple everyday concepts

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

#433
post #376
post #330

Stupid question. How do these bugs happen? 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…

> 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. 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: birthday: datetime.date birthday…

The Java library actually supports this case.

It may not have the convenient "years" method directly, but you can add an arbitrary unit of time quite easily

Example with duration:

    Duration.of(1, ChronoUnit.YEARS)
Example with datetime:

    today.plus(2, ChronoUnit.YEARS)
It even supports decades, centuries, eras and half days :-)

For those curious about how it handles leap years:

    var leapDay = LocalDate.of(2024, 2, 29)
    leapDay.plus(1, ChronoUnit.YEARS);
   
    // ==> 2025-02-28

    var lastYear = LocalDate.of(2023, 3, 1);
    lastYear.plus(1, ChronoUnit.YEARS);

    // ==> 2024-03-01

    var lastFeb = LocalDate.of(2023, 2, 28);
    lastFeb.plus(1, ChronoUnit.YEARS);

    // ==> 2024-02-28

    var firstFeb = LocalDate.of(2024, 2, 1);
    leapDay.with(TemporalAdjusters.lastDayOfMonth());

    // ==> 2024-02-29

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

#435
post #346
post #103

We have a product that uses ChatGPT via the API, using the 3.5 turbo version. Our query involves some dates. Instead of giving back text like it usually does, today it has been giving errors because it does not think 2024-02-29 is a valid date. This is easy to reproduce with the web interface, at least sometimes [0]. It start out by saying it's not a valid date and then as it's explaining why it isn't it realizes its…

Saw the same via the API with gpt-4-0125-preview. IOW, even gpt-4 thinks 2024 is not a leap year.

That's weird, I don't get that with gpt-4

https://chat.openai.com/share/336b1c4b-53b7-4d56-ac68-e3c868...

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

#436
post #394

I know I'm late to the party, but I have a Python script that creates a security.txt for one of my own project, and it sets the "Expires" date to one year in the future. Old code: expires = datetime.datetime.now(tz) expires = expires.replace(year=expires.year + 1) It broke yesterday, throws an exception ("ValueError: day is out of range for month"). It's kinda obvious that it does. Fixed version code: expires = datet…

In .NET there is an AddYears function that deals with all of this, and even gives you Feb 29 if the date is valid, otherwise Feb 28: https://learn.microsoft.com/en-us/dotnet/api/system.datetime...

There's the same in python, but if you wanna write shitty code you can always get around it

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

#437

Earlier quoted context omitted.

365.2425

365.2421 is more correct. Nasa explains: 365 +0.25 - 0.01 + 0.0025 - 0.00025 = 365.24225 https://pumas.nasa.gov/examples/how-many-days-are-year

>Omitting a leap year every 4000 years

Wait, is this right? omitting every 100 and adding every 400 should be enough.

EDIT: the 4000-year rule is just a proposal for now. So 365.2425 is correct.

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

#438

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?

At midnight in-between 28th February and 1st March.

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

#439
post #429
post #289

Earlier quoted context omitted.

It doesn’t even matter how many tokens there is, because LLMs are completely ignorant about how their input is structured. They don’t see letters or syllables cause they have no “eyes”. The closest analogy with a human is that vocal-ish concepts just emerge in their mind without any visual representation. They can only “recall” how many “e”s are there, but cannot look and count.

>They can only “recall” how many “e”s are there, but cannot look and count. Like a blind person?

My initial analogy was already weak, so I guess there's no point in extending it. They key fact here is that tokens are inputs to what essentially is an overgrown matrix multiplication routine. Everything "AI" happens few levels of scientific abstractions higher, and is semantically disconnected from the "moving parts".

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

#440

Earlier quoted context omitted.

In .NET there is an AddYears function that deals with all of this, and even gives you Feb 29 if the date is valid, otherwise Feb 28: https://learn.microsoft.com/en-us/dotnet/api/system.datetime...

There's the same in python, but if you wanna write shitty code you can always get around it

Yup relativedelta https://dateutil.readthedocs.io/en/stable/relativedelta.html
Post reply on HN