diff options
Diffstat (limited to 'packages')
-rw-r--r-- | packages/taler-util/src/time.ts | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/packages/taler-util/src/time.ts b/packages/taler-util/src/time.ts index 3d7d80485..cf370fdad 100644 --- a/packages/taler-util/src/time.ts +++ b/packages/taler-util/src/time.ts @@ -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 { return durationMax(d1, d2); } |