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

fixes #619 wrong weeknumber for 31.12.2018 #621

Merged
merged 2 commits into from
Mar 1, 2019

Conversation

BT-sschmid
Copy link
Contributor

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.

Fixes #619

@codecov-io
Copy link

codecov-io commented Jan 7, 2019

Codecov Report

Merging #621 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #621   +/-   ##
=======================================
  Coverage   90.31%   90.31%           
=======================================
  Files          24       24           
  Lines        4129     4129           
=======================================
  Hits         3729     3729           
  Misses        400      400
Impacted Files Coverage Δ
babel/dates.py 91.55% <100%> (+0.02%) ⬆️
babel/_compat.py 98.03% <0%> (-0.08%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b7dda2a...085a397. Read the comment docs.

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.
babel/dates.py Show resolved Hide resolved
@akx akx merged commit ea5bc49 into python-babel:master Mar 1, 2019
d-fence added a commit to odoo-dev/odoo that referenced this pull request Jun 5, 2024
Since Babel issue 621 [0] searching the week number of a date alongside
with the year can lead to a wrong year in the result. e.g.: `2023-01-01`
gives `W1 2022`

Before the present commit, the tests were surprisingly expecting the
wrong result.

An attempt was made [1] to fix the upstream issue but was never merged.

In the meanwhile, Debian reverted the Babel issue 621 [2] in their
package.

It means that our test would fail with the patched Debian package like
in Ubuntu Noble or Debian Bookworm. On the other hand, if we fix the
test to expect the correct value, it would fail on unpatched version of
the Babel lib.

So, this commit mitigate the issue by guessing the expected value even
if the result is wrong.

[0]: python-babel/babel#621
[1]: python-babel/babel#887
[2]: https://sources.debian.org/patches/python-babel/2.10.3-1/
robodoo pushed a commit to odoo/odoo that referenced this pull request Jun 10, 2024
Since Babel issue 621 [0] searching the week number of a date alongside
with the year can lead to a wrong year in the result. e.g.: `2023-01-01`
gives `W1 2022`

Before the present commit, the tests were surprisingly expecting the
wrong result.

An attempt was made [1] to fix the upstream issue but was never merged.

In the meanwhile, Debian reverted the Babel issue 621 [2] in their
package.

It means that our test would fail with the patched Debian package like
in Ubuntu Noble or Debian Bookworm. On the other hand, if we fix the
test to expect the correct value, it would fail on unpatched version of
the Babel lib.

So, this commit mitigate the issue by guessing the expected value even
if the result is wrong.

[0]: python-babel/babel#621
[1]: python-babel/babel#887
[2]: https://sources.debian.org/patches/python-babel/2.10.3-1/

closes #168132

Signed-off-by: Xavier Dollé (xdo) <xdo@odoo.com>
fw-bot pushed a commit to odoo-dev/odoo that referenced this pull request Jun 10, 2024
Since Babel issue 621 [0] searching the week number of a date alongside
with the year can lead to a wrong year in the result. e.g.: `2023-01-01`
gives `W1 2022`

Before the present commit, the tests were surprisingly expecting the
wrong result.

An attempt was made [1] to fix the upstream issue but was never merged.

In the meanwhile, Debian reverted the Babel issue 621 [2] in their
package.

It means that our test would fail with the patched Debian package like
in Ubuntu Noble or Debian Bookworm. On the other hand, if we fix the
test to expect the correct value, it would fail on unpatched version of
the Babel lib.

So, this commit mitigate the issue by guessing the expected value even
if the result is wrong.

[0]: python-babel/babel#621
[1]: python-babel/babel#887
[2]: https://sources.debian.org/patches/python-babel/2.10.3-1/

X-original-commit: 426fc56
fw-bot pushed a commit to odoo-dev/odoo that referenced this pull request Jun 10, 2024
Since Babel issue 621 [0] searching the week number of a date alongside
with the year can lead to a wrong year in the result. e.g.: `2023-01-01`
gives `W1 2022`

Before the present commit, the tests were surprisingly expecting the
wrong result.

An attempt was made [1] to fix the upstream issue but was never merged.

In the meanwhile, Debian reverted the Babel issue 621 [2] in their
package.

It means that our test would fail with the patched Debian package like
in Ubuntu Noble or Debian Bookworm. On the other hand, if we fix the
test to expect the correct value, it would fail on unpatched version of
the Babel lib.

So, this commit mitigate the issue by guessing the expected value even
if the result is wrong.

[0]: python-babel/babel#621
[1]: python-babel/babel#887
[2]: https://sources.debian.org/patches/python-babel/2.10.3-1/

X-original-commit: 426fc56
fw-bot pushed a commit to odoo-dev/odoo that referenced this pull request Jun 10, 2024
Since Babel issue 621 [0] searching the week number of a date alongside
with the year can lead to a wrong year in the result. e.g.: `2023-01-01`
gives `W1 2022`

Before the present commit, the tests were surprisingly expecting the
wrong result.

An attempt was made [1] to fix the upstream issue but was never merged.

In the meanwhile, Debian reverted the Babel issue 621 [2] in their
package.

It means that our test would fail with the patched Debian package like
in Ubuntu Noble or Debian Bookworm. On the other hand, if we fix the
test to expect the correct value, it would fail on unpatched version of
the Babel lib.

So, this commit mitigate the issue by guessing the expected value even
if the result is wrong.

[0]: python-babel/babel#621
[1]: python-babel/babel#887
[2]: https://sources.debian.org/patches/python-babel/2.10.3-1/

X-original-commit: 426fc56
fw-bot pushed a commit to odoo-dev/odoo that referenced this pull request Jun 10, 2024
Since Babel issue 621 [0] searching the week number of a date alongside
with the year can lead to a wrong year in the result. e.g.: `2023-01-01`
gives `W1 2022`

Before the present commit, the tests were surprisingly expecting the
wrong result.

An attempt was made [1] to fix the upstream issue but was never merged.

In the meanwhile, Debian reverted the Babel issue 621 [2] in their
package.

It means that our test would fail with the patched Debian package like
in Ubuntu Noble or Debian Bookworm. On the other hand, if we fix the
test to expect the correct value, it would fail on unpatched version of
the Babel lib.

So, this commit mitigate the issue by guessing the expected value even
if the result is wrong.

[0]: python-babel/babel#621
[1]: python-babel/babel#887
[2]: https://sources.debian.org/patches/python-babel/2.10.3-1/

X-original-commit: 426fc56
robodoo pushed a commit to odoo/odoo that referenced this pull request Jun 11, 2024
Since Babel issue 621 [0] searching the week number of a date alongside
with the year can lead to a wrong year in the result. e.g.: `2023-01-01`
gives `W1 2022`

Before the present commit, the tests were surprisingly expecting the
wrong result.

An attempt was made [1] to fix the upstream issue but was never merged.

In the meanwhile, Debian reverted the Babel issue 621 [2] in their
package.

It means that our test would fail with the patched Debian package like
in Ubuntu Noble or Debian Bookworm. On the other hand, if we fix the
test to expect the correct value, it would fail on unpatched version of
the Babel lib.

So, this commit mitigate the issue by guessing the expected value even
if the result is wrong.

[0]: python-babel/babel#621
[1]: python-babel/babel#887
[2]: https://sources.debian.org/patches/python-babel/2.10.3-1/

closes #168786

X-original-commit: 426fc56
Signed-off-by: Xavier Dollé (xdo) <xdo@odoo.com>
Signed-off-by: Christophe Monniez (moc) <moc@odoo.com>
robodoo pushed a commit to odoo/odoo that referenced this pull request Jun 11, 2024
Since Babel issue 621 [0] searching the week number of a date alongside
with the year can lead to a wrong year in the result. e.g.: `2023-01-01`
gives `W1 2022`

Before the present commit, the tests were surprisingly expecting the
wrong result.

An attempt was made [1] to fix the upstream issue but was never merged.

In the meanwhile, Debian reverted the Babel issue 621 [2] in their
package.

It means that our test would fail with the patched Debian package like
in Ubuntu Noble or Debian Bookworm. On the other hand, if we fix the
test to expect the correct value, it would fail on unpatched version of
the Babel lib.

So, this commit mitigate the issue by guessing the expected value even
if the result is wrong.

[0]: python-babel/babel#621
[1]: python-babel/babel#887
[2]: https://sources.debian.org/patches/python-babel/2.10.3-1/

closes #168777

X-original-commit: 426fc56
Signed-off-by: Xavier Dollé (xdo) <xdo@odoo.com>
Signed-off-by: Christophe Monniez (moc) <moc@odoo.com>
robodoo pushed a commit to odoo/odoo that referenced this pull request Jun 11, 2024
Since Babel issue 621 [0] searching the week number of a date alongside
with the year can lead to a wrong year in the result. e.g.: `2023-01-01`
gives `W1 2022`

Before the present commit, the tests were surprisingly expecting the
wrong result.

An attempt was made [1] to fix the upstream issue but was never merged.

In the meanwhile, Debian reverted the Babel issue 621 [2] in their
package.

It means that our test would fail with the patched Debian package like
in Ubuntu Noble or Debian Bookworm. On the other hand, if we fix the
test to expect the correct value, it would fail on unpatched version of
the Babel lib.

So, this commit mitigate the issue by guessing the expected value even
if the result is wrong.

[0]: python-babel/babel#621
[1]: python-babel/babel#887
[2]: https://sources.debian.org/patches/python-babel/2.10.3-1/

closes #168765

X-original-commit: 426fc56
Signed-off-by: Xavier Dollé (xdo) <xdo@odoo.com>
Signed-off-by: Christophe Monniez (moc) <moc@odoo.com>
robodoo pushed a commit to odoo/odoo that referenced this pull request Jun 11, 2024
Since Babel issue 621 [0] searching the week number of a date alongside
with the year can lead to a wrong year in the result. e.g.: `2023-01-01`
gives `W1 2022`

Before the present commit, the tests were surprisingly expecting the
wrong result.

An attempt was made [1] to fix the upstream issue but was never merged.

In the meanwhile, Debian reverted the Babel issue 621 [2] in their
package.

It means that our test would fail with the patched Debian package like
in Ubuntu Noble or Debian Bookworm. On the other hand, if we fix the
test to expect the correct value, it would fail on unpatched version of
the Babel lib.

So, this commit mitigate the issue by guessing the expected value even
if the result is wrong.

[0]: python-babel/babel#621
[1]: python-babel/babel#887
[2]: https://sources.debian.org/patches/python-babel/2.10.3-1/

closes #168747

X-original-commit: 426fc56
Signed-off-by: Xavier Dollé (xdo) <xdo@odoo.com>
Signed-off-by: Christophe Monniez (moc) <moc@odoo.com>
ryv-odoo pushed a commit to odoo-dev/odoo that referenced this pull request Jun 11, 2024
Since Babel issue 621 [0] searching the week number of a date alongside
with the year can lead to a wrong year in the result. e.g.: `2023-01-01`
gives `W1 2022`

Before the present commit, the tests were surprisingly expecting the
wrong result.

An attempt was made [1] to fix the upstream issue but was never merged.

In the meanwhile, Debian reverted the Babel issue 621 [2] in their
package.

It means that our test would fail with the patched Debian package like
in Ubuntu Noble or Debian Bookworm. On the other hand, if we fix the
test to expect the correct value, it would fail on unpatched version of
the Babel lib.

So, this commit mitigate the issue by guessing the expected value even
if the result is wrong.

[0]: python-babel/babel#621
[1]: python-babel/babel#887
[2]: https://sources.debian.org/patches/python-babel/2.10.3-1/

closes odoo#168132

Signed-off-by: Xavier Dollé (xdo) <xdo@odoo.com>
xmo-odoo added a commit to odoo-dev/odoo that referenced this pull request Jun 27, 2024
Babel has a very long standing bug on computing ISO weeks /
year-week.

python-babel/babel#621 fixed some cases but broke others. Debian
decided to revert it[^1] rather than actually fix things up and Ubuntu
shipped that patch in Noble, which is awesome (not): test cases
embedding either behavior flip around depending whether they run or
noble or not.

python-babel/babel#887 was opened to fix the issue but left to rot
then closed when I mistakenly-ish deleted my personal fork of babel.

While technically we could monkeypatch babel and replace functions
wholesale (both versions so it works everywhere), just give up and
instead compute the weeknumber ourselves in the context of
`read_group([X:week])`:

- For ISO locales, delegate to the stdlib which does that fine.
- For non-ISO locales, assume that the week containing the first day
  of the year is the first week, and make the executive decision that
  all days in that calendar week are part of W01. The alternative
  would be to implement a split / overlapping week system where the
  same week is both W53 $YEAR and W01 $YEAR+1, and I really have no
  desire to deal with that from a UI/UX perspective.

Fix tests embedding incorrect week assignments:

- For `test_group_by_week`, redo the entire set (somewhat more
  declaratively / data driven, though not quite table-driven) to
  ensure the assignments are correct, and assert that the locales have
  the properties we assume with respect to 1dow.
- For `test_read_progress_bar`, the entire thing was a fever dream of
  wonky pseudo-split week where 2019 had no week 1.

[^1]: https://sources.debian.org/patches/python-babel/2.10.3-1/
robodoo pushed a commit to odoo/odoo that referenced this pull request Jun 27, 2024
Babel has a very long standing bug on computing ISO weeks /
year-week.

python-babel/babel#621 fixed some cases but broke others. Debian
decided to revert it[^1] rather than actually fix things up and Ubuntu
shipped that patch in Noble, which is awesome (not): test cases
embedding either behavior flip around depending whether they run or
noble or not.

python-babel/babel#887 was opened to fix the issue but left to rot
then closed when I mistakenly-ish deleted my personal fork of babel.

While technically we could monkeypatch babel and replace functions
wholesale (both versions so it works everywhere), just give up and
instead compute the weeknumber ourselves in the context of
`read_group([X:week])`:

- For ISO locales, delegate to the stdlib which does that fine.
- For non-ISO locales, assume that the week containing the first day
  of the year is the first week, and make the executive decision that
  all days in that calendar week are part of W01. The alternative
  would be to implement a split / overlapping week system where the
  same week is both W53 $YEAR and W01 $YEAR+1, and I really have no
  desire to deal with that from a UI/UX perspective.

Fix tests embedding incorrect week assignments:

- For `test_group_by_week`, redo the entire set (somewhat more
  declaratively / data driven, though not quite table-driven) to
  ensure the assignments are correct, and assert that the locales have
  the properties we assume with respect to 1dow.
- For `test_read_progress_bar`, the entire thing was a fever dream of
  wonky pseudo-split week where 2019 had no week 1.

[^1]: https://sources.debian.org/patches/python-babel/2.10.3-1/

closes #170995

Signed-off-by: Xavier Morel (xmo) <xmo@odoo.com>
fw-bot pushed a commit to odoo-dev/odoo that referenced this pull request Jun 27, 2024
Babel has a very long standing bug on computing ISO weeks /
year-week.

python-babel/babel#621 fixed some cases but broke others. Debian
decided to revert it[^1] rather than actually fix things up and Ubuntu
shipped that patch in Noble, which is awesome (not): test cases
embedding either behavior flip around depending whether they run or
noble or not.

python-babel/babel#887 was opened to fix the issue but left to rot
then closed when I mistakenly-ish deleted my personal fork of babel.

While technically we could monkeypatch babel and replace functions
wholesale (both versions so it works everywhere), just give up and
instead compute the weeknumber ourselves in the context of
`read_group([X:week])`:

- For ISO locales, delegate to the stdlib which does that fine.
- For non-ISO locales, assume that the week containing the first day
  of the year is the first week, and make the executive decision that
  all days in that calendar week are part of W01. The alternative
  would be to implement a split / overlapping week system where the
  same week is both W53 $YEAR and W01 $YEAR+1, and I really have no
  desire to deal with that from a UI/UX perspective.

Fix tests embedding incorrect week assignments:

- For `test_group_by_week`, redo the entire set (somewhat more
  declaratively / data driven, though not quite table-driven) to
  ensure the assignments are correct, and assert that the locales have
  the properties we assume with respect to 1dow.
- For `test_read_progress_bar`, the entire thing was a fever dream of
  wonky pseudo-split week where 2019 had no week 1.

[^1]: https://sources.debian.org/patches/python-babel/2.10.3-1/

X-original-commit: 75c6331
robodoo pushed a commit to odoo/odoo that referenced this pull request Jun 28, 2024
Babel has a very long standing bug on computing ISO weeks /
year-week.

python-babel/babel#621 fixed some cases but broke others. Debian
decided to revert it[^1] rather than actually fix things up and Ubuntu
shipped that patch in Noble, which is awesome (not): test cases
embedding either behavior flip around depending whether they run or
noble or not.

python-babel/babel#887 was opened to fix the issue but left to rot
then closed when I mistakenly-ish deleted my personal fork of babel.

While technically we could monkeypatch babel and replace functions
wholesale (both versions so it works everywhere), just give up and
instead compute the weeknumber ourselves in the context of
`read_group([X:week])`:

- For ISO locales, delegate to the stdlib which does that fine.
- For non-ISO locales, assume that the week containing the first day
  of the year is the first week, and make the executive decision that
  all days in that calendar week are part of W01. The alternative
  would be to implement a split / overlapping week system where the
  same week is both W53 $YEAR and W01 $YEAR+1, and I really have no
  desire to deal with that from a UI/UX perspective.

Fix tests embedding incorrect week assignments:

- For `test_group_by_week`, redo the entire set (somewhat more
  declaratively / data driven, though not quite table-driven) to
  ensure the assignments are correct, and assert that the locales have
  the properties we assume with respect to 1dow.
- For `test_read_progress_bar`, the entire thing was a fever dream of
  wonky pseudo-split week where 2019 had no week 1.

[^1]: https://sources.debian.org/patches/python-babel/2.10.3-1/

closes #171135

X-original-commit: 75c6331
Signed-off-by: Xavier Morel (xmo) <xmo@odoo.com>
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 this pull request may close these issues.

Weeknumber wrong for 2018-12-31
3 participants