struct Duration
pub struct Duration :: [
Equatable,
Ordered,
TotalOrder,
Hashable,
Default,
Display,
Parse,
Add,
Sub,
Mul<int>,
Div<int>
]
Conforms to Equatable, Ordered, TotalOrder, Hashable, Default, Display, Parse, Add, Sub, Mul<int>, Div<int>.
A span of time in whole nanoseconds, negative or not: some 292 years either way.
Panics
Arithmetic that leaves that range panics with an overflow (RT0002), as int's does.
Methods
pub static fn ofNanos(n: int): Duration
pub static fn ofMicros(n: int): Duration
pub static fn ofMillis(n: int): Duration
pub static fn ofSecs(n: int): Duration
pub static fn ofMinutes(n: int): Duration
pub static fn ofHours(n: int): Duration
pub fn nanos(): int
Returns the span in nanoseconds.
pub fn millis(): int
Returns the span in whole milliseconds, rounded toward zero.
pub fn secs(): int
Returns the span in whole seconds, rounded toward zero.
pub fn asSecsFloat(): float
Returns the span in seconds, with their fraction.
pub fn add(rhs: Duration): Duration
pub fn sub(rhs: Duration): Duration
pub fn mul(rhs: int): Duration
pub fn div(rhs: int): Duration
Divides the span by rhs, rounded toward zero.
Panics
Panics on a division by zero (RT0001).
pub fn show(): string
Returns the span as text: 0s; under a second one unit — ns, µs, ms — with the
fraction, its trailing zeros dropped (1.5µs, 500ms); from a second on hours, minutes and
seconds with their fraction, the larger ones from the first that is not zero (1.5s,
1m30s, 1h0m0s); a minus in front of a negative one.
pub static fn parse(s: StringView): Duration throws ParseError
Parses a span: an optional sign, then one or more numbers each with its unit — ns,
us (or µs, μs), ms, s, m, h —, a number with a fraction allowed: 1h30m,
1.5h, -300ms. 0 alone is zero. A fraction is scaled to its unit through a float: the
nanoseconds of 1.5h are exact, those of a long fraction of an hour may be rounded.
Errors
Throws ParseError with kind Empty for an empty text, Invalid for a number without
digits or a missing or unknown unit, and Overflow where the span does not fit.