Temporal for Rust#
formatjs_temporal is an allocation-free no_std Temporal core. It provides
typed dates, times, durations, calendars, time zones, and Now.
Installation#
cargo add formatjs_temporal --features compiled_data
The published crate includes generated calendar and time-zone data and a Cargo build script.
Parse a zoned date and time#
use formatjs_temporal::{TemporalContext, ZonedParseOptions};
fn main() -> Result<(), formatjs_temporal::Error> {
let context = TemporalContext::compiled()?;
let meeting = context.parse_zoned(
"2020-03-07T12:00-05:00[America/New_York]",
ZonedParseOptions::default(),
)?;
println!("{}", meeting.instant());
// 2020-03-07T17:00:00Z
Ok(())
}
Reuse the context across calls. Parsed values keep their calendar and time-zone providers.
Choose how to supply data#
| Feature | Included data or integration |
|---|---|
| Default | Arithmetic calendars, UTC, and fixed offsets |
compiled_calendars | Chinese, Dangi, and Umm al-Qura tables |
compiled_time_zones | IANA history and recurring future rules |
compiled_data | Both sets of tables |
ffi | Optional JSON bridge for JavaScript backends |
For arithmetic calendars and UTC or fixed offsets, start with empty data registries:
use formatjs_temporal::{CalendarRegistry, TemporalContext, TimeZoneRegistry};
let context = TemporalContext::new(
CalendarRegistry::arithmetic(),
TimeZoneRegistry::empty(),
);
let date = context.parse_date("2026-11-17")?;
To use your own data, pass a CalendarRegistry and TimeZoneRegistry to
TemporalContext::new. The registries borrow the underlying tables and
transition records. Keep that storage alive for as long as values use it.
Time-zone records must be sorted by primary identifier, without duplicates.
Callers own data loading and decoding.
Missing tables return MissingCalendarData or MissingTimeZoneData.
Unknown zones return an error. For host-default lookup,
TimeZoneRegistry::system falls back to UTC when the name is missing or
unresolvable. Rust's Now takes a clock and time-zone provider from the
embedding application.
Calendar-unit totals validate both interpolation endpoints. Exact results and zero zoned totals can fail near date limits. Plain zero totals return zero.
JavaScript and Hermes#
The TypeScript polyfill exposes JavaScript Temporal. The native Hermes SDK delegates typed operations to Rust while JavaScript handles coercion, option order, and brands.
Verification#
The implementation guide links to current conformance tests and calendar authority ranges. See the Rust API reference for types and methods.