From b2931fbac62a128862f310028c16b32b12f0c14e Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Thu, 19 May 2022 10:36:01 +0200 Subject: wallet-core: clamp claim retry properly --- packages/taler-util/src/time.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'packages/taler-util/src/time.ts') diff --git a/packages/taler-util/src/time.ts b/packages/taler-util/src/time.ts index f12e8d32b..8b0516bf8 100644 --- a/packages/taler-util/src/time.ts +++ b/packages/taler-util/src/time.ts @@ -91,19 +91,24 @@ export namespace Duration { } return { d_ms: deadline.t_ms - now.t_ms }; } + export function toIntegerYears(d: Duration): number { if (typeof d.d_ms !== "number") { throw Error("infinite duration"); } return Math.ceil(d.d_ms / 1000 / 60 / 60 / 24 / 365); } + export const fromSpec = durationFromSpec; + export function getForever(): Duration { return { d_ms: "forever" }; } + export function getZero(): Duration { return { d_ms: 0 }; } + export function fromTalerProtocolDuration( d: TalerProtocolDuration, ): Duration { @@ -116,6 +121,7 @@ export namespace Duration { d_ms: d.d_us / 1000, }; } + export function toTalerProtocolDuration(d: Duration): TalerProtocolDuration { if (d.d_ms === "forever") { return { @@ -126,6 +132,14 @@ export namespace Duration { d_us: d.d_ms * 1000, }; } + + export function clamp(args: { + lower: Duration; + upper: Duration; + value: Duration; + }): Duration { + return durationMax(durationMin(args.value, args.upper), args.lower); + } } export namespace AbsoluteTime { -- cgit v1.2.3