简体   繁体   中英

C# TimeSpan with Exclusions

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.

Eg 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?

您可能需要查看此CodeProject文章: .NET的时间段库 ,特别是TimeGapCalculator示例。

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM