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
| Name | Type | Description |
|---|---|---|
epoch_millis | Integer64 | Milliseconds 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
| Name | Type | Description |
|---|---|---|
millis | Integer64 | Milliseconds since 1970-01-01T00:00:00Z. |
Return type
fromEpochSeconds
- Stability:
stable
Construct an instant from whole seconds since the Unix epoch.
fromEpochSeconds(seconds: Integer64): Instant
Parameters
| Name | Type | Description |
|---|---|---|
seconds | Integer64 | Seconds since 1970-01-01T00:00:00Z. |
Return type
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
| Name | Type | Description |
|---|---|---|
input | String | Timestamp text to parse. |
pattern | String | strptime-style format string: literals plus % conversion specifiers (see types module docs). |
Return type
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
| Name | Type | Description |
|---|---|---|
other | Instant | Instant to compare against. |
Return type
isAfter
- Stability:
stable
Test whether this instant is strictly after another instant.
isAfter(other: Instant): Boolean
Parameters
| Name | Type | Description |
|---|---|---|
other | Instant | Instant to compare against. |
Return type
isBefore
- Stability:
stable
Test whether this instant is strictly before another instant.
isBefore(other: Instant): Boolean
Parameters
| Name | Type | Description |
|---|---|---|
other | Instant | Instant to compare against. |
Return type
minus
- Stability:
stable
Subtract a duration from this instant.
minus(duration: Duration): Instant
Parameters
| Name | Type | Description |
|---|---|---|
duration | Duration | Duration to subtract. |
Return type
plus
- Stability:
stable
Add a duration to this instant.
plus(duration: Duration): Instant
Parameters
| Name | Type | Description |
|---|---|---|
duration | Duration | Duration to add. |
Return type
toEpochMillis
- Stability:
stable
Return this instant as milliseconds since the Unix epoch.
toEpochMillis(): Integer64
Parameters
This function does not take any parameters.
Return type
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
toIsoString
- Stability:
stable
Format this instant as an ISO-8601 UTC timestamp.
toIsoString(): String
Parameters
This function does not take any parameters.