struct const class std::Duration

sys::Obj
  std::Duration

@Serializable { simple=true }

Duration represents a relative duration of time with nanosecond precision.

Also see docLang.

abs

Duration abs()

Absolute value - if this is a negative duration, then return its positive value.

compare

virtual override Int compare(Obj obj)

Compare based on nanosecond ticks.

defVal

const static Duration defVal := zero

Default value is 0ns.

div

@Operator
Duration div(Int b)

Divide this by b. Shortcut is a/b.

divFloat

@Operator
Duration divFloat(Float b)

Divide this by b. Shortcut is a/b.

equals

virtual override Bool equals(Obj? obj)

Return true if same number nanosecond ticks.

floor

Duration floor(Duration accuracy)

Return a new Duration with this duration's nanosecond ticks truncated according to the specified accuracy. For example floor(1min) will truncate this duration such that its seconds are 0.0.

fromDay

static new fromDay(Int s)

fromHour

static new fromHour(Int s)

fromIso

static Duration fromIso(Str s, Bool checked := true)

Parse a duration according to ISO 8601. If invalid format and checked is false return null, otherwise throw ParseErr. The following restrictions are enforced:

  • Cannot specify a Y year or M month component since it is ambiguous
  • Only the S seconds component may include a fraction
  • Only nanosecond resolution is supported See toIso for example formats.
fromMicros

static new fromMicros(Int s)

fromMillis

static new fromMillis(Int s)

fromMin

static new fromMin(Int s)

fromNanos

static new fromNanos(Int nanao)

fromSec

static new fromSec(Int s)

fromStr

static new fromStr(Str s, Bool checked := true)

Parse a Str into a Duration according to the Fantom 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

virtual override Int hash()

Return ticks().

max

Duration max(Duration that)

Return the maximum duration between this and that.

maxVal

const static Duration maxVal := ...

Max value is equivalent to make(Int.maxVal/nsPerMilli).

micrsPerDay

const static Int micrsPerDay := 86400000000

micrsPerHr

const static Int micrsPerHr := 3600000000

micrsPerMilli

const static Int micrsPerMilli := 1000

micrsPerMin

const static Int micrsPerMin := 60000000

micrsPerSec

const static Int micrsPerSec := 1000000

milliPerDay

const static Int milliPerDay := 86400000

milliPerHr

const static Int milliPerHr := 3600000

milliPerMin

const static Int milliPerMin := 60000

milliPerSec

const static Int milliPerSec := 1000

min

Duration min(Duration that)

Return the minimum duration between this and that.

minVal

const static Duration minVal := ...

Min value is equivalent to make(Int.minVal/nsPerMilli).

minus

@Operator
Duration minus(Duration b)

Subtract b from this. Shortcut is a-b.

mult

@Operator
Duration mult(Int b)

Multiply this with b. Shortcut is a*b.

multFloat

@Operator
Duration multFloat(Float b)

Multiply this with b. Shortcut is a*b.

negate

@Operator
Duration negate()

Negative of this. Shortcut is -a.

now

@Deprecated
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.

nowTicks

@Deprecated
static Int nowTicks()

nsPerDay

const static Int nsPerDay := 86400000000000

nsPerHr

const static Int nsPerHr := 3600000000000

nsPerMilli

const static Int nsPerMilli := 1000000

nsPerMin

const static Int nsPerMin := 60000000000

nsPerSec

const static Int nsPerSec := 1000000000

plus

@Operator
Duration plus(Duration b)

Add this with b. Shortcut is a+b.

secPerDay

const static Int secPerDay := 86400

secPerHr

const static Int secPerHr := 3600

secPerMin

const static Int secPerMin := 60

toCode

Str toCode()

Get this Duration as a Fantom code literal.

toDay

Int toDay()

Get this duration in 24 hour days. Any fractional days are truncated with a loss of precision.

toHour

Int toHour()

Get this duration in hours. Any fractional hours are truncated with a loss of precision.

toIso

Str toIso()

Format this duration according to ISO 8601. Also see fromIso.

Examples:

8ns.toIso             =>  PT0.000000008S
100ms.toIso           =>  PT0.1S
(-20sec).toIso        =>  -PT20S
3.5min.toIso          =>  PT3M30S
1day.toIso            =>  PT24H
(1day+2hr+3min).toIso =>  P1DT2H3M
toLocale

Str toLocale()

Return human friendly string representation. TODO: enhance this for pattern

toMicros

Int toMicros()

Return number of microsecond ticks.

toMillis

Int toMillis()

Get this duration in milliseconds. Any fractional milliseconds are truncated with a loss of precision.

toMin

Int toMin()

Get this duration in minutes. Any fractional minutes are truncated with a loss of precision.

toNanos

Int toNanos()

Return number of nanosecond ticks.

toSec

Int toSec()

Get this duration in seconds. Any fractional seconds are truncated with a loss of precision.

toStr

virtual override Str toStr()

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