From a56407cda86bf214ecea9a6a1d46716389abd5ea Mon Sep 17 00:00:00 2001
From: Jonathan Weth <git@jonathanweth.de>
Date: Sun, 3 Jan 2021 12:47:52 +0100
Subject: [PATCH] Fix year detection at year turns

---
 calendarweek/calendarweek.py | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/calendarweek/calendarweek.py b/calendarweek/calendarweek.py
index 264b0c4..6065081 100644
--- a/calendarweek/calendarweek.py
+++ b/calendarweek/calendarweek.py
@@ -64,7 +64,12 @@ class CalendarWeek:
         """ Get the calendar week by a date object (the week this date is in). """
 
         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
+        elif when.month == 1 and (week == 52 or week == 53):
+            year -= 1
 
         return cls(year=year, week=week)
 
-- 
GitLab