Skip to content

Commit d675ed6

Browse files
committed
fix: month overflow in cg start/end
1 parent 5e51714 commit d675ed6

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

coc/utils.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -390,10 +390,14 @@ def get_clan_games_start(time: Optional[datetime] = None) -> datetime:
390390
if time is None:
391391
time = datetime.utcnow()
392392
month = time.month
393+
year = time.year
393394
this_months_cg_end = datetime(year=time.year, month=time.month, day=28, hour=8, minute=0, second=0)
394-
if time > this_months_cg_end:
395+
if time > this_months_cg_end and month < 12:
395396
month += 1
396-
return datetime(year=time.year, month=month, day=22, hour=8, minute=0, second=0)
397+
elif time > this_months_cg_end: # we're at the end of December
398+
month = 1
399+
year += 1
400+
return datetime(year=year, month=month, day=22, hour=8, minute=0, second=0)
397401

398402

399403
def get_clan_games_end(time: Optional[datetime] = None) -> datetime:
@@ -419,10 +423,14 @@ def get_clan_games_end(time: Optional[datetime] = None) -> datetime:
419423
if time is None:
420424
time = datetime.utcnow()
421425
month = time.month
426+
year = time.year
422427
this_months_cg_end = datetime(year=time.year, month=time.month, day=28, hour=8, minute=0, second=0)
423-
if time > this_months_cg_end:
428+
if time > this_months_cg_end and month < 12:
424429
month += 1
425-
return datetime(year=time.year, month=month, day=28, hour=8, minute=0, second=0)
430+
elif time > this_months_cg_end: # we're in December
431+
month = 1
432+
year += 1
433+
return datetime(year=year, month=month, day=28, hour=8, minute=0, second=0)
426434

427435

428436
def get_raid_weekend_start(time: Optional[datetime] = None) -> datetime:

0 commit comments

Comments
 (0)