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

Weeknumber wrong for 2018-12-31 #619

Closed
BT-sschmid opened this issue Jan 3, 2019 · 3 comments · Fixed by #621
Closed

Weeknumber wrong for 2018-12-31 #619

BT-sschmid opened this issue Jan 3, 2019 · 3 comments · Fixed by #621

Comments

@BT-sschmid
Copy link
Contributor

As mentioned in the docs babel.dates.format_date uses the ISO-Calendar when passing "YYYY" as format string.

Evaluating gives

babel.dates.format_date(datetime.datetime(2018,12,31
                                         ), format="w YYYY", locale='en_US')
>> u'53 2018'

The correct result should be 1 2019 by iso definitions.

Thanks for your reply

@akx
Copy link
Member

akx commented Jan 3, 2019

It's entirely possible the code is broken (and it does seem to be, unfortunately).

We would gladly accept a PR fixing this, if you're up for it.

The relevant code is

def get_week_number(self, day_of_period, day_of_week=None):

and it was originally implemented 12 years ago (😅) in 3b3df4b .

BT-sschmid added a commit to BT-sschmid/babel that referenced this issue Jan 7, 2019
The weeknumber was calculated to 53, but by definition the value
must compute to 1.

the fix will compute the weeknumber by using date.isocalendar if
locale.first_week_day == 0.

Also the computation of the year format 'YYYY' is replaced by isocalendar.

Tests added.
BT-sschmid added a commit to BT-sschmid/babel that referenced this issue Jan 7, 2019
The weeknumber was calculated to 53, but by definition the value
must compute to 1.

the fix will compute the weeknumber by using date.isocalendar if
locale.first_week_day == 0.

Also the computation of the year format 'YYYY' is replaced by isocalendar.

Tests added.
@alexander-heyber-manatec

Are there any news about this bug? Since Babel is used in Odoo, the weeknumber bug is present there and should be fixed soon.

@akx akx closed this as completed in #621 Mar 1, 2019
akx pushed a commit that referenced this issue Mar 1, 2019
The weeknumber was calculated to 53, but by definition the value must compute to 1.

the fix will compute the weeknumber by using date.isocalendar if locale.first_week_day == 0.

Also the computation of the year format 'YYYY' is replaced by isocalendar.
@Julien00859
Copy link

@alexander-heyber-manatec

Are there any news about this bug? Since Babel is used in Odoo, the weeknumber bug is present there and should be fixed soon.

Odoo uses a previous version of babel (namely the 2.3.4) we do not update dependencies on stable version. Hopefully this fix will be part of a coming babel release and be part of the next Odoo stable version (namely v13).

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

Successfully merging a pull request may close this issue.

4 participants