Merged in feat/sw-2874-move-select-rate (pull request #2750)
Approved-by: Joakim Jäderberg
This commit is contained in:
44
packages/common/dt/utils/hasOverlappingDates.ts
Normal file
44
packages/common/dt/utils/hasOverlappingDates.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import { dt } from "../dt"
|
||||
|
||||
import type { Dayjs } from "../dt"
|
||||
|
||||
export function hasOverlappingDates(
|
||||
dateRangeItem: {
|
||||
startDate: Date | Dayjs | string | undefined | null
|
||||
endDate: Date | Dayjs | string | undefined | null
|
||||
},
|
||||
fromDate: Date | Dayjs,
|
||||
toDate: Date | Dayjs
|
||||
) {
|
||||
const startDate = dt(fromDate)
|
||||
const endDate = dt(toDate)
|
||||
|
||||
if (dateRangeItem.endDate && dateRangeItem.startDate) {
|
||||
const itemStartDate = dt(dateRangeItem.startDate)
|
||||
const itemEndDate = dt(dateRangeItem.endDate)
|
||||
|
||||
const fromDateIsBetweenItemDates = startDate.isBetween(
|
||||
itemStartDate,
|
||||
itemEndDate,
|
||||
"date",
|
||||
"[]"
|
||||
)
|
||||
const toDateIsBetweenItemDates = endDate.isBetween(
|
||||
itemStartDate,
|
||||
itemEndDate,
|
||||
"date",
|
||||
"[]"
|
||||
)
|
||||
|
||||
const itemFullyContained =
|
||||
startDate.isSameOrBefore(itemStartDate, "date") &&
|
||||
endDate.isSameOrAfter(itemEndDate, "date")
|
||||
|
||||
return (
|
||||
fromDateIsBetweenItemDates ||
|
||||
toDateIsBetweenItemDates ||
|
||||
itemFullyContained
|
||||
)
|
||||
}
|
||||
return true
|
||||
}
|
||||
@@ -27,6 +27,7 @@
|
||||
"./constants/signatureHotels": "./constants/signatureHotels.ts",
|
||||
"./dataCache": "./dataCache/index.ts",
|
||||
"./dt": "./dt/dt.ts",
|
||||
"./dt/utils/hasOverlappingDates": "./dt/utils/hasOverlappingDates.ts",
|
||||
"./global.d.ts": "./global.d.ts",
|
||||
"./hooks/*": "./hooks/*.ts",
|
||||
"./logger": "./logger/index.ts",
|
||||
|
||||
Reference in New Issue
Block a user