mirror of
https://github.com/tomru/pfadi-bussle.git
synced 2026-03-04 06:57:12 +01:00
switch to prisma
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { parse, format, addDays, subDays } from 'date-fns'
|
||||
import { parse, format, addDays, subDays, differenceInDays } from 'date-fns'
|
||||
import { utcToZonedTime } from 'date-fns-tz'
|
||||
|
||||
const FRONTEND_FORMAT = 'dd.MM.yyyy'
|
||||
@@ -23,18 +23,18 @@ export function getDays({
|
||||
endDate,
|
||||
endDateExclusive = false,
|
||||
}: {
|
||||
startDate: Date
|
||||
endDate: Date
|
||||
startDate: string,
|
||||
endDate: string,
|
||||
endDateExclusive?: boolean
|
||||
}): string[] {
|
||||
let currentDay = new Date(startDate.getTime())
|
||||
let currentDay = new Date(startDate);
|
||||
const days = [dateFormatBackend(currentDay)]
|
||||
|
||||
if (!endDate) {
|
||||
return days
|
||||
}
|
||||
|
||||
const inclusiveEndDate = endDateExclusive ? subDays(endDate, 1) : endDate
|
||||
const inclusiveEndDate = endDateExclusive ? subDays(new Date(endDate), 1) : new Date(endDate)
|
||||
|
||||
while (currentDay < inclusiveEndDate) {
|
||||
currentDay = addDays(currentDay, 1)
|
||||
@@ -84,3 +84,8 @@ export function nowInTz(timezone = 'Europe/Berlin'): Date {
|
||||
export function getNextDay(date: Date) {
|
||||
return addDays(date, 1)
|
||||
}
|
||||
|
||||
export function getDayCount({ startDate, endDate }: { startDate: string, endDate: string }) {
|
||||
// TODO: check if this actually works as expected
|
||||
return differenceInDays(new Date(startDate), new Date(endDate)) + 1 // add one as it only counts full days;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user