Skip to content

Commit

Permalink
fix: weekly not working correctly at start of year
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrekfilip committed Mar 15, 2022
1 parent 7516e43 commit 549120d
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion rotate_backups/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -986,7 +986,12 @@ def timestamp(self):
@property
def week(self):
"""The ISO week number of :attr:`timestamp` (a number)."""
return self.timestamp.isocalendar()[1]
# for some days close to January 1, isocalendar()[1] may return the week number as 52 or 53
# eg: date(2022, 1, 1).isocalendar() returns (2021, 52, 6)
if self.year == self.timestamp.isocalendar()[0] + 1:
return 0
else:
return self.timestamp.isocalendar()[1]

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

0 comments on commit 549120d

Please sign in to comment.