Skip to content
Snippets Groups Projects

Resolve "Problems with dates which are in the new year, but in the last calendar week of the old year"

All threads resolved!
@@ -64,7 +64,13 @@ class CalendarWeek:
@@ -64,7 +64,13 @@ class CalendarWeek:
""" Get the calendar week by a date object (the week this date is in). """
""" Get the calendar week by a date object (the week this date is in). """
week = int(when.strftime("%V"))
week = int(when.strftime("%V"))
year = when.year + 1 if when.month == 12 and week == 1 else when.year
year = when.year
 
 
if when.month == 12 and week == 1:
 
year += 1
 
 
if (week == 52 or week == 53) and when.month == 1:
 
year -= 1
return cls(year=year, week=week)
return cls(year=year, week=week)
Loading