Skip to content

Commit

Permalink
Official Tournament Scheduler: fix month and time limits
Browse files Browse the repository at this point in the history
Closes #93
  • Loading branch information
sirDonovan committed Apr 17, 2024
1 parent ae2e1b5 commit fdf163a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/html-pages/components/number-text-input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class NumberTextInput extends TextInput {

onSubmit(input: string): void {
const inputAmount = parseInt(input);
if (isNaN(inputAmount)) {
if (!Tools.isInteger(input) || isNaN(inputAmount)) {
this.errors.push("You must specify a valid number.");
} else {
if (this.props.min && inputAmount < this.props.min) {
Expand Down
10 changes: 5 additions & 5 deletions src/test/modules/tournaments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,18 @@ describe("Tournaments", () => {
const database = Storage.getDatabase(room);
database.officialTournamentSchedule = {years: {}};

const year = 2022;
const date = new Date();
date.setFullYear(year);

const month = 0;
let month = date.getMonth() + 1;
if (month === 12) month = 0;
date.setMonth(month);

const scheduleMonth = month + 1;
const lastDayOfMonth = Tools.getLastDayOfMonth(date);

const formats: Dict<string> = {1: "gen8ou", 2: "gen8uu", 3: "gen8ru"};
database.officialTournamentSchedule.years[year] = {months: {}};
const schedule = database.officialTournamentSchedule.years[year];
database.officialTournamentSchedule.years[date.getFullYear()] = {months: {}};
const schedule = database.officialTournamentSchedule.years[date.getFullYear()];

// 4 officials on 1 day
let times: [number, number][] = [[2, 30], [9, 30], [15, 30], [20, 30]];
Expand Down
10 changes: 9 additions & 1 deletion src/tournaments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ export class Tournaments {
return true;
};

const now = Date.now();

// month is eventually undefined due to rolloverDay()
outer:
while (month) {
Expand All @@ -199,9 +201,15 @@ export class Tournaments {
}

date.setHours(scheduleDays[scheduleDay]!.times[i][0], scheduleDays[scheduleDay]!.times[i][1], 0, 0);

const tournamentTime = date.getTime();
const remainingTime = tournamentTime - now;
if (remainingTime < 0) continue;
if (remainingTime >= Number.MAX_SAFE_INTEGER) break outer;

this.officialTournaments[room]!.push({
format,
time: date.getTime(),
time: tournamentTime,
official: true,
endOfCycle: scheduleDays[scheduleDay]!.endOfCycle && scheduleDays[scheduleDay]!.endOfCycle![i],
});
Expand Down

0 comments on commit fdf163a

Please sign in to comment.