time
local time = require("@lute/time")WARNING
These APIs are still open to future evolution. In new major versions, they may change in backwards incompatible ways.
Summary
| Entry | Description |
|---|---|
| Duration | A time duration with nanosecond precision. Supports arithmetic via +, -, *, /, and comparison operators. |
| Instant | A point in time with nanosecond precision. Can be subtracted from another Instant to produce a Duration. |
| duration.create | Creates a Duration from seconds and a fractional subsecnanos nanosecond component. |
| duration.days | Creates a Duration from a number of days. |
| duration.hours | Creates a Duration from a number of hours. |
| duration.microseconds | Creates a Duration from a number of microseconds. |
| duration.milliseconds | Creates a Duration from a number of milliseconds. |
| duration.minutes | Creates a Duration from a number of minutes. |
| duration.nanoseconds | Creates a Duration from a number of nanoseconds. |
| duration.seconds | Creates a Duration from a number of seconds. |
| duration.weeks | Creates a Duration from a number of weeks. |
| now | Returns the current time as an Instant. |
| since | Returns the number of seconds elapsed since instant. |
Types
Duration
A time duration with nanosecond precision. Supports arithmetic via +, -, *, /, and comparison operators.
type Duration = setmetatable<Frozen, {
read __metatable: "The metatable is locked!",
read __index: typeof(table.freeze(duration_ops)),
read __add: (Duration, Duration) -> Duration,
read __sub: (Duration, Duration) -> Duration,
read __mul: (Duration, number) -> Duration,
read __div: (Duration, number) -> Duration,
read __eq: (Duration, Duration) -> boolean,
read __lt: (Duration, Duration) -> boolean,
read __le: (Duration, Duration) -> boolean,
}>Instant
A point in time with nanosecond precision. Can be subtracted from another Instant to produce a Duration.
type Instant = setmetatable<Frozen, {
read __metatable: "The metatable is locked!",
read __index: typeof(table.freeze(instant)),
read __sub: (Instant, Instant) -> Duration,
read __eq: (Instant, Instant) -> boolean,
read __lt: (Instant, Instant) -> boolean,
read __le: (Instant, Instant) -> boolean,
}>Functions and Properties
time.duration.create
Creates a Duration from seconds and a fractional subsecnanos nanosecond component.
(seconds: number, subsecnanos: number) -> Durationtime.duration.days
Creates a Duration from a number of days.
(days: number) -> Durationtime.duration.hours
Creates a Duration from a number of hours.
(hours: number) -> Durationtime.duration.microseconds
Creates a Duration from a number of microseconds.
(microseconds: number) -> Durationtime.duration.milliseconds
Creates a Duration from a number of milliseconds.
(milliseconds: number) -> Durationtime.duration.minutes
Creates a Duration from a number of minutes.
(minutes: number) -> Durationtime.duration.nanoseconds
Creates a Duration from a number of nanoseconds.
(nanoseconds: number) -> Durationtime.duration.seconds
Creates a Duration from a number of seconds.
(seconds: number) -> Durationtime.duration.weeks
Creates a Duration from a number of weeks.
(weeks: number) -> Durationtime.now
Returns the current time as an Instant.
() -> Instanttime.since
Returns the number of seconds elapsed since instant.
(instant: Instant) -> number