Room planner: fix spans_next, night counter, and B2B booking priority

spans_next was using departure > viewDate (today), which made any 1-night
booking extend the card to the right. Fixed to departure > tomorrow so the
card only extends when it's also active tomorrow.

Night counter used Date.parse() on NewBook datetime strings, which browsers
parse as local time and shift off by hours in BST. Replaced with utcDay()
which slices the YYYY-MM-DD prefix and calls Date.UTC() — always correct.

When multiple bookings overlap today, prefer the one arriving today so an
arriving guest takes priority over a stale stopover. Also treat a co-active
non-arriving booking as the B2B departing context.

Force previous-day bracket to show as "departed" (purple) when that booking
departs today, without waiting for NewBook to update its status field.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
jtricerolph 2026-07-04 11:31:29 +00:00
parent 663ef5d107
commit b66b3a7854
2 changed files with 62 additions and 40 deletions

View file

@ -16,10 +16,17 @@ interface Props {
const I = { strokeWidth: 1.75 }
// Parse any date(-time) string as a UTC midnight value, ignoring any time component.
// Date.parse on "YYYY-MM-DD HH:MM:SS" is timezone-ambiguous in browsers; this is not.
function utcDay(s: string): number {
const d = s.slice(0, 10)
return Date.UTC(+d.slice(0, 4), +d.slice(5, 7) - 1, +d.slice(8, 10))
}
function nightsInfo(arrival: string, departure: string, viewDate: string) {
const msDay = 86400000
const total = Math.round((Date.parse(departure) - Date.parse(arrival)) / msDay)
const current = Math.round((Date.parse(viewDate) - Date.parse(arrival)) / msDay) + 1
const msDay = 86400000
const total = Math.round((utcDay(departure) - utcDay(arrival)) / msDay)
const current = Math.round((utcDay(viewDate) - utcDay(arrival)) / msDay) + 1
return { current: Math.max(1, Math.min(current, total)), total: Math.max(1, total) }
}