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:
Bianca Widstam
2025-12-19 14:03:30 +00:00
parent 3ac8956926
commit 57d0e1b27b
7 changed files with 57 additions and 94 deletions

View 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()
})
})

View File

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