I need a TimeSpan that takes into account working hours. Let’s say that if we configure the TimeSpan with an 8 hour day, two days should return 16 total hours instead of 48. Does anybody know of such a class?
Thanks.
Edit
I need the same functionality as timespan but with configurable day duration. Adding, subtracting,…, should work taking this into account. I tried to extend TimeSpan, but it’s sealed. Maybe I should go for some extension methods to implement this as Oded suggested (or something similar).
If you simply want to figure out each day as 8 hours, you can do this:
Update:
Now that you provided some more detail, I would suggest wrapping timespan with your own type – you can have an
HoursInWorkingDayproperty in it which will allow you to configure the number of hours in a working day.Have a constructor that takes a timespan and assign that to a private timespan that you can use for calculations:
This can be extended to cater for any other requirements you have.