Skip to content

Commit 988923a

Browse files
committed
fix ISO week calculation
1 parent 0d90757 commit 988923a

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

src/rtbnext/resource/collection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ def year( self, year: int ) -> Self:
166166
def month( self, year: int, month: int ) -> Self:
167167
"""Filters resources by month."""
168168

169-
prefix = f"{ year }-{ month:02d }-"
169+
prefix = f"{ year }-{month:02d}-"
170170

171171
return self._clone( [
172172
item for item in self._items

src/rtbnext/resource/series.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,11 @@ def _period( self, date: str, period: AggregatePeriod ) -> str:
8282
return f"{ year }-Q{ ( month - 1 ) // 3 + 1 }"
8383

8484
if period == "month":
85-
return f"{ year }-{ month:02d }"
85+
return f"{ year }-{month:02d}"
8686

8787
if period == "week":
88-
current, first = date_type( year, month, day ), date_type( year, 1, 1 )
89-
return f"{ year }-W{ ( ( current - first ).days // 7 + 1 ):02d }"
88+
iso_year, iso_week, _ = date_type( year, month, day ).isocalendar()
89+
return f"{ iso_year }-W{iso_week:02d}"
9090

9191
raise ValueError( f"Invalid aggregate period: { period }" )
9292

0 commit comments

Comments
 (0)