Skip to content

time ​

luau
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 ​

EntryDescription
DurationA time duration with nanosecond precision. Supports arithmetic via +, -, *, /, and comparison operators.
InstantA point in time with nanosecond precision. Can be subtracted from another Instant to produce a Duration.
duration.createCreates a Duration from seconds and a fractional subsecnanos nanosecond component.
duration.daysCreates a Duration from a number of days.
duration.hoursCreates a Duration from a number of hours.
duration.microsecondsCreates a Duration from a number of microseconds.
duration.millisecondsCreates a Duration from a number of milliseconds.
duration.minutesCreates a Duration from a number of minutes.
duration.nanosecondsCreates a Duration from a number of nanoseconds.
duration.secondsCreates a Duration from a number of seconds.
duration.weeksCreates a Duration from a number of weeks.
nowReturns the current time as an Instant.
sinceReturns the number of seconds elapsed since instant.

Types ​

Duration ​

A time duration with nanosecond precision. Supports arithmetic via +, -, *, /, and comparison operators.

luau
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.

luau
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.

luau
(seconds: number, subsecnanos: number) -> Duration

time.duration.days ​

Creates a Duration from a number of days.

luau
(days: number) -> Duration

time.duration.hours ​

Creates a Duration from a number of hours.

luau
(hours: number) -> Duration

time.duration.microseconds ​

Creates a Duration from a number of microseconds.

luau
(microseconds: number) -> Duration

time.duration.milliseconds ​

Creates a Duration from a number of milliseconds.

luau
(milliseconds: number) -> Duration

time.duration.minutes ​

Creates a Duration from a number of minutes.

luau
(minutes: number) -> Duration

time.duration.nanoseconds ​

Creates a Duration from a number of nanoseconds.

luau
(nanoseconds: number) -> Duration

time.duration.seconds ​

Creates a Duration from a number of seconds.

luau
(seconds: number) -> Duration

time.duration.weeks ​

Creates a Duration from a number of weeks.

luau
(weeks: number) -> Duration

time.now ​

Returns the current time as an Instant.

luau
() -> Instant

time.since ​

Returns the number of seconds elapsed since instant.

luau
(instant: Instant) -> number