Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions spec/booking_recurring_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -671,5 +671,33 @@ module PlaceOS::Model
details.next_idx.should eq 0
bookings.map(&.starting_tz.day).should eq [11, 12]
end

it "should reject recurring booking that clashes with regular all day or similar booking" do
tenant_id = Generator.tenant(domain: "recurrence.dev").id

all_day = Generator.booking(
tenant_id,
asset_id: "desk-1234",
start: Time.local(2025, 5, 28, location: timezone),
ending: Time.local(2025, 5, 28, location: timezone) + 8.hours
)
all_day.timezone = "Europe/Berlin"
all_day.all_day = true
all_day.save.should eq true

Booking.find?(all_day.id.not_nil!).should_not be_nil

recurring_booking = Generator.booking(
tenant_id,
asset_id: "desk-1234",
start: Time.local(2025, 5, 24, location: timezone),
ending: Time.local(2025, 5, 31, location: timezone)
)
recurring_booking.tenant_id = tenant_id
recurring_booking.recurrence_type = :daily
recurring_booking.recurrence_days = 0b1111111
recurring_booking.timezone = "Europe/Berlin"
recurring_booking.save.should eq false
end
end
end
14 changes: 12 additions & 2 deletions src/placeos-models/booking.cr
Original file line number Diff line number Diff line change
Expand Up @@ -513,8 +513,18 @@ module PlaceOS::Model
end

# 24 time -- 08:23:00, 13:30:00 etc
start_time = Time.unix(starting).to_s("%T")
end_time = Time.unix(ending).to_s("%T")
# starting time and ending times are the times of day
start_time_check = Time.unix(starting)
end_time_check = Time.unix(ending)

# we need to account for when a booking crosses a day boundry
if start_time_check.at_beginning_of_day != end_time_check.at_beginning_of_day
start_time = "00:00:00"
end_time = "23:59:59"
else
start_time = Time.unix(starting).to_s("%T")
end_time = Time.unix(ending).to_s("%T")
end

# calculate the period we want to check for clashes
max_period = 90.days
Expand Down