← index

Timestamp

inherits Object

An absolute instant in time: UTC wall-clock, nanosecond precision.

The serializable counterpart to the monotonic Instant — parse and print it as RFC 3339, convert to and from Unix epoch counts, shift it with a Duration, or subtract two to get the Duration between them. A Timestamp has no time zone; view it in one with inZone: / utc, which answer a zone-aware DateTime.

(Timestamp.parse:'2024-01-01T00:00:00Z').asUnixSeconds       "* -> 1704067200
((Timestamp.parse:'2024-01-01T00:00:00Z') + (Duration.hours:6)).s
"* -> 2024-01-01T06:00:00Z
extended at core/16-serialize.qn:23

The absolute instant, as its RFC 3339 string (Timestamp.parse: reads it back).

Class methods

fromUnixMilliseconds:Integer

The Timestamp for a count of whole milliseconds since the Unix epoch (may be negative). The inverse of asUnixMilliseconds.

(Timestamp.fromUnixMilliseconds:1704067200500).s     "* -> 2024-01-01T00:00:00.5Z

native

fromUnixSeconds:Integer

The Timestamp for a count of whole seconds since the Unix epoch (may be negative). The inverse of asUnixSeconds.

(Timestamp.fromUnixSeconds:0).s              "* -> 1970-01-01T00:00:00Z
(Timestamp.fromUnixSeconds:1704067200).s     "* -> 2024-01-01T00:00:00Z

native

now

The current absolute instant, from the system wall clock. For measuring elapsed time prefer Instant.now (monotonic, immune to clock adjustments).

native

parse:String

Parse an RFC 3339 timestamp string (throws a ValueError on anything else). The inverse of s.

(Timestamp.parse:'2024-01-01T00:00:00Z').s     "* -> 2024-01-01T00:00:00Z

native

Instance methods

+:Duration

The Timestamp shifted later by a Duration (earlier, if it is negative). Leaving the representable range (roughly ±9999 years) throws an ArithmeticError.

((Timestamp.parse:'2024-01-01T00:00:00Z') + (Duration.hours:6)).s
"* -> 2024-01-01T06:00:00Z

native

-:Duration
-:Timestamp

With a Duration argument: the Timestamp shifted earlier by that much.

((Timestamp.parse:'2024-01-01T00:00:00Z') - (Duration.hours:6)).s
"* -> 2023-12-31T18:00:00Z

native

<:Timestamp

Whether the receiver is the earlier instant. Only <: is native; >: / <=: / >=: derive from it on Object.

native

==:

Whether the argument is a Timestamp naming the same instant. A non-Timestamp argument is simply unequal — never an error.

native

asData

core/16-serialize.qn:24

asUnixMilliseconds

Whole milliseconds since the Unix epoch (Integer, truncated toward zero).

(Timestamp.parse:'2024-01-01T00:00:00Z').asUnixMilliseconds     "* -> 1704067200000

native

asUnixSeconds

Whole seconds since the Unix epoch (Integer, truncated toward zero).

(Timestamp.parse:'2024-01-01T00:00:00Z').asUnixSeconds     "* -> 1704067200

native

inZone:TimeZone

This instant viewed in a time zone, as a zone-aware DateTime (same instant, local components).

((Timestamp.parse:'2024-01-01T00:00:00Z').inZone:(TimeZone.of:'America/New_York')).s
"* -> 2023-12-31T19:00:00-05:00[America/New_York]

native

s

The RFC 3339 string (always UTC, with the Z suffix). Round-trips through Timestamp.parse:.

(Timestamp.fromUnixSeconds:1704067200).s     "* -> 2024-01-01T00:00:00Z

native

utc

This instant as a DateTime in UTC — shorthand for inZone:TimeZone.utc.

(Timestamp.parse:'2024-07-01T12:00:00Z').utc.s     "* -> 2024-07-01T12:00:00+00:00[UTC]

native