I have the following netfiddle:
How can I make it work by adding a period that spans over midnight like this:
`new Period( "9", Days.Workdays, TimeSpan.FromHours(22), TimeSpan.FromHours(07) )`
Notice from 22:00 (10:00 PM) to 07:00 (07:00 AM)
I have the following netfiddle:
How can I make it work by adding a period that spans over midnight like this:
`new Period( "9", Days.Workdays, TimeSpan.FromHours(22), TimeSpan.FromHours(07) )`
Notice from 22:00 (10:00 PM) to 07:00 (07:00 AM)
Assuming your question is about this part of your code:
e.Start <= timeOfDay && e.End > timeOfDay
You can change that to the following to account for time ranges over midnight:
e.Start <= e.End // Are times in sequence?
? (e.Start <= timeOfDay && e.End > timeOfDay) // Yes - standard calculation (AND)
: (e.Start <= timeOfDay || e.End > timeOfDay) // No - inverse calculation (OR)
Matt has the right answer above, but a couple changes:
First, you need to make sure you have parentheses (hence your memory problem):
Second, in your GetShiftPeriods method, you need to shift by a day (simply adding period.End won't work in this scenario because that would just be "7hrs" instead of 7 in the morning.
Lastly, you have some overlap in your periods that you've defined. It works fine for me when I remove period #4 (comment out) with the two changes above. Not sure if you intended to have overlap, but if you do - that period will be ignored.