organize events by months, weeks and days and print a calendar view

This commit is contained in:
2024-05-12 16:06:49 +02:00
parent e12a9a82fa
commit 7dfb505af0
4 changed files with 139 additions and 22 deletions

View File

@@ -1,5 +1,6 @@
import { isToday, isAfter, parseISO } from "date-fns";
import { toZonedTime, format } from "date-fns-tz";
import { isToday, isAfter, parse } from "date-fns";
import { nb } from "date-fns/locale";
import { toZonedTime, format} from "date-fns-tz";
const timeZone = "Europe/Oslo";
@@ -10,7 +11,16 @@ export function toLocalTime(date: Date | string | number) {
}
export function formatDate(date: Date | string | number, formatStr: string) {
return format(toLocalTime(date), formatStr, { timeZone });
return format(toLocalTime(date), formatStr, { timeZone, locale: nb });
}
export function formatYearMonth(yearMonth: string) {
// full name of month if year is current year, otherwise name of month + year
const parsed = parse(yearMonth, "yyyy-MM", new Date());
if (parsed.getFullYear === new Date().getFullYear) {
return formatDate(parsed, "MMMM");
}
return formatDate(parsed, "MMMM yyyy");
}
export function isTodayOrFuture(