taler-util: compile-time flavor for timestamp types

This commit is contained in:
Florian Dold 2023-05-26 11:12:44 +02:00
parent 735336d751
commit 6e13fce8a9
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B

View File

@ -23,15 +23,40 @@
*/ */
import { Codec, renderContext, Context } from "./codec.js"; 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 { export interface AbsoluteTime {
/** /**
* Timestamp in milliseconds. * Timestamp in milliseconds.
*/ */
readonly t_ms: number | "never"; readonly t_ms: number | "never";
readonly _flavor?: typeof flavor_AbsoluteTime;
} }
export interface TalerProtocolTimestamp { export interface TalerProtocolTimestamp {
/**
* Seconds (as integer) since epoch.
*/
readonly t_s: number | "never"; 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 { export namespace TalerProtocolTimestamp {