[REBOL] Re: Average of times
From: SunandaDH:aol at: 3-May-2004 14:47
> Let b be a block containing your session times.
That works if the durations are hours:minutes:seconds -- you are using
REBOL's standard date arithmetic.
But, if I read Stuart's question right, he has days:hours:minutes. They don't
add right in the same way:
1:12:00 + 1:12:00 should be 3:00:00 in his example (1 day & 12 hours, twice)
In REBOL, 1:12:00 + 1:12:00 = 2:24
Here's a couple of functions that misuse the date format to treat it as d:h:m
The result is in hours:minutes -- you'll need a bit more arithmetic to
convert that to days:hours:minutes -- after dividing to get the average, that is.
make-hm: func [d1 [time!] ][
return to-time join d1/minute [":" d1/second ":00"]
add-dhm: func [d1 [time!] d2 [time!] ][
return (make-hm d1)
+ (make-hm d2)
+ (24 * 3600 * to-time (d1/hour + d2/hour))
add-dhm 1:12:0 1:12:0 ;; 1.5 days + 1.5 days
== 72:00 ;; seventy-two hours = three days
add-dhm 0:30:30 0:30:30
add-dhm 2:1:45 0:0:15