logo

const class

sys::Duration

sys::Obj
  sys::Duration

Duration represents a relative duration of time with nanosecond precision.

Slots

compare

override Int compare(Obj obj)

Compare based on nanosecond ticks.

equals

override Bool equals(Obj obj)

Return true if same number nanosecond ticks.

fromStr

static Duration fromStr(Str s, Bool checked := def)

Parse a Str into a Duration according to the Fan literal format. If invalid format and checked is false return null, otherwise throw ParseErr. The following suffixes are supported:

ns:   nanoseconds  (x 1)
ms:   milliseconds (x 1,000,000)
sec:  seconds      (x 1,000,000,000)
min:  minutes      (x 60,000,000,000)
hr:   hours        (x 3,600,000,000,000)
day:  days         (x 86,400,000,000,000)

Examples:

Duration.fromStr("4ns")
Duration.fromStr("100ms")
Duration.fromStr("-0.5hr")
hash

override Int hash()

Return ticks().

make

static Duration make(Int ticks)

Create a Duration which represents the specified number of nanosecond ticks.

minus

Duration minus(Duration b)

Subtract b from this. Shortcut is a-b.

negate

Duration negate()

Negative of this. Shortcut is -a.

now

static Duration now()

Get the current value of the system timer. This method returns a relative time unrelated to system or wall-clock time. Typically it is the number of nanosecond ticks which have elapsed since system startup.

plus

Duration plus(Duration b)

Add this with b. Shortcut is a+b.

slash

Duration slash(Float b)

Divide this by b. Shortcut is a/b.

star

Duration star(Float b)

Multiply this with b. Shortcut is a*b.

ticks

Int ticks()

Return number of nanosecond ticks.

toMillis

Int toMillis()

Get this duration in milliseconds (there may be a loss of precision).

toStr

override Str toStr()

Return string representation of the duration which is a valid duration literal format suitable for decoding via fromStr.