export const APP_PREFIX = "crupest"; export const APP_NAME = "mailserver"; export function getEnvRequired(key: string, usage: string): string { key = `${APP_PREFIX.toUpperCase()}_${APP_NAME.toUpperCase()}_${key}`; const value = Deno.env.get(key); if (value == null) { throw new Error(`Env ${key} does not exist, used for ${usage}.`); } return value; } function getZonedDateTime(instant?: Temporal.Instant | Date) { if (instant == null) { instant = Temporal.Now.instant(); } else if (instant instanceof Date) { instant = instant.toTemporalInstant(); } return instant.toZonedDateTimeISO("UTC"); } export function generateTimeStringForFileName( instant?: Temporal.Instant | Date, dateOnly: boolean = false, ): string { const time = getZonedDateTime(instant); if (dateOnly) { return time.toPlainDate().toString(); } else { return time.toPlainDateTime().toString().replaceAll(/:|\./g, "-"); } }