2023-05-26 15:43:14 -05:00
|
|
|
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'
|
2023-01-20 15:31:04 +01:00
|
|
|
import 'dayjs/locale/nl'
|
|
|
|
|
|
|
|
|
|
dayjs.extend(isSameOrBefore)
|
|
|
|
|
dayjs.extend(utc)
|
|
|
|
|
dayjs.extend(timezone)
|
|
|
|
|
dayjs.locale('nl')
|
|
|
|
|
|
|
|
|
|
dayjs.tz.setDefault('Europe/Amsterdam')
|
|
|
|
|
|
2023-05-26 15:43:14 -05:00
|
|
|
export interface DateRange {
|
2023-06-27 16:06:19 +02:00
|
|
|
start: dayjs.Dayjs
|
|
|
|
|
end: dayjs.Dayjs
|
2023-05-26 15:43:14 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface SerializedDateRange {
|
2023-06-27 16:06:19 +02:00
|
|
|
start: string
|
|
|
|
|
end: string
|
2023-05-26 15:43:14 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const convertDateRangeStringToObject = ({
|
2023-06-27 16:06:19 +02:00
|
|
|
start,
|
|
|
|
|
end,
|
2023-05-26 15:43:14 -05:00
|
|
|
}: {
|
2023-06-27 16:06:19 +02:00
|
|
|
start: string
|
|
|
|
|
end: string
|
2023-05-26 15:43:14 -05:00
|
|
|
}): DateRange => ({ start: dayjs(start), end: dayjs(end) })
|
|
|
|
|
|
2023-01-20 15:31:04 +01:00
|
|
|
const dayjsTz = (
|
2023-06-27 16:06:19 +02:00
|
|
|
date?: string | number | Date | dayjs.Dayjs | null | undefined,
|
2023-01-20 15:31:04 +01:00
|
|
|
) => {
|
2023-06-27 16:06:19 +02:00
|
|
|
return dayjs(date).tz()
|
2023-01-20 15:31:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default dayjsTz
|