Duration
struct Duration
A duration of time.
Durations are the primitive type for the measurement of time.
A duration can be negative, when the difference is from a later to an earlier instant.
Examples
let d = 5.seconds();
assert_eq d.seconds(), 5.0;
operator-:2
pub fn operator-:2(self, b: Duration): Duration
Return a - b as Duration object.
operator-:2
pub fn operator-:2(self, b: Duration): Duration
Return a - b as Duration object.
Return a - b as Duration object.
let d = 5.seconds();
d - 5.seconds(); // 0 seconds
let d = 1.5.hours() - 30.minutes();
assert_eq d.hours(), 1.0;
assert_eq d.minutes(), 60.0;
operator+:2
pub fn operator+:2(self, b: Duration): Duration
Return a + b as Duration object.
operator+:2
pub fn operator+:2(self, b: Duration): Duration
Return a + b as Duration object.
Return a + b as Duration object.
let d = 5.seconds();
d + 5.seconds(); // 10 seconds
let d = 1.5.hours() + 30.minutes();
assert_eq d.hours(), 2.0;
assert_eq d.minutes(), 120.0;
operator>=:2
pub fn operator>=:2(self, b: Duration): bool
operator>=:2
pub fn operator>=:2(self, b: Duration): bool
operator>:2
pub fn operator>:2(self, b: Duration): bool
operator>:2
pub fn operator>:2(self, b: Duration): bool
operator<=:2
pub fn operator<=:2(self, b: Duration): bool
operator<=:2
pub fn operator<=:2(self, b: Duration): bool
operator<:2
pub fn operator<:2(self, b: Duration): bool
operator<:2
pub fn operator<:2(self, b: Duration): bool
operator!=:2
pub fn operator!=:2(self, b: Duration): bool
operator!=:2
pub fn operator!=:2(self, b: Duration): bool
operator==:2
pub fn operator==:2(self, b: Duration): bool
operator==:2
pub fn operator==:2(self, b: Duration): bool
nanoseconds
pub fn nanoseconds(self): int
Return int nanoseconds (ns) of Duration object.
nanoseconds
pub fn nanoseconds(self): int
Return int nanoseconds (ns) of Duration object.
Return int nanoseconds (ns) of Duration object.
let d = 5.5.seconds();
assert_eq d.nanoseconds(), 5500000000;
microseconds
pub fn microseconds(self): int
Return int microseconds (us) of Duration object.
microseconds
pub fn microseconds(self): int
Return int microseconds (us) of Duration object.
Return int microseconds (us) of Duration object.
let d = 5.5.seconds();
assert_eq d.microseconds(), 5500000;
milliseconds
pub fn milliseconds(self): int
Return int milliseconds (ms) of Duration object.
milliseconds
pub fn milliseconds(self): int
Return int milliseconds (ms) of Duration object.
Return int milliseconds (ms) of Duration object.
let d = 5.5.seconds();
assert_eq d.seconds(), 5.5;
assert_eq d.milliseconds(), 5500;
Return float seconds (s) of Duration object.
Return float seconds (s) of Duration object.
Return float seconds (s) of Duration object.
let d = 5.seconds();
assert_eq d.seconds(), 5.0;
assert_eq d.milliseconds(), 5000;
assert_eq d.microseconds(), 5000000;
assert_eq d.nanoseconds(), 5000000000;
Return float minutes (m) of Duration object.
Return float minutes (m) of Duration object.
Return float minutes (m) of Duration object.
let d = 5.minutes();
assert_eq d.minutes(), 5.0;
assert_eq d.seconds(), 300.0;
Return float hours (h) of Duration object.
Return float hours (h) of Duration object.
Return float hours (h) of Duration object.
let d = 5.hours();
assert_eq d.hours(), 5.0;
assert_eq d.minutes(), 300.0;
Return float days (d) of Duration object.
Return float days (d) of Duration object.
Return float days (d) of Duration object.
let d = 2.5.days();
assert_eq d.days(), 2.5;
assert_eq d.hours(), 60.0;
Return string of Duration object.
Return string of Duration object.
Return string of Duration object.
If the value >= 1s, then return in seconds (s). If the value >= 1ms, then return in milliseconds (ms). If the value >= 1µs, then return in microseconds (µs).
let d = 15.5.minutes();
assert_eq d.to_string(), "930s";
let d = 2.35.seconds();
assert_eq d.to_string(), "2.35s";
let d = 0.25.seconds();
assert_eq d.to_string(), "250ms";
let d = 0.25.milliseconds();
assert_eq d.to_string(), "250µs";
let d = 0.25.microseconds();
assert_eq d.to_string(), "250ns";
from_seconds
pub fn from_seconds(n: float): Duration
Return Duration of float seconds (s).
from_seconds
pub fn from_seconds(n: float): Duration
Return Duration of float seconds (s).
Return Duration of float seconds (s).