organize events by months, weeks and days and print a calendar view
This commit is contained in:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user