jellyfin-discord-bot/server/helper/dateHelper.ts

24 lines
820 B
TypeScript
Raw Normal View History

2023-06-27 20:34:20 +02:00
import { format, isToday } from "date-fns";
2023-06-24 20:56:58 +02:00
import { utcToZonedTime } from "date-fns-tz"
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-07-05 23:21:44 +02:00
export function createDateStringFromEvent(eventStartDate:Date, requestId: string, guildId?: string): string {
if (!eventStartDate) {
2023-06-24 21:09:56 +02:00
logger.error("Event has no start. Cannot create dateString.", { guildId, requestId })
return `"habe keinen Startzeitpunkt ermitteln können"`
}
2023-06-24 21:09:56 +02:00
const timeZone = 'Europe/Berlin'
2023-07-05 23:21:44 +02:00
const zonedDateTime = utcToZonedTime(eventStartDate, timeZone)
2023-06-24 21:09:56 +02:00
const time = format(zonedDateTime, "HH:mm", { locale: de })
2023-06-24 21:09:56 +02:00
if (isToday(zonedDateTime)) {
return `heute um ${time}`
}
2023-06-24 20:56:58 +02:00
2023-06-24 21:09:56 +02:00
const date = format(zonedDateTime, "eeee dd.MM", { locale: de })
return `am ${date} um ${time}`
}