JavaScript Temporal Duration compare()
Example
const d1 = Temporal.Duration.from({ hours:2, minutes:30 });
const d2 = Temporal.Duration.from({ hours:1, minutes:30 });
let result = Temporal.Duration.compare(d1, d2);
Try it Yourself »
Description
The compare() method returns -1, 0, or 1 indicating if the first duration
is shorter, equal to, or longer than the second.
Syntax
Temporal.Duration.compare(duration1, duration2)
Parameters
| Parameter | Description |
| duration1 | The first duration to compare. |
| duration2 | The second duration to compare. |
Return Value
| Type | Description |
| Number | -1 if duration1 is shorter than duration2. 0 if they are equal. 1 if duration1 is longer than duration2. |
Note
The equals() method compares only values of the same type.
Other Temporal types must be converted before comparison.
Browser Support
Temporal is a major update to the JavaScript standard (TC39).
It is currently supported in Chrome, Edge, Firefox, and Opera and is expected to reach full availability across browsers before the summer of 2026.
| Chrome 144 |
Edge 144 |
Firefox 139 |
Safari |
Opera 128 |
| Jan 2026 | Jan 2026 | May 2025 | 🚫 | Feb 2026 |
The Safari implementation can be tested in Safari Technology Preview by enabling the --use-temporal runtime flag.
Polyfill
Until Safari support Temporal natively, you can use the official polyfill:
<script
src="https://cdn.jsdelivr.net/npm/@js-temporal/polyfill/dist/index.umd.js">
</script>