aboutsummaryrefslogtreecommitdiff
path: root/packages/taler-util
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2021-11-02 17:02:04 +0100
committerFlorian Dold <florian@dold.me>2021-11-02 17:02:14 +0100
commitfdc36b4fb75201e23023a583b8eebd05b1f24f77 (patch)
tree828fdd4cd2e80dcbd170211f8babff1adf096279 /packages/taler-util
parent83b63d1cc076dced82a235d7ca37ff04357ddb73 (diff)
anastasis-core: compute upload fees
Diffstat (limited to 'packages/taler-util')
-rw-r--r--packages/taler-util/src/amounts.ts3
-rw-r--r--packages/taler-util/src/time.ts14
2 files changed, 16 insertions, 1 deletions
diff --git a/packages/taler-util/src/amounts.ts b/packages/taler-util/src/amounts.ts
index 5a8c7f06f..41fd14bee 100644
--- a/packages/taler-util/src/amounts.ts
+++ b/packages/taler-util/src/amounts.ts
@@ -349,7 +349,8 @@ export class Amounts {
}
}
- static mult(a: AmountJson, n: number): Result {
+ static mult(a: AmountLike, n: number): Result {
+ a = this.jsonifyAmount(a);
if (!Number.isInteger(n)) {
throw Error("amount can only be multipied by an integer");
}
diff --git a/packages/taler-util/src/time.ts b/packages/taler-util/src/time.ts
index c0858ada6..856db8a57 100644
--- a/packages/taler-util/src/time.ts
+++ b/packages/taler-util/src/time.ts
@@ -69,6 +69,20 @@ export function getDurationRemaining(
return { d_ms: deadline.t_ms - now.t_ms };
}
+export namespace Duration {
+ export const getRemaining = getDurationRemaining;
+ 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 namespace Timestamp {
+ export const min = timestampMin;
+}
+
export function timestampMin(t1: Timestamp, t2: Timestamp): Timestamp {
if (t1.t_ms === "never") {
return { t_ms: t2.t_ms };