Subtracting Delphi Time Ranges from a Date Range, Calculate Remaining Time
Posted
by Anagoge
on Stack Overflow
See other posts from Stack Overflow
or by Anagoge
Published on 2010-04-06T23:13:48Z
Indexed on
2010/04/06
23:33 UTC
Read the original article
Hit count: 256
I'm looking for an algorithm that will help calculate a workday working time length. It would have an input date range and then allow subtracting partially or completely intersecting time range slices from that date range and the result would be the number of minutes (or the fraction/multiple of a day) left in the original date range, after subtracting out the various non-working time slices.
For Example:
Input date range: 1/4/2010 11:21 am - 1/5/2010 3:00 pm
Subtract out any partially or completely intersecting slices like this:
Remove all day Sunday
Non-Sundays remove 11:00 - 12:00
Non-Sundays remove time after 5:00 pm
Non-Sundays remove time before 8:00 am
Non-Sundays remove time 9:15 - 9:30 am
Output: # of minutes left in the input date range
I don't need anything overly-general. I could hardcode the rules to simplify the code. If anyone knows of sample code or a library/function somewhere, or has some pseudo-code ideas, I'd love something to start with. I didn't see anything in DateUtils, for example. Even a basic function that calculates the number of minutes of overlap in two date ranges to subtract out would be a good start.
© Stack Overflow or respective owner