Skip to content

createOrThrow ​

The createOrThrow() function builds a TheDate from a TheDate, a SerializedTheDate, a Date, or a timestamp. It throws CreateTheDateError when the input is invalid.

Interactive example ​

Syntax ​

typescript
function createOrThrow<
	GenericInput extends TheDate | SerializedTheDate | Date | number
>(
	input: GenericInput
): TheDate

Parameters ​

  • input: A date (TheDate), a SerializedTheDate, a JavaScript Date, or a timestamp.

Return value ​

A valid TheDate. If the timestamp is out of bounds or the value is inconsistent, a CreateTheDateError is thrown.

See also ​

  • create – Returns an Either instead of throwing.
  • isSafeTimestamp – Checks a timestamp before conversion.

Sources ​

Released under the MIT license.