compare duration

This commit is contained in:
Sebastian 2023-06-15 13:06:03 -03:00
parent 4e7967dbac
commit 08746f5bf0
No known key found for this signature in database
GPG Key ID: 173909D1A5F66069

View File

@ -216,6 +216,29 @@ export namespace Duration {
}; };
} }
/**
* Compare two durations. Returns 0 when equal, -1 when a < b
* and +1 when a > b.
*/
export function cmp(d1: Duration, d2: Duration): 1 | 0 | -1 {
if (d1.d_ms === "forever") {
if (d2.d_ms === "forever") {
return 0;
}
return 1;
}
if (d2.d_ms === "forever") {
return -1;
}
if (d1.d_ms == d2.d_ms) {
return 0;
}
if (d1.d_ms > d2.d_ms) {
return 1;
}
return -1;
}
export function max(d1: Duration, d2: Duration): Duration { export function max(d1: Duration, d2: Duration): Duration {
return durationMax(d1, d2); return durationMax(d1, d2);
} }