refactor: use date-fns for date comparison
This commit is contained in:
parent
117ff23a0c
commit
40d220ed7b
@ -5,6 +5,8 @@ import { jellyfinHandler } from "../..";
|
|||||||
import { closePoll } from "../commands/closepoll";
|
import { closePoll } from "../commands/closepoll";
|
||||||
import { config } from "../configuration";
|
import { config } from "../configuration";
|
||||||
import { logger } from "../logger";
|
import { logger } from "../logger";
|
||||||
|
import toDate from "date-fns/fp/toDate";
|
||||||
|
import { addDays, isAfter, isBefore } from "date-fns";
|
||||||
|
|
||||||
|
|
||||||
export const name = 'guildScheduledEventCreate'
|
export const name = 'guildScheduledEventCreate'
|
||||||
@ -73,10 +75,14 @@ async function checkForPollsToClose(event: GuildScheduledEvent): Promise<void> {
|
|||||||
logger.error("Event does not have a scheduled start time. Cancelling", { guildId: event.guildId, requestId })
|
logger.error("Event does not have a scheduled start time. Cancelling", { guildId: event.guildId, requestId })
|
||||||
return
|
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 })
|
logger.info("Less than two days until event. Closing poll", { guildId: event.guildId, requestId })
|
||||||
closePoll(event.guild, requestId)
|
closePoll(event.guild, requestId)
|
||||||
} else {
|
} 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 })
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user