aboutsummaryrefslogtreecommitdiff
path: root/packages/taler-wallet-core/src/util
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2022-03-18 15:32:41 +0100
committerFlorian Dold <florian@dold.me>2022-03-21 19:20:48 +0100
commitf8d12f7b0d4af1b1769b89e80c87f9c169678564 (patch)
tree2478696c7bc1efc6d090b93aa340de542a7dccd9 /packages/taler-wallet-core/src/util
parent32cd54e11d80bde0274b3c0238f8f5bd00ff83cb (diff)
downloadwallet-core-f8d12f7b0d4af1b1769b89e80c87f9c169678564.tar.xz
wallet: t_s/d_us migration
Diffstat (limited to 'packages/taler-wallet-core/src/util')
-rw-r--r--packages/taler-wallet-core/src/util/http.ts17
-rw-r--r--packages/taler-wallet-core/src/util/retries.ts26
2 files changed, 22 insertions, 21 deletions
diff --git a/packages/taler-wallet-core/src/util/http.ts b/packages/taler-wallet-core/src/util/http.ts
index 43fe29bba..79afd5707 100644
--- a/packages/taler-wallet-core/src/util/http.ts
+++ b/packages/taler-wallet-core/src/util/http.ts
@@ -28,10 +28,7 @@ import { OperationFailedError, makeErrorDetails } from "../errors.js";
import {
Logger,
Duration,
- Timestamp,
- getTimestampNow,
- timestampAddDuration,
- timestampMax,
+ AbsoluteTime,
TalerErrorDetails,
Codec,
j2s,
@@ -314,24 +311,24 @@ export async function readSuccessResponseTextOrThrow<T>(
/**
* Get the timestamp at which the response's content is considered expired.
*/
-export function getExpiryTimestamp(
+export function getExpiry(
httpResponse: HttpResponse,
opt: { minDuration?: Duration },
-): Timestamp {
+): AbsoluteTime {
const expiryDateMs = new Date(
httpResponse.headers.get("expiry") ?? "",
).getTime();
- let t: Timestamp;
+ let t: AbsoluteTime;
if (Number.isNaN(expiryDateMs)) {
- t = getTimestampNow();
+ t = AbsoluteTime.now();
} else {
t = {
t_ms: expiryDateMs,
};
}
if (opt.minDuration) {
- const t2 = timestampAddDuration(getTimestampNow(), opt.minDuration);
- return timestampMax(t, t2);
+ const t2 = AbsoluteTime.addDuration(AbsoluteTime.now(), opt.minDuration);
+ return AbsoluteTime.max(t, t2);
}
return t;
}
diff --git a/packages/taler-wallet-core/src/util/retries.ts b/packages/taler-wallet-core/src/util/retries.ts
index 8dec22bed..4b78d38ef 100644
--- a/packages/taler-wallet-core/src/util/retries.ts
+++ b/packages/taler-wallet-core/src/util/retries.ts
@@ -21,11 +21,11 @@
/**
* Imports.
*/
-import { Timestamp, Duration, getTimestampNow } from "@gnu-taler/taler-util";
+import { AbsoluteTime, Duration } from "@gnu-taler/taler-util";
export interface RetryInfo {
- firstTry: Timestamp;
- nextRetry: Timestamp;
+ firstTry: AbsoluteTime;
+ nextRetry: AbsoluteTime;
retryCounter: number;
}
@@ -45,7 +45,7 @@ export function updateRetryInfoTimeout(
r: RetryInfo,
p: RetryPolicy = defaultRetryPolicy,
): void {
- const now = getTimestampNow();
+ const now = AbsoluteTime.now();
if (now.t_ms === "never") {
throw Error("assertion failed");
}
@@ -54,10 +54,14 @@ export function updateRetryInfoTimeout(
return;
}
- const nextIncrement = p.backoffDelta.d_ms * Math.pow(p.backoffBase, r.retryCounter)
+ const nextIncrement =
+ p.backoffDelta.d_ms * Math.pow(p.backoffBase, r.retryCounter);
const t =
- now.t_ms + (p.maxTimeout.d_ms === "forever" ? nextIncrement : Math.min(p.maxTimeout.d_ms, nextIncrement));
+ now.t_ms +
+ (p.maxTimeout.d_ms === "forever"
+ ? nextIncrement
+ : Math.min(p.maxTimeout.d_ms, nextIncrement));
r.nextRetry = { t_ms: t };
}
@@ -73,13 +77,13 @@ export function getRetryDuration(
return { d_ms: "forever" };
}
const t = p.backoffDelta.d_ms * Math.pow(p.backoffBase, r.retryCounter);
- return { d_ms: p.maxTimeout.d_ms === "forever" ? t : Math.min(p.maxTimeout.d_ms, t) };
+ return {
+ d_ms: p.maxTimeout.d_ms === "forever" ? t : Math.min(p.maxTimeout.d_ms, t),
+ };
}
-export function initRetryInfo(
- p: RetryPolicy = defaultRetryPolicy,
-): RetryInfo {
- const now = getTimestampNow();
+export function initRetryInfo(p: RetryPolicy = defaultRetryPolicy): RetryInfo {
+ const now = AbsoluteTime.now();
const info = {
firstTry: now,
nextRetry: now,