# Duration compare

`duration-compare` · version 1.0.0 · Dates & times (UTC, ISO 8601) · free, no key needed

Compare two SI duration amounts after converting both to nanoseconds.

**Use when you need to: duration compare · compare two durations · compare duration amounts.**

## Supported

- duration compare
- compare two durations
- compare duration amounts

## Not supported

- months
- years
- weeks
- leap seconds
- ISO-8601 duration strings
- sort durations
- approximate compare

## Behavior

- left and right are {value, unit} duration amounts with canonical integer-string values.
- Units are ns, us, ms, s, min, h, and day; day is exactly 86400 seconds.
- Each amount is converted to nanoseconds as a BigInt and compared numerically.
- cmp is -1, 0, or 1 for left < right, left == right, and left > right.
- Negative durations are allowed; leap seconds, months, years, and ISO-8601 duration strings are rejected.

## Input

- `left` (object, required)
- `right` (object, required)

## Output

- `cmp` (one of -1, 0, 1, required)

## Limits

- max digits: 1000
- units: ["ns","us","ms","s","min","h","day"]

## Example

Request input:

```json
{
  "left": {
    "value": "1",
    "unit": "min"
  },
  "right": {
    "value": "59",
    "unit": "s"
  }
}
```

Response:

```json
{
  "result": {
    "cmp": 1
  }
}
```

## How to call it

### MCP

Connect `https://computefirst.net/mcp` ([setup](/docs#connect)), then call `execute` with:

```json
{
  "id": "duration-compare",
  "version": "1.0.0",
  "input": {
    "left": {
      "value": "1",
      "unit": "min"
    },
    "right": {
      "value": "59",
      "unit": "s"
    }
  }
}
```

### HTTP (no key)

```sh
curl -X POST https://computefirst.net/v1/tools/duration-compare/versions/1.0.0/execute \
  -H "Content-Type: application/json" \
  -d '{"left":{"value":"1","unit":"min"},"right":{"value":"59","unit":"s"}}'
```

The machine-readable contract is at [/v1/tools/duration-compare/versions/1.0.0](/v1/tools/duration-compare/versions/1.0.0).

### CLI

```sh
node cli.mjs run duration-compare 1.0.0 --input input.json --base-url https://computefirst.net
```

Get the client at [/clients/cli/](/clients/cli/).

## Related tools

- [ISO date compare](/tools/iso-date-compare): Compare two YYYY-MM-DD calendar dates and return -1, 0, or 1.
- [ISO date-time compare](/tools/iso-datetime-compare): Compare two strict UTC ISO-8601 datetimes and return -1, 0, or 1.
- [Duration add](/tools/duration-add): Sum mixed SI duration terms in nanoseconds and return the exact rational in a target unit.
- [Duration convert](/tools/duration-convert): Convert a canonical integer duration between nanosecond-based SI units as an exact rational.
- [ISO date business days count](/tools/iso-date-business-days-count): Count the business days in an inclusive date range, skipping caller-supplied weekend weekdays and holidays.
- [ISO date range intersect](/tools/iso-date-range-intersect): Compute the intersection of two inclusive [start, end] date ranges.
