|
56 | 56 | # for each star to compute the rank score. |
57 | 57 | StarResult = collections.namedtuple("StarResult", "member_id completion_time") |
58 | 58 |
|
| 59 | +# In 2025, AOC was changed to be held from Dec 1 to 12, with 12 days rather than 25. |
| 60 | +# This implementation is done in such a way that any arbitary number of days can be supported. |
| 61 | +def days_in_year(year:int | None = None) -> int: |
| 62 | + """Return the number of days in the current Advent of Code year.""" |
| 63 | + if year is None: |
| 64 | + year = AdventOfCode.year |
| 65 | + return 25 if year < 2025 else 12 |
| 66 | + |
| 67 | +DAYS_THIS_YEAR = days_in_year() |
| 68 | + |
59 | 69 |
|
60 | 70 | class UnexpectedRedirect(aiohttp.ClientError): |
61 | 71 | """Raised when an unexpected redirect was detected.""" |
@@ -427,13 +437,15 @@ async def get_public_join_code(author: discord.Member) -> str | None: |
427 | 437 |
|
428 | 438 | def is_in_advent() -> bool: |
429 | 439 | """ |
430 | | - Check if we're currently on an Advent of Code day, excluding 25 December. |
| 440 | + Check if we're currently on an Advent of Code day, excluding the final day of AOC for that year. |
431 | 441 |
|
432 | 442 | This helper function is used to check whether or not a feature that prepares |
433 | 443 | something for the next Advent of Code challenge should run. As the puzzle |
434 | | - published on the 25th is the last puzzle, this check excludes that date. |
| 444 | + published on the final day is the last puzzle, this check excludes that date. |
435 | 445 | """ |
436 | | - return arrow.now(EST).day in range(1, 25) and arrow.now(EST).month == 12 |
| 446 | + # Advent of Code always begins on December 1st, and runs for one month |
| 447 | + now = arrow.now(EST) |
| 448 | + return now.month == 12 and now.day in range(1, DAYS_THIS_YEAR) |
437 | 449 |
|
438 | 450 |
|
439 | 451 | def time_left_to_est_midnight() -> tuple[datetime.datetime, datetime.timedelta]: |
@@ -471,7 +483,7 @@ async def countdown_status(bot: SirRobin) -> None: |
471 | 483 | # sleeping for the entire year, it will only wait in the currently |
472 | 484 | # configured year. This means that the task will only start hibernating once |
473 | 485 | # we start preparing the next event by changing environment variables. |
474 | | - last_challenge = arrow.get(datetime.datetime(AdventOfCode.year, 12, 25, tzinfo=datetime.UTC), EST) |
| 486 | + last_challenge = arrow.get(datetime.datetime(AdventOfCode.year, 12, DAYS_THIS_YEAR, tzinfo=datetime.UTC), EST) |
475 | 487 | end = last_challenge + datetime.timedelta(hours=1) |
476 | 488 |
|
477 | 489 | while arrow.now(EST) < end: |
@@ -516,9 +528,8 @@ async def new_puzzle_notification(bot: SirRobin) -> None: |
516 | 528 | log.error("Could not find the AoC role to announce the daily puzzle") |
517 | 529 | return |
518 | 530 |
|
519 | | - # The last event day is 25 December, so we only have to schedule |
520 | | - # a reminder if the current day is before 25 December. |
521 | | - end = arrow.get(datetime.datetime(AdventOfCode.year, 12, 25, tzinfo=datetime.UTC), EST) |
| 531 | + # Only schedule a reminder if the current day is before the final day December. |
| 532 | + end = arrow.get(datetime.datetime(AdventOfCode.year, 12, DAYS_THIS_YEAR, tzinfo=datetime.UTC), EST) |
522 | 533 | while arrow.now(EST) < end: |
523 | 534 | log.trace("Started puzzle notification loop.") |
524 | 535 | tomorrow, time_left = time_left_to_est_midnight() |
|
0 commit comments