From 6e13fce8a9c0037ce5fb8a9c2a9e5028e1ef1f5d Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Fri, 26 May 2023 11:12:44 +0200 Subject: [PATCH] taler-util: compile-time flavor for timestamp types --- packages/taler-util/src/time.ts | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/packages/taler-util/src/time.ts b/packages/taler-util/src/time.ts index 8b4f4cac3..6ada13e25 100644 --- a/packages/taler-util/src/time.ts +++ b/packages/taler-util/src/time.ts @@ -23,15 +23,40 @@ */ import { Codec, renderContext, Context } from "./codec.js"; +declare const flavor_AbsoluteTime: unique symbol; +declare const flavor_TalerProtocolTimestamp: unique symbol; +declare const flavor_TalerWalletDbTimestamp: unique symbol; + export interface AbsoluteTime { /** * Timestamp in milliseconds. */ readonly t_ms: number | "never"; + + readonly _flavor?: typeof flavor_AbsoluteTime; } export interface TalerProtocolTimestamp { + /** + * Seconds (as integer) since epoch. + */ readonly t_s: number | "never"; + + readonly _flavor?: typeof flavor_TalerProtocolTimestamp; +} + +export interface TalerWalletDbTimestamp { + /** + * Seconds (as integer) since epoch. + */ + readonly t_s: number | "never"; + + /** + * Optional microsecond offset (non-negative integer). + */ + readonly off_us?: number; + + readonly _flavor?: typeof flavor_TalerWalletDbTimestamp; } export namespace TalerProtocolTimestamp {