search envelope-o feed check
Home Unanswered Active Tags New Question
user comment-o

How to retrieve free time from calendar

Asked by jackie
12 years ago.

I would like to retrieve times on the calendar that have not been occupied by any events yet.

Is there a way to do so?

Thanks.

Comment posted by Dan Letecky
12 years ago.
Generally, I would suggest that you rather check this against the database.

But it depends on what are you going to do with the data - I assume that you need it on the client side (on the server side there is no reason not the check the DB) and that you want to use it to prevent event overlapping.

You can get a list of all events by checking dp.events array on the client side ("dp" being the ClientObjectName value). This works in both DayPilotCalendar and DayPilotScheduler. The array elements are actually "event parts". If there is an event that spans multiple days in DayPilotCalendar, it's shown as two boxes = event parts, one in each day.
You can check the following values:
  • Start
  • End
  • PartStart
  • PartEnd
And a few others (you will see the values if you open the HTML source of a page with DayPilot and scroll down to v.events = ""). The values are strings and can be converted to Date objects using new Date(dp.events[0].Start).

This is just a workaround:
  • the .events array is not public and might change in the future (although it's not likely)
  • it will involve quite a piece of code that will create the free time blocks from that information
However, I plan to add support for preventing event overlapping on the client side during move, resize and time range selection operations. Before it's available, you have two choices:
  • play with the .events array
  • check it in the server-side event handlers (you need to do this anyway) and use either CallBack + .Update("Not allowed") or PostBack + UpdatePanel + regular Label to pass the feedback back to the client
But you might as well be asking because of a completely different reason...
This question is more than 3 months old and has been closed. Please create a new question if you have anything to add.