temporal-fns
API reference

API reference

The API is experimental. See installation and setup before running these examples.

Import functions from @frantss/temporal-fns, except the two calendar widget adapters, which use @frantss/temporal-fns/calendar. Each function has its own file with examples, related APIs, and executable Gherkin behavior links. Group links describe shared input types and conventions.

Functions

Shared contracts

  • Supply a global Temporal; importing this package does not install it.
  • Pass Temporal objects of a supported kind. Strings and legacy Date objects are not implicitly converted; fromCalendarDate explicitly accepts Date.
  • Calendar-bearing values must use iso8601. Non-ISO calendars throw RangeError.
  • Pairs, collections, and interval arguments require matching kinds. A PlainDate and a PlainDateTime cannot be combined even when they identify the same date.
  • Inputs, arrays, options, and global defaults are not changed. Options apply only to the call.
  • Omitted options and properties set to undefined select defaults. null does not select defaults. Unknown option keys and invalid option values throw.
  • Functions return a supported input kind unless their entry specifies a scalar, Date, tuple, or array. Partial values do not gain fields they lack.
  • All examples assume the installation and TypeScript setup are complete. Each TypeScript block has its own imports and variables. // => comments show expected results; // throws comments identify deliberate failures.

Behaviors: package and ownership contracts, input-kind coverage, TypeScript overload constraints.

Calendar comparison zones

Period comparisons, relative pair descriptions, and business-day differences select calendar fields as follows:

Input kindZone context
Plain valuesReject timeZone; use their own calendar fields
Instant, where supportedRequire explicit timeZone
ZonedDateTime with matching zone IDsUse that zone, or an explicit common timeZone override
ZonedDateTime with different zone IDsRequire an explicit common timeZone

These rules are specific to calendar comparisons. Collection selection and interval queries order zoned values by exact instant across zones. Sequences require matching endpoint zones. Parsing, formatting, and ToNow functions describe their own context requirements.

Behaviors: comparison context, relative context, business-day context.

Types and options

See exported types and options for value unions, result tuples, intervals, and option interfaces.

Behavior specifications

The links on each function lead to the source Gherkin scenarios under test/features. Stable case IDs identify each rule; scenario outlines contain the full set of examples. See the development instructions to run them.