diff --git a/apps/api/src/services/vote.Service.ts b/apps/api/src/services/vote.Service.ts index 43e2e3d..3fcea05 100644 --- a/apps/api/src/services/vote.Service.ts +++ b/apps/api/src/services/vote.Service.ts @@ -5,6 +5,33 @@ import { eq, count } from 'drizzle-orm' import type { AppEnv } from '../types' import { ensureUserExists } from './user.Service' import { refreshStallAggregates } from './stalls.Service' +function isVotingOpen(): boolean { + const istOffset = 5.5 * 60 * 60 * 1000; + const istTime = new Date(Date.now() + istOffset); + + const year = istTime.getUTCFullYear(); + const month = istTime.getUTCMonth() + 1; + const day = istTime.getUTCDate(); + + if (year !== 2026 || month !== 3) return false; + + const timeInMinutes = istTime.getUTCHours() * 60 + istTime.getUTCMinutes(); + + if (day === 28) { + const startMinsDay1 = 8 * 60 + 30; // 8:30 AM (510) + const endMins = 22 * 60; // 10:00 PM (1320) + return timeInMinutes >= startMinsDay1 && timeInMinutes <= endMins; + } + + if (day === 29) { + const startMinsDay2 = 9 * 60 + 30; // 9:30 AM (570) + const endMins = 12 * 60; // 12:00 PM (720) + return timeInMinutes >= startMinsDay2 && timeInMinutes <= endMins; + } + + return false; +} + export const submitVote = async ( env: AppEnv['Bindings'], userId: string,