Skip to content

createTime

The createTime() function builds a TheTime from a millisecond value or from a structured time object. It also accepts an ISO time string via the value field.

Interactive example

Syntax

typescript
function createTime(
	input: number & TimeConstraint,
	unit: Units
): TheTime

function createTime<
	GenericInput extends number | TheTime | SpoolingTime
>(
	input: GenericInput
): MayBeTime

TimeConstraint ensures the strict (number, unit) overload only accepts literal values and that they stay within the supported bounds for each unit.

INFO

Use the strict overload for constants known in advance (tests, defaults). For dynamic values, prefer the overload that returns MayBeTime.

Parameters

  • input: A millisecond value, a TheTime, or a SpoolingTime object (week, day, hour, minute, second, millisecond, value).
  • unit: Required unit for numeric input when using the strict overload ("millisecond", "second", "minute", "hour", "day", "week").

Return value

  • TheTime when called with (number, unit) or with a TheTime input (returned as-is).
  • MayBeTime (Either) when called with a number or SpoolingTime.

See also

Released under the MIT license.