Date
The Date constructor, instance methods, and statics in Tish.
Overview
Date represents a single moment in time as the number of milliseconds since the Unix epoch
(1970-01-01T00:00:00Z). The constructor and all instance methods work identically across every
Tish backend — the interpreter, the bytecode VM, and native (AOT) compiled binaries.
Tish runs
Datein UTC.getTimezoneOffset()is always0, and the local-time getters (getFullYear,getHours, …) are exact aliases of theirgetUTC*counterparts. The core runtime ships no timezone database, which keeps it small and WebAssembly-friendly.getTime,valueOf, thegetUTC*family, andtoISOString()are therefore fully deterministic on every machine.
Constructor
Static methods
Instance methods
Examples
let d = new Date(1623242096789)
d.toISOString() // "2021-06-09T12:34:56.789Z"
d.getUTCFullYear() // 2021
d.getUTCMonth() // 5 (June — 0-based)
d.getUTCDate() // 9
d.getUTCDay() // 3 (Wednesday)
Date.UTC(2021, 5, 9, 12, 34, 56, 789) // 1623242096789
Date.parse("2021-06-09T12:34:56.789Z") // 1623242096789
let t = new Date(0)
t.setTime(1000)
t.toISOString() // "1970-01-01T00:00:01.000Z"
// Leap day round-trips correctly.
new Date(Date.UTC(2020, 1, 29)).toISOString() // "2020-02-29T00:00:00.000Z"Compatibility notes
- UTC only. Local-time methods return UTC values and
getTimezoneOffset()is0(see the note above). Code that needs the host timezone should run on the--target jsbackend. new Date(year, month, …)is interpreted as UTC, whereas standard JavaScript interprets the multi-argument form in local time. With Tish's UTC model the two coincide.- Setters other than
setTime(e.g.setUTCHours) are not yet implemented; build a newDatefromDate.UTC(...)instead.