also get booked days from calendar

This commit is contained in:
Thomas Ruoff
2022-04-01 00:12:40 +02:00
parent cd58a535cb
commit c31448ff9c
5 changed files with 43 additions and 9 deletions

View File

@@ -16,3 +16,7 @@ export function getNextBigger<T>(array: T[], pivot: T): T {
return array.sort().find((day) => day > pivot)
}
export function uniqueFilter(value, index, self) {
return self.indexOf(value) === index;
}

View File

@@ -1,4 +1,4 @@
import { parse, format, addDays } from 'date-fns'
import { parse, format, addDays, subDays } from 'date-fns'
import { utcToZonedTime } from 'date-fns-tz'
const FRONTEND_FORMAT = 'dd.MM.yyyy'
@@ -21,9 +21,11 @@ export function daysFormatFrontend(days: string[]): string {
export function getDays({
startDate,
endDate,
endDateExclusive = false,
}: {
startDate: Date
endDate: Date
endDateExclusive?: boolean
}): string[] {
let currentDay = new Date(startDate.getTime())
const days = [dateFormatBackend(currentDay)]
@@ -32,7 +34,9 @@ export function getDays({
return days
}
while (currentDay < endDate) {
const inclusiveEndDate = endDateExclusive ? subDays(endDate, 1) : endDate;
while (currentDay < inclusiveEndDate) {
currentDay = addDays(currentDay, 1)
days.push(dateFormatBackend(currentDay))
}