toCalendarDate
API index · Input types and conventions · Installation
toCalendarDate(value) → Date
Copy a PlainDate, PlainDateTime, or ZonedDateTime into a host-local Date with the same calendar fields. Date-only input uses midnight; a zoned input's zone is not transferred.
Reject microsecond or nanosecond precision, host-local gaps or skipped dates, and values outside the host's Date range with RangeError. Years 0–99 retain their literal year. A repeated host time can round-trip its displayed fields, without identifying an original instant.
The successful examples use ordinary October dates; they require the displayed times to exist in the host zone.
import { toCalendarDate } from '@frantss/temporal-fns/calendar';
const date = toCalendarDate(Temporal.PlainDate.from('2026-10-23'));
[date.getFullYear(), date.getMonth() + 1, date.getDate(), date.getHours()]; // => [2026, 10, 23, 0]
const zoned = Temporal.ZonedDateTime.from('2026-10-23T14:30[Asia/Tokyo]');
toCalendarDate(zoned).getHours(); // => 14
toCalendarDate(Temporal.PlainDateTime.from('2026-10-23T12:00:00.000001')); // throws RangeErrorRelated: fromCalendarDate, format, parse.
Behaviors: ADP-001: toCalendarDate copies fields into the host zone; ADP-002: A zoned calendar adapter deliberately copies fields rather than the instant; ADP-003: Years zero through ninety-nine are copied literally; ADP-005: Sub-millisecond precision cannot be silently discarded; ADP-006: A host gap is rejected instead of shifting the copied fields; ADP-011: A valid Temporal value may exceed the Date range in the host zone.