type
Duration
@Serializable { simple=true }
const class Duration : Obj
Duration represents a relative duration of time with nanosecond precision.
Also see docLang.
constructors
fromStr |
Parse a Str into a Duration according to the Fantom literal format. |
---|---|
make |
Create a Duration which represents the specified number of nanosecond ticks. |
fields
defVal |
Default value is 0ns. |
---|---|
maxVal |
Max value is equivalent to |
minVal |
Min value is equivalent to |
methods
abs |
Absolute value - if this is a negative duration, then return its positive value. |
---|---|
boot |
Get the system timer at boot time of the Fantom VM. |
clamp |
Clamp this duration between the min and max. |
compare |
Compare based on nanosecond ticks. |
div |
Divide this by b. |
divFloat |
Divide this by b. |
equals |
Return true if same number nanosecond ticks. |
floor |
Return a new Duration with this duration's nanosecond ticks truncated according to the specified accuracy. |
fromIso |
Parse a duration according to ISO 8601. |
hash |
Return ticks(). |
max |
Return the maximum duration between this and that. |
min |
Return the minimum duration between this and that. |
minus |
Subtract b from this. |
mult |
Multiply this with b. |
multFloat |
Multiply this with b. |
negate |
Negative of this. |
now |
Get the current value of the system timer. |
nowTicks |
Convenience for |
plus |
Add this with b. |
ticks |
Return number of nanosecond ticks. |
toCode |
Get this Duration as a Fantom code literal. |
toDay |
Get this duration in 24 hour days. |
toHour |
Get this duration in hours. |
toIso |
Format this duration according to ISO 8601. |
toLocale |
Return human friendly string representation. |
toMillis |
Get this duration in milliseconds. |
toMin |
Get this duration in minutes. |
toSec |
Get this duration in seconds. |
toStr |
Return string representation of the duration which is a valid duration literal format suitable for decoding via |
uptime |
Get the duration which has elapsed since the Fantom VM was booted which is |
Slot Details
abs
Duration abs()
Absolute value - if this is a negative duration, then return its positive value.
boot
static Duration boot()
Get the system timer at boot time of the Fantom VM.
clamp
compare
defVal
const static Duration defVal
Default value is 0ns.
div
divFloat
equals
floor
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 orM
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.
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().
make
static new make(Int ticks)
Create a Duration which represents the specified number of nanosecond ticks.
max
maxVal
const static Duration maxVal
Max value is equivalent to make(Int.maxVal)
.
min
minVal
const static Duration minVal
Min value is equivalent to make(Int.minVal)
.
minus
mult
multFloat
negate
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.
nowTicks
static Int nowTicks()
Convenience for now.ticks
.
plus
ticks
Int ticks()
Return number of nanosecond ticks.
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
toLocale
Str toLocale()
Return human friendly string representation. TODO: enhance this for pattern
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.
toSec
Int toSec()
Get this duration in seconds. Any fractional seconds are truncated with a loss of precision.
toStr
uptime
static Duration uptime()
Get the duration which has elapsed since the Fantom VM was booted which is now - boot
.