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 Date in UTC. getTimezoneOffset() is always 0, and the local-time getters (getFullYear, getHours, …) are exact aliases of their getUTC* counterparts. The core runtime ships no timezone database, which keeps it small and WebAssembly-friendly. getTime, valueOf, the getUTC* family, and toISOString() are therefore fully deterministic on every machine.

Constructor

FormResult
new Date()The current moment (Date.now()).
new Date(ms)From epoch milliseconds.
new Date(isoString)Parses ISO-8601 (YYYY-MM-DD or YYYY-MM-DDTHH:MM:SS.sss with optional Z/±HH:MM).
new Date(year, month, day?, h?, m?, s?, ms?)From UTC components — month is 0-based (January = 0). Omitted fields default to 0 (or 1 for day).

Static methods

MethodDescription
Date.now()Current time in epoch milliseconds.
Date.parse(string)Epoch milliseconds for an ISO-8601 string, or NaN if unparseable.
Date.UTC(year, month, day?, h?, m?, s?, ms?)Epoch milliseconds for the given UTC components (month 0-based).

Instance methods

MethodDescription
getTime() / valueOf()Epoch milliseconds.
setTime(ms)Set the instant; returns ms.
toISOString() / toJSON()ISO-8601 string (…Z).
toString() / toUTCString() / toDateString() / toTimeString()Human-readable UTC renderings.
getUTCFullYear()getUTCMilliseconds()UTC calendar fields. getUTCMonth() is 0-based; getUTCDay() is 0 (Sun) … 6 (Sat).
getFullYear()getMilliseconds()Local-time fields — identical to the getUTC* family (Tish is UTC).
getTimezoneOffset()Always 0.

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() is 0 (see the note above). Code that needs the host timezone should run on the --target js backend.
  • 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 new Date from Date.UTC(...) instead.

Improve this documentation