Skip to content
Snippets Groups Projects

Fix CalendarWeek.from_date in this case: week == 1 and month == 12

Merged Jonathan Weth requested to merge fix-week into master
1 unresolved thread
1 file
+ 4
1
Compare changes
  • Side-by-side
  • Inline
@@ -20,7 +20,10 @@ class CalendarWeek:
def from_date(cls, when: date):
""" Get the calendar week by a date object (the week this date is in). """
return cls(year=when.year, week=int(when.strftime("%V")))
week = int(when.strftime("%V"))
year = when.year + 1 if when.month == 12 and week == 1 else when.year
return cls(year=year, week=week)
@classmethod
def current_week(cls) -> int:
Loading