π§² Core Getters β
The Tempo class provides an extensive array of zero-cost getters that allow you to seamlessly read properties from the underlying Temporal instance.
TIP
Zero-Cost Lazy Evaluation
Tempo uses a sophisticated proxy-based lazy-evaluation pattern. Accessing a getter (like t.yy) resolves the property on demand, and then overwrites the getter with a static literal. This means the first access is
β‘ Native Temporal Gateway (.zdt) β
The .zdt getter provides direct, zero-overhead access to the underlying native Temporal.ZonedDateTime instance. All tables below cross-reference Tempo's ergonomic shorthand getters with their underlying native zdt.* properties or namespace sources:
| Getter | Type | Description | Example |
|---|---|---|---|
.zdt | Temporal.ZonedDateTime | Direct zero-overhead access to the underlying native Temporal instance | t.zdt.inLeapYear |
π Date Properties β
| Getter / Temporal | Type | Description | Example |
|---|---|---|---|
.yyzdt.year | number | 4-digit Year | 2026 |
.mmzdt.month | number | Month number (1 = Jan, 12 = Dec) | 10 |
.ddzdt.day | number | Day of the month (1β31) | 24 |
.dimzdt.daysInMonth | number | Total days in the month (28β31) | 31 |
.eragetTemporalEra(zdt) | string | Canonical calendar era identifier (falls back to 'ce' / 'bce' on calendars without Temporal eras, such as iso8601, chinese and dangi; use t.zdt.era for raw Temporal) | 'ce', 'bce', 'reiwa' |
.eongetTemporalEra(zdt).eraYear | number | Positive integer year within current .era [1] (use t.zdt.eraYear for raw Temporal) | 2026, 4 |
.jj | number | Integer Julian Day number for the local ISO date (ignoring time of day) [2] | 2461331 |
- Era Year (
.eon) vs. Calendar Year (.yy): While.yyreturns the signed astronomical year (e.g.2026or-3),.eonreturns the positive integer year within the active.era(e.g.2026in CE,4in 4 BCE, or4in Reiwa 4 when using the Japanese calendar). - Astronomical Julian Day (
.jj) vs. Day of Year (.doy):.jjprovides the integer Julian Day Number for the instance's local ISO date (an integer day count elapsed since noon UT on January 1, 4713 BC, in the proleptic Julian calendar, ignoring time of day, e.g.2461331for 2026-10-17). If you need the calendar day within the current year (1β366), use.doy.
β±οΈ Time Properties β
| Getter / Temporal | Type | Description | Example |
|---|---|---|---|
.hhzdt.hour | number | Hour of the day (0β23) | 15 |
.mizdt.minute | number | Minutes of the hour (0β59) | 30 |
.sszdt.second | number | Seconds of the minute (0β59) | 45 |
.mszdt.millisecond | number | Milliseconds of the second (0β999) | 123 |
.uszdt.microsecond | number | Microseconds of the millisecond (0β999) | 456 |
.nszdt.nanosecond | number | Nanoseconds of the microsecond (0β999) | 789 |
.ff | number | Fractional seconds representation | 0.123456789 |
ποΈ ISO Week & Day Alignments β
| Getter / Temporal | Type | Description | Example |
|---|---|---|---|
.yowzdt.yearOfWeek | number | 4-digit ISO week-numbering year | 2026 |
.woyzdt.weekOfYear | number | ISO week number of the year (1β53; canonical, supersedes legacy .ww) | 43 |
.dowzdt.dayOfWeek | number | ISO weekday number (1 = Mon, 7 = Sun) | 6 |
.doyzdt.dayOfYear | number | Day of the year (1β366) | 297 |
π€ Named String Representations β
| Getter / Path | Type | Description | Example |
|---|---|---|---|
.monEnum.keyOf(Tempo.MONTHS, zdt.month) | string | Full English month name (Gregorian registry label) | 'October' |
.mmmEnum.keyOf(Tempo.MONTH, zdt.month) | string | Short English month name (Gregorian registry label) | 'Oct' |
.wkdEnum.keyOf(Tempo.WEEKDAYS, zdt.dayOfWeek) | string | Full English weekday name | 'Saturday' |
.wwwEnum.keyOf(Tempo.WEEKDAY, zdt.dayOfWeek) | string | Short English weekday name | 'Sat' |
π Regional, Timezone & System Properties β
| Getter / Path | Type | Description | Example |
|---|---|---|---|
.tzzdt.timeZoneId | string | IANA Time Zone ID | 'Australia/Sydney' |
.calzdt.calendarId | string | Calendar identifier [3] | 'iso8601', 'gregory' |
.localeintl.locale?.toString() | string | Resolved canonical BCP 47 language tag | 'en-AU', 'en-US' |
.spheregeo.sphere | Tempo.COMPASS |undefined | Resolved terrestrial hemisphere or compass orientation ('north', 'south', 'equator', 'east', 'west') | 'south' |
.tst.epoch[timeStamp ?? 'ms'] | number | bigint | Unix timestamp using configured epoch unit (defaults to 'ms'; number for ss/ms/us, bigint for ns) [4] | 1792843200000 |
.isozdt.toInstant()β€· .toString() | string | Standard ISO 8601 string (RFC 3339) in UTC | '2026-10-24T04:30:45.123456789Z' |
.isValid | boolean | true if the underlying date-time is valid | true |
- Active Calendar (
.cal) vs. Locale Calendar Preference (.intl.info.calendar):.calreturns the instance's active calendar identifier (zdt.calendarId), which controls arithmetic and date representation. To inspect the cultural default calendar associated with the resolved locale (e.g.'gregory'foren-US, or'buddhist'forth-TH), uset.intl.info.calendar. - Configured Epoch Timestamp (
.ts):.tsresolves its value using the configuredtimeStampunit (defaults to'ms'). Only'ms'maps directly to nativezdt.epochMilliseconds. When configured to'ss','us', or'ns',.tsmaps to their respective epoch values ('ss'seconds,'us'microseconds, or'ns'zdt.epochNanoseconds). For an unconditional nanosecond timestamp regardless of instance configuration, uset.epoch.ns.
βοΈ Comparing & Checking Equality β
Tempo provides unified static and instance methods for ordering and equality checks without manual timestamp math:
| Method | Signature | Returns | Purpose |
|---|---|---|---|
Tempo.compare() | (tempo1?, tempo2?, unitOrOptions?) | -1 | 0 | 1 | Compares two dates chronologically (tempo2 defaults to now when omitted; usable directly in Array.prototype.sort(Tempo.compare)). |
Tempo.equals() | (tempo1?, tempo2?, unitOrOptions?) | boolean | Returns true when both values are valid and match at exact instant or at the requested unit boundary. |
t.equals() | (other?, unitOrOptions?) / (unitOrOptions) | boolean | Instance shorthand delegating to Tempo.equals(t, other, unitOrOptions), or comparing t against now when passed a single unit / { unit } options argument. |
Exact Instant vs. Unit Granularity β
When the third argument (unitOrOptions) is omitted, Tempo compares exact nanosecond instants (epoch.ns). Unlike native Temporal.ZonedDateTime.prototype.equals()βwhich returns false if timezones or calendars differβTempo.equals(a, b) treats matching instants across different timezones as equal.
Passing a CompareUnit string or CompareOptions object ({ unit }) evaluates both operands at that boundary instead:
const morning = new Tempo('2026-05-10T08:00:00');
const evening = new Tempo('2026-05-10T20:15:00');
Tempo.compare(morning, evening); // -1 (earlier instant)
Tempo.compare(morning, evening, 'day'); // 0 (same calendar day)
Tempo.compare(morning, evening, { unit: 'hour' }); // -1
Tempo.equals(morning, evening); // false
Tempo.equals(morning, evening, 'day'); // true
morning.equals(evening, { unit: 'month' }); // true
morning.equals('week'); // compares `morning` against now at ISO week granularity
morning.equals(new Tempo('2026-05-11T08:00:00'), 'time'); // true (08:00:00 wall-clock time)Supported Units (CompareUnit) β
Both unit strings and { unit } objects accept singular or plural unit names as well as shorthand tokens:
- Calendar boundaries:
'year'('years','yy'),'month'('months','mm'),'week'('weeks','ww', ISO week-year & week),'day'/'date'('days','dates','dd') - Time boundaries:
'hour'('hours','hh'),'minute'('minutes','mi'),'second'('seconds','ss'),'millisecond'('milliseconds','ms'),'microsecond'('microseconds','us'),'nanosecond'('nanoseconds','ns') - Wall-clock time slice:
'time'('times') β compares only time-of-day (HH:MM:SS.fffffffff), ignoring the calendar date
Passing a non-string unit or unrecognized unit string throws a TypeError.
Timezone Projection, Anchor Frame & Catch-Mode Behavior β
- Timezone Alignment: By default, when a unit is specified and
tempo2is coerced from a raw string or options object without an explicit timezone, it inheritstempo1's timezone and calendar, and unit boundaries are evaluated intempo1's timezone and calendar. - Explicit Frame (
timeZone,calendar,anchor):CompareOptions(andEqualOptions) accept optionalanchor,timeZone, andcalendarproperties to evaluate both operands against a single fixed reference frame (explicittimeZone/calendaroverrideanchorfields when combined)βuseful when comparing or sorting mixed-timezone arrays at unit granularity (e.g.{ unit: 'day', anchor: dates[0] }or{ unit: 'day', timeZone: 'UTC', calendar: 'iso8601' }). - Invalid Dates (Catch Mode): If either operand (or
anchor) is invalid in catch mode (!t.isValid),Tempo.equals()andt.equals()returnfalsewithout throwing, whereasTempo.compare()throws aRangeError.
ποΈ Structured Namespaces β
In addition to scalar getters, Tempo provides structured sub-namespaces for domain-specific metadata, high-precision epoch units, internationalization, and geographic context.
| Namespace | Type | Sub-Properties | Example Usage |
|---|---|---|---|
.epoch | Readonly<object> | High-precision Unix epoch counters: β’ .ss (number) β seconds since epochβ’ .ms (number) β milliseconds since epochβ’ .us (number) β microseconds since epochβ’ .ns (bigint) β nanoseconds since epoch | t.epoch.ms β 1792843200000t.epoch.ns β 1792843200000000000n |
.intl | TempoIntlNamespace | Internationalization metadata and locale engine: β’ .info (object) β cultural metadata (firstDay, weekend, calendar, minimalDays)β’ .locale (Intl.Locale) β native locale instance | t.intl.info.firstDay β 1t.intl.locale.baseName β 'en-US' |
.geo | Readonly<GeoConfig> | Geographic coordinates and location data: β’ .sphere ('north' | 'south' | 'equator'; always resolved)β’ .latitude, .longitude (number | undefined)β’ .elevation (number | undefined) | t.geo.sphere β 'south't.geo.latitude β -33.87 |
.term | TempoTermRegistry | Dynamic delegator accessing resolved terminology from loaded TermPlugin modules | t.term.season β 'summer't.term.quarter β 'Q1' |
.fmt | Record<string,string | undefined> | Dynamic delegator evaluating named format presets from Tempo.enums.FORMAT and config.registry.formats | t.fmt.date β '2026-10-24't.fmt.display β 'Sat, 24 Oct 2026' |
ποΈ Metadata & State Inspection β
Beyond date-time properties, Tempo instances expose read-only inspection getters for debugging, parser AST auditing, and plugin registration introspection:
| Getter | Type | Description | Example Usage |
|---|---|---|---|
.config | Readonly<Config> | Active configuration proxy reflecting resolved global defaults and local instance overrides. | t.config.timeZone |
.parse | Internal.Parse | Shadowed view of internal parse state, including active mode, anchor, and matched AST tokens (.result). | t.parse.anchort.parse.result |
ποΈ Design Philosophy: The 3-Tier Rubric β
Tempo v5 intentionally avoids cluttering the top-level prototype with aliases or wrappers for every single Temporal property. Instead, properties are organized into three clear tiers to maximize Developer Experience (DX) while keeping IDE autocompletion fast and uncluttered:
- Tier 1: Core Daily Primitives (
t.*)
High-frequency getters used across the majority of date applications (.yy,.mm,.dd,.hh,.mi,.ss,.dim,.doy,.dow,.iso,.mon, etc.). - Tier 2: Structured Namespaces (
t.<namespace>.*)
Domain-specific sub-properties grouped into clean namespaces (.epoch,.geo,.intl,.term) to prevent flat autocomplete pollution. - Tier 3: The Native Temporal Gateway (
t.zdt.*)
Standard TC39 Temporal properties (.daysInYear,.inLeapYear,.offsetNanoseconds,.hoursInDay,.monthCode) are accessed directly via.zdtwith zero performance overhead and full TypeScript type fidelity.
NOTE
Why isn't there a t.diy or t.inLeapYear on root?
Rather than introducing dozens of cryptic 3-letter abbreviations or wrapping all native Temporal properties, Tempo leaves standardized properties in t.zdt.*. If your application or domain requires custom root getters, Tempo is built to be easily extended:
TIP
Extending Tempo with Custom Getters & Namespaces
Developers are never limited to Tempo's built-in getters. The Tempo class is intentionally open for extension:
- Custom Instance Getters (
defineProperties/defineProperty): Define custom instance getters and methods directly onTempoor an isolated sandbox (Tempo.extend()). Resolver functions are automatically treated as lazy, per-instance memoized getters:typescriptimport { Tempo, defineProperties } from 'tempo-kit'; Tempo.use(defineProperties({ isWeekend: (t) => t.dow >= 6, quarter: (t) => Math.ceil(t.mm / 3), }, 'DateExtensions')); - Structured Sub-Namespaces: Mount entire custom namespaces (e.g.
t.audit.*ort.astro.*) with automatic proxy resolution and caching usingdefineNamespace. - Reusable Lifecycle Plugins: Package complex behaviors, prototype methods, and static tools using
definePlugin.
Learn more in the comprehensive Extending Tempo with Plugins Guide.