Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Leaderboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from 'discord.js';
import DiscordBot from './DiscordBot';
import { request } from 'https';
import { aocTime, parseDay, send } from './common';
import { aocTime, numberOfDays, parseDay, send } from './common';
import * as fs from 'fs';
import { IncomingMessage } from 'http';

Expand Down Expand Up @@ -243,7 +243,7 @@ export default class Leaderboard {
if (member.stars === 0) continue;
let stars: string = '';

for (let i = 1; i < 26; i++) {
for (let i = 1; i <= numberOfDays(now.getFullYear()); i++) {
if (i in member.completion_day_level) {
if (member.completion_day_level[i as AdventDay]![2]) {
// part 1 and 2 are complete
Expand Down
14 changes: 12 additions & 2 deletions src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,24 @@ export function send(
}

/**
* Checks if given date is in the Advent of Code time (between Dec 1 and Dec 25)
* Checks if given date is in the Advent of Code time
* (between Dec 1 and Dec 25 for 2024 or earlier and between Dec 1 and Dec 12 for 2025 or later)
* @param date The date to check
* @returns Whether the date is in the Advent of Code time
*/
export function aocTime(date: Date): boolean {
return (
date.getMonth() === 11 &&
date.getDate() <= 25 &&
date.getDate() <= numberOfDays(date.getFullYear())&&
(date.getDate() !== 1 || date.getUTCHours() >= 5)
);
}

/**
* Returns the number of days of challenges for the current year
* @param year The year to check
* @returns The amount of days for the specified year
*/
export function numberOfDays(year: number): number {
return year <= 2024 ? 25 : 12;
}