Duration

A Duration represents a span of time, stored as a signed 128-bit integer in nanoseconds. By default its value is 0.

let nothing be new Duration

It may be instantiated using units of time.

let hour_and_half be new Duration with hours as 1, and minutes as 30

Below are all of the available constructor parameters.

new Duration with
  weeks as 0,
  days as 0,
  hours as 0,
  minutes as 0,
  seconds as 0,
  milliseconds as 0,
  microseconds as 0, and
  nanoseconds as 0

The following are equivalent.

let hour_and_half_a be new Duration with hours as 1, and minutes as 30
let hour_and_half_b be new Duration with just hours as 1.5

Operators

The Instant and Duration classes overload many operators for convenience. See the list below for details.

Instant  [= != > < >= <=] Instant  → Boolean
Duration [= != > < >= <=] Duration → Boolean
Instant  [+-] Duration → Instant
Instant  [-]  Instant  → Duration
Duration [+-] Duration → Duration
Duration [*/] Float    → Duration
Duration [*/] Integer  → Duration
Duration [/]  Duration → Float
Duration [%]  Duration → Duration
[-]Duration → Duration

Methods

Returns a formatted string representing the duration.

let a be new Duration with just seconds as 10_000_000
print do a's to_string
# 16 weeks, 3 days, 17 hours, 46 minutes, and 40 seconds

Returns the total amount of nanoseconds as a number in JSON format.

Returns a string representing the duration, with the given formatting.

let a be new Duration with just seconds as -10_000_000
print a's formatted "[sign][hours]:[minutes:02]:[seconds:02]"
# -17:46:40

Use :# to pad with # spaces, and :0# to pad with # zeros.

"[days]"    -> "3"
"[days:2]"  -> " 3"
"[days:03]" -> "003"

Prefix with total_ to grab the total amount instead.

let a be new Duration with just seconds as 10_000_000
print a's formatted "[sign][total_hours]h [minutes:02]m [seconds:02]s"
# 2777h 46m 40s

Getters

Returns the amount of weeks in this duration.

Returns the amount of days in this duration.

Returns the amount of hours in this duration.

Returns the amount of minutes in this duration.

Returns the amount of seconds in this duration.

Returns the amount of milliseconds in this duration.

Returns the amount of microseconds in this duration.

Returns the amount of nanoseconds in this duration.

Returns the total amount of weeks in this duration.

Returns the total amount of days in this duration.

Returns the total amount of hours in this duration.

Returns the total amount of minutes in this duration.

Returns the total amount of seconds in this duration.

Returns the total amount of milliseconds in this duration.

Returns the total amount of microseconds in this duration.

Returns the total amount of nanoseconds in this duration.

print "hello world"