add some date handling
This commit is contained in:
24
web/src/lib/date.ts
Normal file
24
web/src/lib/date.ts
Normal file
@ -0,0 +1,24 @@
|
||||
import { isToday, isAfter, parseISO } from "date-fns";
|
||||
import { toZonedTime, format } from "date-fns-tz";
|
||||
|
||||
const timeZone = "Europe/Oslo";
|
||||
|
||||
export const commonDateFormat = "dd.MM.yyyy 'kl.' HH:mm";
|
||||
|
||||
export function toLocalTime(date: Date | string | number) {
|
||||
return toZonedTime(date, timeZone);
|
||||
}
|
||||
|
||||
export function formatDate(date: Date | string | number, formatStr: string) {
|
||||
return format(toLocalTime(date), formatStr, { timeZone });
|
||||
}
|
||||
|
||||
export function isTodayOrFuture(
|
||||
date: Date | string | number,
|
||||
timeZone = "UTC"
|
||||
) {
|
||||
const now = new Date();
|
||||
const zonedNow = toZonedTime(now, timeZone);
|
||||
const zonedDate = toLocalTime(date);
|
||||
return isToday(zonedDate) || isAfter(zonedDate, zonedNow);
|
||||
}
|
@ -1,6 +1,8 @@
|
||||
import { graphql } from "@/gql";
|
||||
import { EventFragment, EventOccurrence } from "@/gql/graphql";
|
||||
|
||||
export type { EventFragment } from "@/gql/graphql"
|
||||
|
||||
const EventFragmentDefinition = graphql(`
|
||||
fragment Event on EventPage {
|
||||
__typename
|
||||
|
Reference in New Issue
Block a user