Duration add
duration-add · version 1.0.0 · Dates & times (UTC, ISO 8601) · free, no key needed
Sum mixed SI duration terms in nanoseconds and return the exact rational in a target unit.
Use when you need to: duration add · add duration terms · sum mixed duration units.
Supported
- duration add
- add duration terms
- sum mixed duration units
Not supported
- months
- years
- weeks
- leap seconds
- ISO-8601 duration strings
- average duration
- floats
Behavior
- terms is a non-empty list of at most 32 {value, unit} duration amounts.
- Each value is a canonical integer string; unit is one of ns, us, ms, s, min, h, day.
- Terms are converted to nanoseconds with BigInt, summed, then expressed in the to unit as a reduced rational.
- day is exactly 86400 seconds; negative terms are allowed; leap seconds are not applied.
- Input integers and the reduced numerator and denominator may have at most 1000 digits excluding sign.
Input
terms(array of object, required): min items 1; max items 32to(one of "ns", "us", "ms", "s", "min", "h", "day", required)
Output
numerator(string, required): pattern^(0|-?[1-9][0-9]*)$denominator(string, required): pattern^[1-9][0-9]*$
Limits
- max digits: 1000
- max terms: 32
- units: ["ns","us","ms","s","min","h","day"]
Example
Request input:
{
"terms": [
{
"value": "1",
"unit": "min"
},
{
"value": "30",
"unit": "s"
}
],
"to": "s"
}
Response:
{
"result": {
"numerator": "90",
"denominator": "1"
}
}
How to call it
MCP
Connect https://computefirst.net/mcp (setup), then call execute with:
{
"id": "duration-add",
"version": "1.0.0",
"input": {
"terms": [
{
"value": "1",
"unit": "min"
},
{
"value": "30",
"unit": "s"
}
],
"to": "s"
}
}
HTTP (no key)
curl -X POST https://computefirst.net/v1/tools/duration-add/versions/1.0.0/execute \
-H "Content-Type: application/json" \
-d '{"terms":[{"value":"1","unit":"min"},{"value":"30","unit":"s"}],"to":"s"}'
The machine-readable contract is at /v1/tools/duration-add/versions/1.0.0.
CLI
node cli.mjs run duration-add 1.0.0 --input input.json --base-url https://computefirst.net
Get the client at /clients/cli/.
Related tools
- Duration convert: Convert a canonical integer duration between nanosecond-based SI units as an exact rational.
- Duration compare: Compare two SI duration amounts after converting both to nanoseconds.
- ISO date add: Add a signed whole-day delta to a strict YYYY-MM-DD calendar date.
- ISO date add months: Add a signed month count to a YYYY-MM-DD date, clamping the day to the target month.
- ISO date add years: Add a signed whole-year delta to a YYYY-MM-DD date, clamping the day if 29 February has no match.
- ISO date business day add: Add a signed count of business days to a date, skipping caller-supplied weekend weekdays and holidays.