autobaan/src/common/dayjs.ts

39 lines
778 B
TypeScript
Raw Normal View History

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