diff options
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/time.ts | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/util/time.ts b/src/util/time.ts index ea4f8ca8d..f296aba12 100644 --- a/src/util/time.ts +++ b/src/util/time.ts @@ -49,6 +49,7 @@ export function getTimestampNow(): Timestamp { export function getDurationRemaining( deadline: Timestamp, now = getTimestampNow(), + ): Duration { if (deadline.t_ms === "never") { return { d_ms: "forever" }; @@ -72,6 +73,19 @@ export function timestampMin(t1: Timestamp, t2: Timestamp): Timestamp { return { t_ms: Math.min(t1.t_ms, t2.t_ms) }; } +/** + * Truncate a timestamp so that that it represents a multiple + * of seconds. The timestamp is always rounded down. + */ +export function timestampTruncateToSecond(t1: Timestamp): Timestamp { + if (t1.t_ms === "never") { + return { t_ms: "never" }; + } + return { + t_ms: Math.floor(t1.t_ms / 1000) * 1000, + }; +} + export function durationMin(d1: Duration, d2: Duration): Duration { if (d1.d_ms === "forever") { return { d_ms: d2.d_ms }; |