autobaan/src/common/dayjs.ts

39 lines
779 B
TypeScript

import 'dayjs/locale/nl'
import * as dayjs from 'dayjs'
import * as isSameOrBefore from 'dayjs/plugin/isSameOrBefore'
import * as timezone from 'dayjs/plugin/timezone'
import * as utc from 'dayjs/plugin/utc'
dayjs.extend(isSameOrBefore)
dayjs.extend(utc)
dayjs.extend(timezone)
dayjs.locale('nl')
dayjs.tz.setDefault('Europe/Amsterdam')
export interface DateRange {
start: dayjs.Dayjs
end: dayjs.Dayjs
}
export interface SerializedDateRange {
start: string
end: string
}
export const convertDateRangeStringToObject = ({
start,
end,
}: {
start: string
end: string
}): DateRange => ({ start: dayjs(start), end: dayjs(end) })
const dayjsTz = (
date?: string | number | Date | dayjs.Dayjs | null | undefined,
) => {
return dayjs(date).tz()
}
export default dayjsTz