The sumTime operator calculates the total sum of time values in a collection. It operates on collections of DateTime, Time, or TimeSpan values and returns the aggregate sum as a TimeSpan.
Syntax
collection->sumTime()Parameters
A collection of DateTime, Time, or TimeSpan values.
Return Type
TimeSpan - representing the total duration
Description
The sumTime operator calculates the total duration by iterating through a collection of time-related values. For DateTime values, it sums only the time portions; for TimeSpan values, it directly adds the durations.
This operator is particularly useful for:
- Calculating total hours worked across multiple time entries
- Summing durations of tasks or activities
- Aggregating time spans for reporting purposes
Implementation Details
sumTime calls through to the Common Language Runtime (CLR) to perform precise time arithmetic, ensuring accurate calculations even when dealing with large datasets or complex time values.
Example:
Total hours worked from a collection of time entries:
let timeEntries = Sequence{
TimeSpan.FromHours(8),
TimeSpan.FromHours(7.5),
TimeSpan.FromHours(8),
TimeSpan.FromHours(6),
TimeSpan.FromHours(8.5)
}
in
timeEntries->sumTime()Result: 1 day 14 hours.
1.14:00:00