mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-05-24 04:22:10 -05:00
* Initial * Saves preferences * Include TW * mapModePreferencesToModeList * mapPoolFromPreferences initial * Preference to map pool * Adjust seed * q.looking tests * adds about created map preferences to memento in the correct spot (two preferrers) * Failing test about modes * Mode preferences to memento * Remove old Plus Voting code * Fix seeding * find match by id via kysely * View map memento * Fix up map list generation logic * Mode memento info * Future match modes * Add TODO * Migration number * Migrate test DB * Remove old map pool code * createGroupFromPrevious new * Settings styling * VC to settings * Weapon pool * Add TODOs * Progress * Adjust mode exclusion policy * Progress * Progress * Progress * Notes in progress * Note feedback after submit * Textarea styling * Unskip tests * Note sorting failing test * Private note in Q * Ownerpicksmaps later * New bottom section * Mobile layout initial * Add basic match meta * Tabs initial * Sticky tab * Unseen messages in match page * Front page i18n * Settings i18n * Looking 18n * Chat i18n * Progress * Tranfer weapon pools script * Sticky on match page * Match page translations * i18n - tiers page * Preparing page i18n * Icon * Show add note right after report
75 lines
1.7 KiB
TypeScript
75 lines
1.7 KiB
TypeScript
import type { MonthYear } from "./types";
|
|
import { type RankingSeason, SEASONS } from "~/features/mmr/season";
|
|
|
|
export function lastCompletedVoting(now: Date): MonthYear {
|
|
let match: { startDate: Date; endDate: Date } | null = null;
|
|
for (const season of SEASONS) {
|
|
const range = seasonToVotingRange(season);
|
|
|
|
if (now.getTime() > range.endDate.getTime()) {
|
|
match = range;
|
|
} else if (now.getTime() < range.endDate.getTime()) {
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (!match) {
|
|
throw new Error("No previous voting found.");
|
|
}
|
|
|
|
return rangeToMonthYear(match);
|
|
}
|
|
|
|
export function nextNonCompletedVoting(now: Date) {
|
|
for (const season of SEASONS) {
|
|
const range = seasonToVotingRange(season);
|
|
|
|
if (now.getTime() < range.endDate.getTime()) {
|
|
return range;
|
|
}
|
|
}
|
|
|
|
throw new Error("No next voting found.");
|
|
}
|
|
|
|
export function rangeToMonthYear(range: { startDate: Date; endDate: Date }) {
|
|
return {
|
|
month: range.startDate.getMonth(),
|
|
year: range.startDate.getFullYear(),
|
|
};
|
|
}
|
|
|
|
export function seasonToVotingRange(season: RankingSeason) {
|
|
const { ends: date } = season;
|
|
|
|
if (date.getUTCDay() !== 0) {
|
|
throw new Error("End date is not a Sunday.");
|
|
}
|
|
|
|
const endDate = new Date(date);
|
|
endDate.setUTCDate(endDate.getUTCDate() - 7);
|
|
endDate.setUTCHours(18, 0, 0, 0);
|
|
|
|
const startDate = new Date(endDate);
|
|
startDate.setUTCDate(startDate.getUTCDate() - 2);
|
|
|
|
return { startDate, endDate };
|
|
}
|
|
|
|
export function isVotingActive() {
|
|
const now = new Date();
|
|
|
|
for (const season of SEASONS) {
|
|
const { startDate, endDate } = seasonToVotingRange(season);
|
|
|
|
if (
|
|
now.getTime() > startDate.getTime() &&
|
|
now.getTime() < endDate.getTime()
|
|
) {
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|