Skip to content
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

format_date function shows wrong year for last days of year #1171

Open
Esterbi opened this issue Jan 13, 2025 · 2 comments
Open

format_date function shows wrong year for last days of year #1171

Esterbi opened this issue Jan 13, 2025 · 2 comments

Comments

@Esterbi
Copy link

Esterbi commented Jan 13, 2025

Overview Description

I've noticed that format_date(..., ..., format='YYYY'):

  1. returns 2025 for december 30 2024 and december 31 2024, but 2024 for for december 29 2024
  2. returns 2026 for december 29 2025, december 30 2025 and december 31 2025, but 2025 for for december 28 2025
  3. returns actual year for any dates in december 2022 and december 2023.

Version Information

I'm using babel 2.9.0, but upgrade to 2.16.0 doesn't solve issue.

Additional Information

It's my first issue ever, so I'm sorry in advance for any mistakes in the formalization.

@akx
Copy link
Member

akx commented Jan 14, 2025

@Esterbi Thanks for the report. Could you add the actual code you're running (e.g. what are the ...s – are they e.g. local times in some timezone?), or in any case a reproducible example, to make this easier to triage?

@Esterbi
Copy link
Author

Esterbi commented Jan 14, 2025

Well, for example format_date(self.date, locale='ru', format=' EE YYYY'). But I've tried locale 'en', and got same result as well (that's why I've not mentioned that).

Another example (for django admin):

def open_tren_last(obj):
    if obj.open_tren.exists():
        last = obj.open_tren.latest('date')
        format = 'dd MMM YYYY'
        date_info = format_datetime(last.date, locale='ru', format=format,
                                    tzinfo=datetime.timezone(
                                        datetime.timedelta(
                                            hours=3))).capitalize()

I've tried also different tzinfo, but have got same result.
I'm using Django 3.2.25 in my project, so all dates come from models, like (for example above)
date = models.DateField(verbose_name='Дата тренировки', )

Maybe problem is in some outdated libs in my project, which babel is using? I mean, you don't have same result? I've included all libs from my venv, may be it could help. (Yeah, I know they are outdated, but it's first time I have problems with such common library as babel). Also it's strange for me that function returns so different results depends on year. May be it's my mistake somehow, but I still wonder why it is so. I've checked all my code, using different combinations of locale and tzinfo, but got same result. Problem is only with year, days and months are still fully valid with any locale or tzinfo.
req.txt

Here's part from Django settings

LANGUAGE_CODE = 'ru-ru'
TIME_ZONE = 'Europe/Moscow'
USE_I18N = True
USE_L10N = True
USE_TZ = True

Thx a lot for helping!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants