You can use sumTime in OCL to add the time values in a collection when you need one total duration, such as the combined duration of work entries.
Syntax
collection->sumTime()
Purpose
sumTime calculates the total of the time-related values in a collection and returns that total as a TimeSpan.
Use it when a collection contains DateTime, Time, or TimeSpan values and you need the aggregate duration.
Input and result
| Item | Details |
|---|---|
| Input | A collection of DateTime, Time, or TimeSpan values.
|
| Result | A TimeSpan that represents the total duration.
|
DateTime handling
|
The operator adds the time portion of each DateTime value, not its date portion.
|
TimeSpan handling
|
The operator adds each duration directly. |
How it calculates the total
The operator iterates through the collection and adds each value to a running total.
- For a
DateTimevalue, it uses the time-of-day portion. For example, a value whose date and time are2026-07-01 08:00contributes eight hours; the2026-07-01date does not contribute to the total. - For a
TimeSpanvalue, it adds the duration itself. For example,06:30contributes six hours and 30 minutes. - The returned value is a
TimeSpan, so totals can extend beyond 24 hours.
Example: total duration
Suppose a collection of duration values contains:
08:0006:0024:00
Applying sumTime produces a TimeSpan of 1 day 14 hours. The result is 38 hours in total, which is represented as one day plus 14 hours.
1 day 14 hours.
1.14:00:00
Example: time portions of DateTime values
Suppose a collection contains these DateTime values:
2026-07-01 08:002026-07-02 06:30
sumTime uses 08:00 and 06:30. The resulting TimeSpan is 14:30.
Typical uses
Use sumTime for collection-based duration totals, including:
- Total hours worked across time entries.
- Total duration of tasks or activities.
- Aggregate duration values in reports.
For example, if each task has a duration recorded as a TimeSpan, use sumTime on the collection of those durations to obtain the total task time.
Total hours worked from a collection of time entries: 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:
Precision
sumTime calls through to the Common Language Runtime (CLR) for time arithmetic. This provides the time calculation used for the aggregate result.
