Client - init calendar on Dashboard
This commit is contained in:
@ -2,10 +2,13 @@ import {
|
||||
addDays,
|
||||
addMonths,
|
||||
addYears,
|
||||
endOfMonth,
|
||||
endOfWeek,
|
||||
startOfMonth,
|
||||
startOfWeek,
|
||||
startOfYear,
|
||||
} from 'date-fns'
|
||||
import { utcToZonedTime } from 'date-fns-tz'
|
||||
|
||||
export const startDate = (
|
||||
duration: string,
|
||||
@ -40,3 +43,20 @@ export const incrementDate = (duration: string, day: Date): Date => {
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
export const getDateWithTZ = (dateInUTC: string, tz: string): Date => {
|
||||
return utcToZonedTime(new Date(dateInUTC), tz)
|
||||
}
|
||||
|
||||
export const getCalendarStartAndEnd = (
|
||||
date: Date,
|
||||
weekStartingMonday: boolean
|
||||
): Record<string, Date> => {
|
||||
const monthStart = startOfMonth(date)
|
||||
const monthEnd = endOfMonth(date)
|
||||
const weekStartsOn = weekStartingMonday ? 1 : 0
|
||||
return {
|
||||
start: startOfWeek(monthStart, { weekStartsOn }),
|
||||
end: endOfWeek(monthEnd),
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user