Given multiple time span, how can I get an array that gives me number of working hours for a day.
The working hours start at 09:00 and end at 17:00
Examples:
15-Nov-2017 16:00 - 17-Nov-2017 12:00 -> Should give me an array of [1,8,3]
15-Nov-2017 09:00 - 17-Nov-2017 12:00 -> Should give me an array of [8,8,1] (This seems easy as I can do Hrs / 8 and Hrs % 8 to get the result.)
16-Nov-2017 15:00 - 17-Nov-2017 15:00 -> Should give me an array of [2,6]
This is the method that currently gives me total working hours between the start time and end time:
protected double getWorkingHrs(DateTime _dtTaskStart, DateTime _dtTaskEnd)
{
double count = 0;
for (var i = _dtTaskStart; i < _dtTaskEnd; i = i.AddHours(1))
{
if (i.DayOfWeek != DayOfWeek.Saturday && i.DayOfWeek != DayOfWeek.Sunday)
{
if (i.TimeOfDay.Hours >= 9 && i.TimeOfDay.Hours < 17)
{
count++;
}
}
}
return count;
}
Any help would be appreciated.
Task showed like this in 8 hour blocks. So when I add a 20 Hour task, I have to break them down into sets and display them in the grid. I have to split them as chances are the task on different day might get assigned to a different user and may have different notes etc.
Cheers