apoc.coll.avgDuration

Function APOC Full

apoc.coll.avgDuration([duration('P2DT3H'), duration('PT1H45S'), …​]) - returns the average of a list of duration values

Signature

apoc.coll.avgDuration(durations :: LIST? OF DURATION?) :: (DURATION?)

Input parameters

Name Type Default

durations

LIST? OF DURATION?

null

Usage Examples

The apoc.coll.avgDuration works similar to the avg() function, but it’s not an aggregate function and takes a list of durations as an argument. For example:

WITH [duration('P2DT4H1S'), duration('PT1H1S'), duration('PT1H6S'), duration('PT1H5S')] AS durations
RETURN apoc.coll.avgDuration(durations) AS value
Table 1. Results
value

PT13H45M3.25S

In case of null or empty list, a null result will be returned:

RETURN apoc.coll.avgDuration([]) AS output;
RETURN apoc.coll.avgDuration(null) AS output;
Table 2. Results
output

null

In case a non-duration list is passed, a Type mismatch error will be thrown:

RETURN apoc.coll.avgDuration([1,2,3]) AS value;
Table 3. Results

Type mismatch: expected List<Duration> but was List<Integer>

While in case a list with all duration values is not passed, a TypeError will be thrown:

RETURN apoc.coll.avgDuration([duration('PT1H1S'),2,3]) AS output;
Table 4. Results

Can’t coerce `Long(2)` to Duration