change some event datetime formatting

This commit is contained in:
2024-06-21 23:51:51 +02:00
parent 1097cd8b03
commit b51c737885
6 changed files with 30 additions and 18 deletions

View File

@ -4,8 +4,8 @@ import { toZonedTime, format } from "date-fns-tz";
const timeZone = "Europe/Oslo";
export const commonDateTimeFormat = "dd.MM.yyyy 'kl.' HH:mm";
export const commonDateFormat = "dd.MM.yyyy";
export const compactDateTimeFormat = "dd.MM.yyyy 'kl.' HH:mm";
export const compactDateFormat = "dd.MM.yyyy";
export function toLocalTime(date: Date | string | number) {
return toZonedTime(date, timeZone);
@ -24,6 +24,17 @@ export function formatYearMonth(yearMonth: string) {
return formatDate(parsed, "MMMM yyyy");
}
export function formatExtendedDateTime(date: Date | string | number, dateOnly: boolean = false) {
// wide date with weekday and month name
// year included if not current year
const parsed = toLocalTime(date);
const timePart = dateOnly ? "" : " 'kl.' HH:mm";
if (parsed.getFullYear === new Date().getFullYear) {
return formatDate(parsed, `EEEE d. MMMM${timePart}`);
}
return formatDate(parsed, `EEEE d. MMMM yyyy${timePart}`);
}
export function isTodayOrFuture(
date: Date | string | number,
timeZone = "UTC"