All street lamps in Paris turned off at midnight :) https://www.leparisien.fr/paris-75/paris-pourquoi-les-rues-d...
Ask HN: Did you encounter any leap year bugs today?
431–440 of 498 posts
Re: Ask HN: Did you encounter any leap year bugs today?
#432One 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.)
Re: Ask HN: Did you encounter any leap year bugs today?
#433Stupid 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…
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-29Re: Ask HN: Did you encounter any leap year bugs today?
#434queryset.filter(user__last_login__gte=today.replace(year=today.year - 1)).count()
Meanwhile, in the betting world, someone actually placed a bet on the day of the week for February 29, 2020.
Re: Ask HN: Did you encounter any leap year bugs today?
#435We 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.
https://chat.openai.com/share/336b1c4b-53b7-4d56-ac68-e3c868...
Re: Ask HN: Did you encounter any leap year bugs today?
#436I 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...
Re: Ask HN: Did you encounter any leap year bugs today?
#437Earlier 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
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?
#438The 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?
#439Earlier 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?
Re: Ask HN: Did you encounter any leap year bugs today?
#440Earlier 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