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

24 lines
818 B
TypeScript

import { format, isToday } from "date-fns";
import { utcToZonedTime } from "date-fns-tz"
import { logger } from "../logger";
import de from "date-fns/locale/de";
import { Maybe } from "../interfaces";
export function createDateStringFromEvent(eventStartDate: Maybe<Date>, requestId: string, guildId?: string): string {
if (!eventStartDate) {
logger.error("Event has no start. Cannot create dateString.", { guildId, requestId })
return `"habe keinen Startzeitpunkt ermitteln können"`
}
const timeZone = 'Europe/Berlin'
const zonedDateTime = utcToZonedTime(eventStartDate, timeZone)
const time = format(zonedDateTime, "HH:mm", { locale: de })
if (isToday(zonedDateTime)) {
return `heute um ${time}`
}
const date = format(zonedDateTime, "eeee dd.MM.", { locale: de })
return `am ${date} um ${time}`
}