Skip to main content

Instant

  • Stability: stable
  • Since: 0.1.0

Represents an absolute timestamp independent of local calendar rules or time zones. Use Instant for ordering events, computing elapsed time, and storing machine time.

  • Qualified id: com.dataspine.datetime.Instant@1
  • Kind: struct

Examples

Build from epoch milliseconds

let occurredAt = com.dataspine.datetime.Instant.fromEpochMillis(0)

Properties

NameTypeDescription
epoch_millisInteger64Milliseconds since 1970-01-01T00:00:00Z.

Static methods

fromEpochMillis

  • Stability: stable

Construct an instant from milliseconds since the Unix epoch.

fromEpochMillis(millis: Integer64): Instant

Parameters

NameTypeDescription
millisInteger64Milliseconds since 1970-01-01T00:00:00Z.

Return type

Instant

fromEpochSeconds

  • Stability: stable

Construct an instant from whole seconds since the Unix epoch.

fromEpochSeconds(seconds: Integer64): Instant

Parameters

NameTypeDescription
secondsInteger64Seconds since 1970-01-01T00:00:00Z.

Return type

Instant

parsePattern

  • Stability: stable

Matches input against pattern using POSIX-style % directives (see module types overview). The parsed fields must fix a unique UTC instant; include Z or a numeric offset in the pattern (for example %z, %:z, or a literal Z) when the text alone does not determine the offset.

parsePattern(input: String, pattern: String): Instant

Parameters

NameTypeDescription
inputStringTimestamp text to parse.
patternStringstrptime-style format string: literals plus % conversion specifiers (see types module docs).

Return type

Instant

Examples

Parse a timestamp
let parsed = com.dataspine.datetime.Instant.parsePattern("2026-04-25T12:00:00Z", "%Y-%m-%dT%H:%M:%SZ")

Methods

durationUntil

  • Stability: stable

Compute the elapsed duration from this instant until another instant.

durationUntil(other: Instant): Duration

Parameters

NameTypeDescription
otherInstantInstant to compare against.

Return type

Duration

isAfter

  • Stability: stable

Test whether this instant is strictly after another instant.

isAfter(other: Instant): Boolean

Parameters

NameTypeDescription
otherInstantInstant to compare against.

Return type

Boolean

isBefore

  • Stability: stable

Test whether this instant is strictly before another instant.

isBefore(other: Instant): Boolean

Parameters

NameTypeDescription
otherInstantInstant to compare against.

Return type

Boolean

minus

  • Stability: stable

Subtract a duration from this instant.

minus(duration: Duration): Instant

Parameters

NameTypeDescription
durationDurationDuration to subtract.

Return type

Instant

plus

  • Stability: stable

Add a duration to this instant.

plus(duration: Duration): Instant

Parameters

NameTypeDescription
durationDurationDuration to add.

Return type

Instant

toEpochMillis

  • Stability: stable

Return this instant as milliseconds since the Unix epoch.

toEpochMillis(): Integer64

Parameters

This function does not take any parameters.

Return type

Integer64

toEpochSeconds

  • Stability: stable

Return this instant as whole seconds since the Unix epoch.

toEpochSeconds(): Integer64

Parameters

This function does not take any parameters.

Return type

Integer64

toIsoString

  • Stability: stable

Format this instant as an ISO-8601 UTC timestamp.

toIsoString(): String

Parameters

This function does not take any parameters.

Return type

String

Back to Datetime