mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-05-21 02:42:07 -05:00
38 lines
991 B
TypeScript
38 lines
991 B
TypeScript
export function checkInHasStarted(checkInStartTime: string) {
|
|
return new Date(checkInStartTime) < new Date();
|
|
}
|
|
|
|
export function sortTeamsBySeed(seeds: string[]) {
|
|
return function (
|
|
a: { id: string; createdAt: string | Date },
|
|
b: { id: string; createdAt: string | Date }
|
|
) {
|
|
const aSeed = seeds.indexOf(a.id);
|
|
const bSeed = seeds.indexOf(b.id);
|
|
|
|
// if one team doesn't have seed and the other does
|
|
// the one with the seed takes priority
|
|
if (aSeed === -1 && bSeed !== -1) return 1;
|
|
if (aSeed !== -1 && bSeed === -1) return -1;
|
|
|
|
// if both teams are unseeded the one who registered
|
|
// first gets to be seeded first as well
|
|
if (aSeed === -1 && bSeed === -1) {
|
|
return Number(a.createdAt) - Number(b.createdAt);
|
|
}
|
|
|
|
// finally, consider the seeds
|
|
return aSeed - bSeed;
|
|
};
|
|
}
|
|
|
|
export function tournamentHasStarted(
|
|
brackets: {
|
|
rounds: {
|
|
position: number;
|
|
}[];
|
|
}[]
|
|
) {
|
|
return brackets[0].rounds.length > 0;
|
|
}
|