Merged in fix/BOOK-662-handle-overlapping-dates-timezone (pull request #3319)
Fix/BOOK-662 handle overlapping dates timezone * fix(BOOK-662): handle overlapping dates alerts * fix(BOOK-662): handle overlapping dates alerts * fix(BOOK-662): add test same dates Approved-by: Anton Gunnarsson
This commit is contained in:
38
packages/common/dt/utils/hasOverlappingDates.test.ts
Normal file
38
packages/common/dt/utils/hasOverlappingDates.test.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import { describe, expect, it } from "vitest"
|
||||
|
||||
import { dt } from "../dt"
|
||||
import { hasOverlappingDates } from "./hasOverlappingDates"
|
||||
|
||||
describe("hasOverlappingDates", () => {
|
||||
const item = { startDate: "2025-09-01", endDate: "2025-09-10" }
|
||||
|
||||
it("returns true if start date is within date range", () => {
|
||||
const result = hasOverlappingDates(item, dt("2025-09-05"), dt("2025-09-12"))
|
||||
expect(result).toBeTruthy()
|
||||
})
|
||||
|
||||
it("returns true if end date is within date range", () => {
|
||||
const result = hasOverlappingDates(item, dt("2025-08-28"), dt("2025-09-05"))
|
||||
expect(result).toBeTruthy()
|
||||
})
|
||||
|
||||
it("returns true if start and end date if match dates exactly", () => {
|
||||
const result = hasOverlappingDates(item, dt("2025-09-01"), dt("2025-09-10"))
|
||||
expect(result).toBeTruthy()
|
||||
})
|
||||
|
||||
it("returns true if start and end date is within date range", () => {
|
||||
const result = hasOverlappingDates(item, dt("2025-08-28"), dt("2025-09-15"))
|
||||
expect(result).toBeTruthy()
|
||||
})
|
||||
|
||||
it("returns true if start and end date is within date range", () => {
|
||||
const result = hasOverlappingDates(item, dt("2025-09-03"), dt("2025-09-05"))
|
||||
expect(result).toBeTruthy()
|
||||
})
|
||||
|
||||
it("return false if no overlap", () => {
|
||||
const result = hasOverlappingDates(item, dt("2025-08-01"), dt("2025-08-05"))
|
||||
expect(result).toBeFalsy()
|
||||
})
|
||||
})
|
||||
@@ -10,8 +10,8 @@ export function hasOverlappingDates(
|
||||
fromDate: Date | Dayjs,
|
||||
toDate: Date | Dayjs
|
||||
) {
|
||||
const startDate = dt(fromDate)
|
||||
const endDate = dt(toDate)
|
||||
const startDate = dt.utc(fromDate)
|
||||
const endDate = dt.utc(toDate)
|
||||
|
||||
if (dateRangeItem.endDate && dateRangeItem.startDate) {
|
||||
const itemStartDate = dt(dateRangeItem.startDate)
|
||||
|
||||
Reference in New Issue
Block a user