Skip to content

Commit 625298b

Browse files
committed
get_date_offset_breaks_and_labels
1 parent 7012293 commit 625298b

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

openskistats/nesh/timelines.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,24 @@
2828
SEASON_ORIGIN_DAY = 1
2929

3030

31+
def get_date_offset_breaks_and_labels() -> tuple[list[int], list[str]]:
32+
"""
33+
Get offset breaks used for axis major plotting breaks,
34+
which are the number of days into the ski season in the Northern Hemisphere.
35+
Also return offset labels, which are the month and day of the first day of each month.
36+
Assumes a non-leap year.
37+
"""
38+
offset_breaks = [0]
39+
offset_labels = []
40+
for month_offset in range(12):
41+
month = (SEASON_ORIGIN_MONTH - 1 + month_offset) % 12 + 1
42+
_, days_in_month = calendar.monthrange(2025, month) # 2025 is not a leap year
43+
offset_breaks.append(offset_breaks[-1] + days_in_month)
44+
offset_labels.append(calendar.month_abbr[month] + " 1")
45+
offset_breaks.pop()
46+
return offset_breaks, offset_labels
47+
48+
3149
@dataclass(frozen=True)
3250
class NewEnglandSkiHistoryTimelineScraper:
3351
season: int

0 commit comments

Comments
 (0)