diff --git a/server/events/guildScheduledEventCreate.ts b/server/events/guildScheduledEventCreate.ts index 9b51552..f0b66b6 100644 --- a/server/events/guildScheduledEventCreate.ts +++ b/server/events/guildScheduledEventCreate.ts @@ -5,6 +5,8 @@ import { jellyfinHandler } from "../.."; import { closePoll } from "../commands/closepoll"; import { config } from "../configuration"; import { logger } from "../logger"; +import toDate from "date-fns/fp/toDate"; +import { addDays, isAfter, isBefore } from "date-fns"; export const name = 'guildScheduledEventCreate' @@ -73,10 +75,14 @@ async function checkForPollsToClose(event: GuildScheduledEvent): Promise { logger.error("Event does not have a scheduled start time. Cancelling", { guildId: event.guildId, requestId }) return } - if ((updatedEvent.scheduledStartTimestamp - Date.now()) <= (1000 * 60 * 60 * 24 * 2)) { + + const eventDate: Date = toDate(updatedEvent.scheduledStartTimestamp) + const closePollDate: Date = addDays(eventDate, -2) + + if (isAfter(Date.now(), closePollDate)) { logger.info("Less than two days until event. Closing poll", { guildId: event.guildId, requestId }) closePoll(event.guild, requestId) } else { - logger.info(`ScheduledStart: ${updatedEvent.scheduledStartTimestamp}. Now: ${Date.now()}`, { guildId: event.guildId, requestId }) + logger.info(`ScheduledStart: ${closePollDate}. Now: ${toDate(Date.now())}`, { guildId: event.guildId, requestId }) } } \ No newline at end of file