The Arithematic/calculateTimeAverage extension calculates the average of multiple time values and returns the result in hours and minutes format.
This is useful when a journey needs to average durations, elapsed times, task completion times, or other HH:mm values that are already available as a JSON string array.
Parameters:
-
timeArrayrequired, a JSON string representing an array of time values inHH:mmformat, for example["01:30","02:15"];
Note: The input must be valid JSON and must parse into an array of strings. Each string is split using :, where the first part is treated as hours and the second part is treated as minutes.
NLP usage
Use the extension in a journey by calling Arithematic/calculateTimeAverage with the execute command. Pass the JSON time array to the matching extension input using as timeArray.
Note: The extension runs synchronously and returns the calculated average directly. The result is rounded to the nearest minute using Math.round.
execute "Arithematic/calculateTimeAverage" using '["01:30","02:15","03:00"]' as timeArray returning $responseexecute "Arithematic/calculateTimeAverage" using '["00:45","01:15","02:00"]' as timeArray returning $responseYou can also pass the time array from a variable when the value is prepared earlier in the journey.
execute "Arithematic/calculateTimeAverage" using "$timeArray" as timeArray returning $responsestore value '["01:30","02:15","03:00"]' in $timeArray
execute "Arithematic/calculateTimeAverage" using "$timeArray" as timeArray returning $responseExample output:
2:15This extension does not require any external resource.
The extension should be configured as:
- Run asynchronously: No
- Scope: Global
Limitation: This extension expects every array item to be a simple HH:mm string. It does not validate malformed values, empty arrays, missing minutes, non-numeric text, seconds, dates, AM/PM values, time zones, or locale-specific time formats. Because it uses parseInt, partially numeric values may still be parsed, and an empty input array can result in an invalid NaN:NaN-style result.
Add the extension to your Virtuoso instance
Select the domain that matches your Virtuoso account.
View source
Last updated: 25/05/2026
Resources:
This extension does not require any external resource.
let times = JSON.parse(timeArray)
let totalMinutes = 0;
for (let i = 0; i < times.length; i++) {
let parts = times[i].split(":");
let hours = parseInt(parts[0]);
let minutes = parseInt(parts[1]);
totalMinutes += (hours * 60) + minutes;
}
let averageMinutes = Math.round(totalMinutes / times.length);
let averageHours = Math.floor(averageMinutes / 60);
let averageMinutesFormatted = averageMinutes % 60;
let averageTime = averageHours + ":" + (averageMinutesFormatted < 10 ? "0" + averageMinutesFormatted : averageMinutesFormatted);
return(averageTime);
Comments
0 comments
Please sign in to leave a comment.