@Serializable {
simple=true
collection=false
}
Duration represents a relative duration of time with nanosecond precision.
Also see docLang.
Slots
- absSource
-
Duration abs()
Absolute value - if this is a negative duration, then return its positive value.
- bootSource
-
static Duration boot()
Get the system timer at boot time of the Fantom VM.
- compareSource
-
Overrides sys::Obj.compare
Compare based on nanosecond ticks.
- defValSource
-
const static Duration defVal
Default value is 0ns.
- divSource
-
Divide this by b. Shortcut is a/b.
- equalsSource
-
override Bool equals(Obj? obj)
Overrides sys::Obj.equals
Return true if same number nanosecond ticks.
- floorSource
-
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. - fromIsoSource
-
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.
- Cannot specify a
- fromStrSource
-
static Duration? 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")
- hashSource
-
override Int hash()
Overrides sys::Obj.hash
Return ticks().
- makeSource
-
static Duration make(Int ticks)
Create a Duration which represents the specified number of nanosecond ticks.
- maxValSource
-
const static Duration maxVal
Max value is equivalent to
make(Int.maxVal)
. - minValSource
-
const static Duration minVal
Min value is equivalent to
make(Int.minVal)
. - minusSource
-
Subtract b from this. Shortcut is a-b.
- multSource
-
Multiply this with b. Shortcut is a*b.
- negateSource
-
Duration negate()
Negative of this. Shortcut is -a.
- nowSource
-
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.
- nowTicksSource
-
static Int nowTicks()
Convenience for
now.ticks
. - plusSource
-
Add this with b. Shortcut is a+b.
-
new privateMake()
Private constructor.
- ticksSource
-
Int ticks()
Return number of nanosecond ticks.
- toCodeSource
-
Str toCode()
Get this Duration as a Fantom code literal.
- toDaySource
-
Int toDay()
Get this duration in 24 hour days. Any fractional days are truncated with a loss of precision.
- toHourSource
-
Int toHour()
Get this duration in hours. Any fractional hours are truncated with a loss of precision.
- toIsoSource
-
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
- toLocaleSource
-
Str toLocale()
Return human friendly string representation. TODO: enhance this for pattern
- toMillisSource
-
Int toMillis()
Get this duration in milliseconds. Any fractional milliseconds are truncated with a loss of precision.
- toMinSource
-
Int toMin()
Get this duration in minutes. Any fractional minutes are truncated with a loss of precision.
- toSecSource
-
Int toSec()
Get this duration in seconds. Any fractional seconds are truncated with a loss of precision.
- toStrSource
-
override Str toStr()
Overrides sys::Obj.toStr
Return string representation of the duration which is a valid duration literal format suitable for decoding via fromStr.
- uptimeSource
-
static Duration uptime()
Get the duration which has elapsed since the Fantom VM was booted which is
now - boot
.