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

Changed get_week_number() to fix a problem with the locale en_AU #1146

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions babel/dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -1656,10 +1656,10 @@ def get_week_number(self, day_of_period: int, day_of_week: int | None = None) ->
# If the weeknumber exceeds the maximum number of weeks for the given year
# we must count from zero.For example the above calculation gives week 53
# for 2018-12-31. By iso-calender definition 2018 has a max of 52
# weeks, thus the weeknumber must be 53-52=1.
# weeks, thus the weeknumber must be 53-1=52.
max_weeks = datetime.date(year=self.value.year, day=28, month=12).isocalendar()[1]
if week_number > max_weeks:
week_number -= max_weeks
week_number -= 1

return week_number

Expand Down
8 changes: 8 additions & 0 deletions tests/test_dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -795,3 +795,11 @@ def test_issue_892():
def test_issue_1089():
assert dates.format_datetime(datetime.now(), locale="ja_JP@mod")
assert dates.format_datetime(datetime.now(), locale=Locale.parse("ja_JP@mod"))


def test_issue_1133():
format = dates.DateTimeFormat(date(2006, 1, 8), Locale.parse('de_DE'))
assert format.get_week_number(6) == 1

format = dates.DateTimeFormat(date(2006, 1, 8), Locale.parse('en_US'))
assert format.get_week_number(6) == 2