Client - init calendar on Dashboard

This commit is contained in:
Sam
2021-09-05 17:43:14 +02:00
parent a85860581f
commit 2ae2cf04d5
23 changed files with 500 additions and 22 deletions

View File

@ -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),
}
}