Question

I know this is probably not possible but off hand does anyone know if there are any shortcuts or mechanisms within .NET to allow me to do this.

I have a 'Diary'

9AM - 5PM

Inside this diary I have events or 'Appointments'

10AM - 12PM - Appointment 1
1PM - 1:30PM - Appointment 2

What I am asking for is there a tool that I can invert the diary to give me free spaces outside of these Appointments.

E.g. It would return me a list of

9AM - 10AM
12PM - 1PM
1:30PM - 5PM

So that I can then use within my program.

Any Ideas?

Was it helpful?

Solution

You might want to check this CodeProject article: Time Period Library for .NET, specifically the TimeGapCalculator example.

OTHER TIPS

Yes there is! I highly suggest using this free library from the CodeProject called TimePeriod.

This library will handle

Doesn't seem that hard to implement yourself:

  • Sort the diary appointments by start date.
  • One free period from start diary > first appointment
  • One free period from last appointment > end diary
  • Iterate the appointments and each period in between is a free period
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top