2023-06-23 23:46:11 +02:00
|
|
|
import { format, isToday, toDate } from "date-fns";
|
|
|
|
import {utcToZonedTime} from "date-fns-tz"
|
2023-06-23 15:51:07 +02:00
|
|
|
import { GuildScheduledEvent } from "discord.js";
|
|
|
|
import { logger } from "../logger";
|
2023-06-23 23:46:11 +02:00
|
|
|
import de from "date-fns/locale/de";
|
2023-06-23 15:51:07 +02:00
|
|
|
|
|
|
|
export function createDateStringFromEvent(event: GuildScheduledEvent, requestId: string, guildId?: string): string {
|
|
|
|
if(!event.scheduledStartAt) {
|
|
|
|
logger.error("Event has no start. Cannot create dateString.", {guildId, requestId})
|
2023-06-23 19:30:17 +02:00
|
|
|
return `"habe keinen Startzeitpunkt ermitteln können"`
|
2023-06-23 15:51:07 +02:00
|
|
|
}
|
|
|
|
|
2023-06-23 23:46:11 +02:00
|
|
|
const timeZone = 'Europe/Berlin'
|
|
|
|
const zonedDateTime = utcToZonedTime(event.scheduledStartAt, timeZone)
|
|
|
|
const time = format(zonedDateTime, "HH:mm", {locale: de})
|
|
|
|
|
|
|
|
if(isToday(zonedDateTime)) {
|
|
|
|
return `heute um ${time}`
|
|
|
|
}
|
2023-06-23 15:51:07 +02:00
|
|
|
|
2023-06-23 23:46:11 +02:00
|
|
|
const date = format(zonedDateTime, "eeee dd.MM", {locale: de})
|
2023-06-23 15:51:07 +02:00
|
|
|
return `am ${date} um ${time}`
|
|
|
|
}
|