Skip to content

Commit e59dd1c

Browse files
committed
fix: weekly not working correctly at start of year
1 parent 003569e commit e59dd1c

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

rotate_backups/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -986,7 +986,12 @@ def timestamp(self):
986986
@property
987987
def week(self):
988988
"""The ISO week number of :attr:`timestamp` (a number)."""
989-
return self.timestamp.isocalendar()[1]
989+
# for some days close to January 1, isocalendar()[1] may return the week number as 52 or 53
990+
# eg: date(2022, 1, 1).isocalendar() returns (2021, 52, 6)
991+
if self.year == self.timestamp.isocalendar()[0] + 1:
992+
return 0
993+
else:
994+
return self.timestamp.isocalendar()[1]
990995

991996
def __getattr__(self, name):
992997
"""Defer attribute access to :attr:`timestamp`."""

0 commit comments

Comments
 (0)