Code Studio - Bookings, Diaries and Calendars

I’m trying to create a series of bookings using code studio, but having trouble.
I want to book the next available slot after a certain date, which isn’t available using a rule (only book next available slot) so need to do it with code studio.
So I assumed that adding a booking in code studio for a certain date & time would book only valid slots. Well it seems to book whatever you tell it, even if there’s an appointment already there or it’s not a valid day/slot in the diary and even if it’s not a valid working day/time in the linked calendar.
So I’m now trying to do that in code studio too, by a loop which check cs.is_working_day(mydate, calendar_ref) and adding a day if false. The trouble is that it always returns true regardless that I’m passing in a Sunday date which is not a working day. There doesn’t seem to be a way of working with diaries on Code Studio, so I can’t check that way. So basically it seems I can’t do it.
If there were a book_next_available_slot_after_date response option it would be easy.
Any suggestions? Nothing seems to work as I expected it to.

Hi Chris. Unfortunately not an expert in Booking functionality, but would you be able to create a temporary booking up to the date that you need, then use the book next available slot before removing the temp booking? This could possibly be done in a flash with minimal affect on other bookings. Have used similar approaches in creating custom Gannt charts where a task, with no preceding tasks, should not start before a given date - so creating an empty task from project start date to the required date is used as a padding element.

Actually, the is_working_day() works ok, it’s just that I was being stupid by passing a JS date rather than a Create-compatible date (I use mydate.toISOString().slice(0, 19).replace(‘T’, ’ ') to convert, don’t know if that’s the best way). I thought it would give me an error for passing an invalid date though, rather than just returning true.
The booking issue still stands because being a working time/day is only part of it. The other part is getting a free diary slot and I can’t do that with no interface to diaries.

Thanks for the suggestion Denis but if I create a booking for 20th December, it will still find any free slots before that date if I invoke a rule to book the next available slot. I still need something to allow me to “book the next available slot after 20th Dec 10:30am”