temporal

package
v0.33.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 24, 2026 License: MIT Imports: 15 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package temporal implements Temporal, the ECMAScript date and time API, for a beastjs.VM.

QuickJS has no Temporal. Register installs all of it: Temporal.Now, Instant, ZonedDateTime, PlainDate, PlainTime, PlainDateTime, PlainYearMonth, PlainMonthDay and Duration with every method V8 ships, the calendars of ECMA-402 and the IANA time zones, and Date.prototype.toTemporalInstant. The computing is go-intl's temporal package (internal/gointl/temporal), a Go port of temporal_rs, the library V8 builds Temporal on. The javascript half reads arguments, options and property bags in the order V8 reads them, with its conversions and its error messages, and keeps the internal slots of each object in a private field no page can reach.

Time and zones

Temporal.Now reads beastjs.VM.Now, including changes made with SetClock. A non-nil Clock overrides it for Temporal.Now only.

Temporal.Now.timeZoneId() is the VM's default time zone, the one package intl formats in (intl.TimeZone, "UTC" without it), which is ECMA-402's DefaultTimeZone, and the Now methods called without a zone use it too. The engine's Date does not follow it: its local time is UTC in every VM, so new Date().getHours() and Temporal.Now.plainTimeISO().hour differ when the default zone is not UTC.

The zone and calendar data is go-intl's, built into the binary: ICU's zoneinfo64 from ICU's time zone update for tz 2026e and ICU's calendar data, the 92 KB pack of it that Temporal reads. The host's zoneinfo is never read, so Temporal gives the same answers on every machine, a container without /usr/share/zoneinfo included. Temporal date formatting and named-zone validation read the same embedded zones, without needing host zoneinfo. ZonedDateTime.toLocaleString honors Temporal's offset even if the zone data used for formatting ever differs, naming that offset instead.

toLocaleString

Date types use the same type-specific formats as Intl.DateTimeFormat, from package intl, whether or not the VM has intl registered. Plain values ignore timeZone, an Instant uses the formatter's zone, and ZonedDateTime uses its own zone. DateTimeFormat itself rejects ZonedDateTime. Formatting supports all 18 calendars listed by Chromium. A mismatched calendar throws RangeError. ISO PlainYearMonth and PlainMonthDay need an explicit ISO calendar. Duration.toLocaleString uses Intl.DurationFormat. Both paths read private slots and captured built-ins, not properties a page can replace.

Cost

Register puts a stand-in for the global Temporal and for Date.prototype.toTemporalInstant on the VM. The rest is installed the first time a page reads Temporal or calls toTemporalInstant, from bytecode compiled once per process. The zone and calendar data is read once per process, the first time any VM needs it.

License of the data

The zone and calendar data is go-intl's, made from ICU's data and the IANA tz database, and the computing is go-intl's port of temporal_rs, of ICU4X's crates and of parts of V8. They are under the Unicode License V3 and the licenses of those projects. A program that imports this package distributes them, and has to include in its documentation or with its copies go-intl's LICENSE (internal/gointl/LICENSE) and the notices in internal/gointl/qjsdata: NOTICE-ICU, NOTICE-ICU4X, NOTICE-TEMPORAL and NOTICE-V8. It imports package intl, so intl's LICENSE-DATA as well. NOTICE.md, at the root of the module, says which notice covers what.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register

func Register(vm *beastjs.VM, opts ...Option) error

Register installs Temporal on vm's global object, and Date.prototype.toTemporalInstant. See the package documentation for what it is made of.

As with intl.Register: call it on every VM that is to have Temporal, before any code of the page runs, so that it takes the built-ins its code uses before a page can change them. Registering a second time on the same VM is an error. Nothing has to be released: vm.Close does it all.

Types

type Option

type Option func(*config)

An Option configures Register.

func Clock

func Clock(now func() time.Time) Option

Clock returns an Option setting the clock Temporal.Now reads, which is the VM clock without it. Prefer VM.SetClock to control Date and Intl too. A non-nil option takes precedence over VM.SetClock. now is called once per Temporal.Now call, and must be safe for concurrent use when VMs share it. A time outside Temporal.Instant's range, 1e8 days either side of 1970, makes Temporal.Now throw a RangeError.

now must not block: the VM waits for it, and an eval timeout (SetEvalTimeout) cannot cut it short, since the engine checks for one only between its own instructions. A panic in now reaches the caller of Eval, as a panic in any Go function the VM calls does, and the VM can be used again after it.

Clock drives Temporal.Now only. Date and Intl keep the VM clock. Clock(nil) uses the VM clock, including later SetClock changes.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL