Skip to content

🧲 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 O(1) and every subsequent access is raw property access (O(0) cost).

⚑ 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:

GetterTypeDescriptionExample
.zdtTemporal.ZonedDateTimeDirect zero-overhead access to the underlying native Temporal instancet.zdt.inLeapYear

πŸ“… Date Properties ​

Getter / TemporalTypeDescriptionExample
.yy
zdt.year
number4-digit Year2026
.mm
zdt.month
numberMonth number (1 = Jan, 12 = Dec)10
.dd
zdt.day
numberDay of the month (1–31)24
.dim
zdt.daysInMonth
numberTotal days in the month (28–31)31
.era
getTemporalEra(zdt)
stringCanonical 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'
.eon
getTemporalEra(zdt).eraYear
numberPositive integer year within current .era [1] (use t.zdt.eraYear for raw Temporal)2026, 4
.jjnumberInteger Julian Day number for the local ISO date (ignoring time of day) [2]2461331
  1. Era Year (.eon) vs. Calendar Year (.yy): While .yy returns the signed astronomical year (e.g. 2026 or -3), .eon returns the positive integer year within the active .era (e.g. 2026 in CE, 4 in 4 BCE, or 4 in Reiwa 4 when using the Japanese calendar).
  2. Astronomical Julian Day (.jj) vs. Day of Year (.doy): .jj provides 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. 2461331 for 2026-10-17). If you need the calendar day within the current year (1–366), use .doy.

⏱️ Time Properties ​

Getter / TemporalTypeDescriptionExample
.hh
zdt.hour
numberHour of the day (0–23)15
.mi
zdt.minute
numberMinutes of the hour (0–59)30
.ss
zdt.second
numberSeconds of the minute (0–59)45
.ms
zdt.millisecond
numberMilliseconds of the second (0–999)123
.us
zdt.microsecond
numberMicroseconds of the millisecond (0–999)456
.ns
zdt.nanosecond
numberNanoseconds of the microsecond (0–999)789
.ffnumberFractional seconds representation0.123456789

πŸ—“οΈ ISO Week & Day Alignments ​

Getter / TemporalTypeDescriptionExample
.yow
zdt.yearOfWeek
number4-digit ISO week-numbering year2026
.woy
zdt.weekOfYear
numberISO week number of the year (1–53; canonical, supersedes legacy .ww)43
.dow
zdt.dayOfWeek
numberISO weekday number (1 = Mon, 7 = Sun)6
.doy
zdt.dayOfYear
numberDay of the year (1–366)297

πŸ”€ Named String Representations ​

Getter / PathTypeDescriptionExample
.mon
Enum.keyOf(Tempo.MONTHS, zdt.month)
stringFull English month name (Gregorian registry label)'October'
.mmm
Enum.keyOf(Tempo.MONTH, zdt.month)
stringShort English month name (Gregorian registry label)'Oct'
.wkd
Enum.keyOf(Tempo.WEEKDAYS, zdt.dayOfWeek)
stringFull English weekday name'Saturday'
.www
Enum.keyOf(Tempo.WEEKDAY, zdt.dayOfWeek)
stringShort English weekday name'Sat'

🌍 Regional, Timezone & System Properties ​

Getter / PathTypeDescriptionExample
.tz
zdt.timeZoneId
stringIANA Time Zone ID'Australia/Sydney'
.cal
zdt.calendarId
stringCalendar identifier [3]'iso8601', 'gregory'
.locale
intl.locale?.toString()
stringResolved canonical BCP 47 language tag'en-AU', 'en-US'
.sphere
geo.sphere
Tempo.COMPASS |
undefined
Resolved terrestrial hemisphere or compass orientation ('north', 'south', 'equator', 'east', 'west')'south'
.ts
t.epoch[timeStamp ?? 'ms']
number | bigintUnix timestamp using configured epoch unit (defaults to 'ms'; number for ss/ms/us, bigint for ns) [4]1792843200000
.iso
zdt.toInstant()
β€· .toString()
stringStandard ISO 8601 string (RFC 3339) in UTC'2026-10-24T04:30:45
.123456789Z'
.isValidbooleantrue if the underlying date-time is validtrue
  1. Active Calendar (.cal) vs. Locale Calendar Preference (.intl.info.calendar): .cal returns 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' for en-US, or 'buddhist' for th-TH), use t.intl.info.calendar.
  2. Configured Epoch Timestamp (.ts): .ts resolves its value using the configured timeStamp unit (defaults to 'ms'). Only 'ms' maps directly to native zdt.epochMilliseconds. When configured to 'ss', 'us', or 'ns', .ts maps to their respective epoch values ('ss' seconds, 'us' microseconds, or 'ns' zdt.epochNanoseconds). For an unconditional nanosecond timestamp regardless of instance configuration, use t.epoch.ns.

βš–οΈ Comparing & Checking Equality ​

Tempo provides unified static and instance methods for ordering and equality checks without manual timestamp math:

MethodSignatureReturnsPurpose
Tempo.compare()(tempo1?, tempo2?, unitOrOptions?)-1 | 0 | 1Compares two dates chronologically (tempo2 defaults to now when omitted; usable directly in Array.prototype.sort(Tempo.compare)).
Tempo.equals()(tempo1?, tempo2?, unitOrOptions?)booleanReturns true when both values are valid and match at exact instant or at the requested unit boundary.
t.equals()(other?, unitOrOptions?) / (unitOrOptions)booleanInstance 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:

typescript
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 tempo2 is coerced from a raw string or options object without an explicit timezone, it inherits tempo1's timezone and calendar, and unit boundaries are evaluated in tempo1's timezone and calendar.
  • Explicit Frame (timeZone, calendar, anchor): CompareOptions (and EqualOptions) accept optional anchor, timeZone, and calendar properties to evaluate both operands against a single fixed reference frame (explicit timeZone/calendar override anchor fields 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() and t.equals() return false without throwing, whereas Tempo.compare() throws a RangeError.

πŸ—‚οΈ Structured Namespaces ​

In addition to scalar getters, Tempo provides structured sub-namespaces for domain-specific metadata, high-precision epoch units, internationalization, and geographic context.

NamespaceTypeSub-PropertiesExample Usage
.epochReadonly<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 β†’ 1792843200000
t.epoch.ns β†’ 1792843200000000000n
.intlTempoIntlNamespaceInternationalization metadata and locale engine:
β€’ .info (object) β€” cultural metadata (firstDay, weekend, calendar, minimalDays)
β€’ .locale (Intl.Locale) β€” native locale instance
t.intl.info.firstDay β†’ 1
t.intl.locale.baseName β†’ 'en-US'
.geoReadonly<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
.termTempoTermRegistryDynamic delegator accessing resolved terminology from loaded TermPlugin modulest.term.season β†’ 'summer'
t.term.quarter β†’ 'Q1'
.fmtRecord<string,
string | undefined>
Dynamic delegator evaluating named format presets from Tempo.enums.FORMAT and config.registry.formatst.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:

GetterTypeDescriptionExample Usage
.configReadonly<Config>Active configuration proxy reflecting resolved global defaults and local instance overrides.t.config.timeZone
.parseInternal.ParseShadowed view of internal parse state, including active mode, anchor, and matched AST tokens (.result).t.parse.anchor
t.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:

  1. 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.).
  2. Tier 2: Structured Namespaces (t.<namespace>.*)
    Domain-specific sub-properties grouped into clean namespaces (.epoch, .geo, .intl, .term) to prevent flat autocomplete pollution.
  3. Tier 3: The Native Temporal Gateway (t.zdt.*)
    Standard TC39 Temporal properties (.daysInYear, .inLeapYear, .offsetNanoseconds, .hoursInDay, .monthCode) are accessed directly via .zdt with 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 on Tempo or an isolated sandbox (Tempo.extend()). Resolver functions are automatically treated as lazy, per-instance memoized getters:
    typescript
    import { 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.* or t.astro.*) with automatic proxy resolution and caching using defineNamespace.
  • Reusable Lifecycle Plugins: Package complex behaviors, prototype methods, and static tools using definePlugin.

Learn more in the comprehensive Extending Tempo with Plugins Guide.

Released under the MIT License.