Skip to main content
Version: v0.1.6

Errors and issue codes

Every refusal in @cosyte/dates is named: a function either throws one of the errors below, or, for validateParts(), returns issues with one of the codes below. Nothing is logged and nothing is returned in place of a refusal. Troubleshooting says what to do about each.

Errors​

The four named classes are exported and extend Error, so instanceof works on each. The other two are the JavaScript built-ins.

ErrorThrown byCarries
DatePartsErrorassertValidParts, precisionOf, and every converterissues
PrecisionErrortoTemporal, toZonedDateTime, toInstantprecision
MissingZoneErrortoZonedDateTime, toInstantthe message
AmbiguousLocalTimeErrortoZonedDateTime, toInstantthe message
RangeErrortoZonedDateTime, toInstantthe message
TypeErrortoZonedDateTime, toInstantthe message

The converters are toISO, toTemporal, toZonedDateTime and toInstant.

DatePartsError​

The value failed validation. issues is the same array validateParts() returns for that value, and the message joins each issue's message. See DatePartsError.

PrecisionError​

The value lacks a component the call needs, and adding it would mean inventing it. toTemporal() throws it for a value with only a year; toZonedDateTime() and toInstant() throw it for a value with no time of day. precision is the precision the value has. From those two, when the value also has no zone, the message says that too. See PrecisionError.

MissingZoneError​

An instant was asked for, the value has no offsetMinutes, and no timeZone or offsetMinutes option was passed. See MissingZoneError.

AmbiguousLocalTimeError​

The local time does not exist in the named zone, because a daylight-saving transition skips it, or exists twice, because one repeats it. The message names the whole local date and time and the zone, says which, and for a repeated time names both candidate offsets. See AmbiguousLocalTimeError.

RangeError​

For a value with no offsetMinutes: the timeZone option is not an identifier Temporal knows, or the offsetMinutes option is not a whole number from -1439 to 1439.

TypeError​

Both the timeZone and the offsetMinutes options were passed for a value with no offsetMinutes.

Issue codes​

validateParts() returns one issue per fault, each a ValidationIssue with a component, a code and a message. The component is the name of the component at fault, or value when the argument itself is wrong. The type of code is IssueCode.

CodeComponentRaised when
not-a-parts-objectvaluethe argument is not an object, or is null, an array or a JavaScript Date
missing-componentthe missing onethere is no year, or a more significant component is absent while a less significant one is set
unreadablethe one readreading the component threw, so its value could not be seen
not-a-numberthe one at faultthe component is present but is not a number
not-finitethe one at faultthe component is NaN or infinite
not-an-integerthe one at faultthe component must be a whole number and is not
out-of-rangethe one at faultthe component is outside its range in the contract
year-not-four-digitsyearthe year is a whole number outside 1000 to 9999; no century window is applied
finer-than-nanosecondfractionfraction has more than nine decimal places; it is not rounded
offset-without-time-of-dayoffsetMinutesoffsetMinutes is set on a value with no hour
no-such-calendar-datedayeach component is in range, but together they name no real date

Most messages quote only the component at fault and its value. A no-such-calendar-date message names the day, the month and the year, which is the whole date, and so does the message of a DatePartsError that carries one. The component and code of an issue carry no value.