API reference@evolu/common › Time

Time representations, durations, and scheduling utilities.

Durations follow a pattern that other quantities in Evolu repeat, such as sizes in Bytes.ts:

  • Millis is the canonical unit, a validated number of milliseconds.
  • DurationLiteral is the human-readable form, such as "1.5s", validated at compile time and runtime.
  • Duration is what APIs accept: DurationLiteral | Millis.
  • durationToMillis normalizes a Duration to Millis.

Core

NameDescription
TimeTime and timer operations.
TimeDepDependency wrapper for Time.
TimeoutIdOpaque type for timeout handles.
createTimeCreates a Time using Date.now(), performance, and globalThis.setTimeout.

Millis

NameDescription
MillisNon-negative integer milliseconds used for timestamps and durations.
PositiveMillisPositive Millis value.
maxMillisMaximum Millis value.
MillisNon-negative integer milliseconds used for timestamps and durations.
minMillisMinimum Millis value.
ms120fpsFrame budget at 120fps (8ms).
ms60fpsFrame budget at 60fps (16ms).
msLongTaskLong task threshold (50ms).
PositiveMillisPositive Millis value.
formatMillisAsClockTimeFormats Millis as local time in HH:MM:SS.mmm format.
formatMillisAsDurationFormats Millis as a human-readable duration string.
millisToDateIsoConverts Millis to DateIso.
saturateMillisConverts a number to Millis, rounding to the nearest millisecond and saturating overflow at maxMillis.

Durations

NameDescription
DurationLiteralErrorError returned when DurationLiteral rejects a value.
DurationDurationLiteral or Millis.
DurationLiteralDuration literal string, from DurationLiteralMilliseconds to DurationLiteralYears.
DurationLiteralDaysDays duration: "1d" to "6d" or "1.1d" to "6.9d". See DurationLiteral.
DurationLiteralHoursHours duration: "1h" to "23h" or "1.1h" to "23.9h". See DurationLiteral.
DurationLiteralMillisecondsMilliseconds duration: "1ms" to "999ms". See DurationLiteral.
DurationLiteralMinutesMinutes duration: "1m" to "59m" or "1.1m" to "59.9m". See DurationLiteral.
DurationLiteralSecondsSeconds duration: "1s" to "59s" or "1.1s" to "59.9s". See DurationLiteral.
DurationLiteralWeeksWeeks duration: "1w" to "51w" or "1.1w" to "51.9w". See DurationLiteral.
DurationLiteralYearsYears duration: "1y" to "99y" or "1.1y" to "99.9y". See DurationLiteral.
PositiveDurationDurationLiteral or PositiveMillis.
DurationLiteralDuration literal Type with compile-time and runtime validation.
DurationLiteralDaysDays duration: "1d" to "6d" or "1.1d" to "6.9d". See DurationLiteral.
DurationLiteralHoursHours duration: "1h" to "23h" or "1.1h" to "23.9h". See DurationLiteral.
DurationLiteralMillisecondsMilliseconds duration: "1ms" to "999ms". See DurationLiteral.
DurationLiteralMinutesMinutes duration: "1m" to "59m" or "1.1m" to "59.9m". See DurationLiteral.
DurationLiteralSecondsSeconds duration: "1s" to "59s" or "1.1s" to "59.9s". See DurationLiteral.
DurationLiteralWeeksWeeks duration: "1w" to "51w" or "1.1w" to "51.9w". See DurationLiteral.
DurationLiteralYearsYears duration: "1y" to "99y" or "1.1y" to "99.9y". See DurationLiteral.
durationToMillisConverts a duration to milliseconds.

Performance

NameDescription
PerformanceDurationElapsed fractional milliseconds measured using PerformanceTime.
PerformanceTimeHigh-resolution milliseconds elapsed since PerformanceTimeOrigin.
PerformanceTimeOriginUnix epoch milliseconds used as the origin for PerformanceTime.
performanceDurationBetweenReturns the elapsed fractional milliseconds between two performance times.

Testing

NameDescription
TestTimeTest Time with controllable timers.
TestTimeDepDependency wrapper for TestTime.
testCreateTimeCreates a TestTime with controllable timers for testing.