-
Notifications
You must be signed in to change notification settings - Fork 457
format_date: Dates in the last 2 days of 2024 get misformatted as dates in 2025 when using a custom format #1177
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Also same problem with last 3 days in 2025 if it can help somehow (but not with any last days in 2023 or 2022) I've closed my issue about that by my mistake, so don't rely on it. Thanks for checking and reopenning! |
@akx DeepSeek has answer The error in the python/babel library is related to the incorrect use of the YYYY format in the format string "YYYY-MM-dd (cccc)". In the Babel library (and other date-handling libraries like Moment.js), YYYY represents the week year, not the calendar year. The week year can differ from the calendar year, especially in the last days of December or the first days of January, if the week transitions into the next year.
How to fix it? Use yyyy instead of YYYY in the format string to get the correct calendar year: Examples:
Why does it work with format="long" and format="short"? When using built-in formats like "long" or "short", the Babel library automatically selects the correct year format (yyyy), so the issue does not occur. The error is caused by using YYYY instead of yyyy. To correctly display the calendar year, always use yyyy in custom formats. |
Thanks for the investigation! So I take it there's nothing to fix on babel's side? FYI, the date patterns are documented here: https://babel.pocoo.org/en/latest/dates.html#pattern-syntax |
So yeah, this was clearly user error though: |
Related to #1171.
Note
long
/short
etc. isn't affected, just the custom formats.The text was updated successfully, but these errors were encountered: