Skip to content

addInterval

Description

Returns the sum of two intervals as a single interval value.

For example, adding an interval of 1d (one day) to another 1d produces 2d (two days).

Note

This function also supports negative intervals. For example, 1d + -1h results in 23h, following standard arithmetic rules where adding a negative is equivalent to subtraction.

Syntax

Like many functions in DataPrime, addInterval supports two notations, function and method notation. These interchangeable forms allow flexibility in how you structure expressions.

addInterval(left: interval, right: interval): interval
(left: interval).addInterval(right: interval): interval

Arguments

NameTypeRequiredDescription
leftintervaltrueThe first interval to add
rightintervaltrueThe second interval to add

Example

Use case: Compute total processing time across different units

A document contains both a loading duration in milliseconds and processing timestamps in seconds. To compute the full duration of the transaction, convert the millisecond value to an interval, compute the processing interval, and add them together.

{
"loading_duration_ms": 5432,
"processing_start_time": 1728582889,
"processing_end_time": 1728582899
}
create processing_duration from diffTime(processing_start_time, processing_end_time)
| create total_duration from addInterval(loading_duration_ms.toInterval('ms'), processing_duration)
create processing_duration from processing_start_time.diffTime(processing_end_time)
| create total_duration from addInterval(loading_duration_ms.toInterval('ms'), processing_duration)

Output

{
"loading_duration_ms": 5432,
"processing_start_time": 1728582889,
"processing_end_time": 1728582899,
"processing_duration": "10s",
"total_duration": "15432ms"
}