Struct duration_breakdown::DurationBreakdown [−][src]
pub struct DurationBreakdown { /* fields omitted */ }Expand description
A DurationBreakdown represents a duration of time that has been
broken up into several units (i.e. weeks, days, etc) in such a way
that the sum of each unit comprises the whole duration of time.
Implementations
Constructs a DurationBreakdown directly from the given component parts.
Examples
let breakdown = DurationBreakdown::from_parts( 4, // weeks 2, // days 17, // hours 41, // minutes 18, // seconds 100, // nanoseconds ); assert_eq!(breakdown.weeks(), 4); assert_eq!(breakdown.days(), 2); assert_eq!(breakdown.hours(), 17); assert_eq!(breakdown.minutes(), 41); assert_eq!(breakdown.seconds(), 18); assert_eq!(breakdown.nanoseconds(), 100);
Converts a DurationBreakdown into a standard form in which the value
of a given time component (week, day, etc) is no greater than the value
of a single unit of the time component one level up. For instance,
a DurationBreakdown with 68 as its minutes value and 3 as its
hours value would be normalized to 8 minutes and 4 hours.
Examples
// 9 days, 1 hour, 50 minutes, 70 seconds (not normalized) let mut breakdown = DurationBreakdown::from_parts(0, 9, 1, 50, 70, 0); breakdown.normalize(); assert_eq!( breakdown.as_string(), "1 week, 2 days, 1 hour, 51 minutes, 10 seconds, and 0 nanoseconds");
Gets the number of nanoseconds in the breakdown.
A string describing the number of weeks in the breakdown. E.g. "14 weeks".
A string describing the number of days in the breakdown. E.g. "6 days".
A string describing the number of hours in the breakdown. E.g. "1 hour".
A string describing the number of minutes in the breakdown. E.g. "53 minutes".
A string describing the number of seconds in the breakdown. E.g. "40 seconds".
A string describing the number of nanoseconds in the breakdown. E.g. "1700 nanoseconds".
A string describing the entire DurationBreakdown. All components
are included, even if their value is 0. See as_string_hide_zeros
for an alternate display of the breakdown.
Note that this function is used by the implementation of Display for
DurationBreakdown.
Examples
let breakdown = DurationBreakdown::from_parts(0, 4, 0, 10, 48, 200); assert_eq!( breakdown.as_string(), "0 weeks, 4 days, 0 hours, 10 minutes, 48 seconds, and 200 nanoseconds");
A string describing the entire DurationBreakdown, but any components
that have a value of 0 are omitted from the description. See
as_string for a version of this function that includes 0-valued
components.
Examples
let breakdown = DurationBreakdown::from_parts(0, 4, 0, 10, 48, 200); assert_eq!( breakdown.as_string_hide_zeros(), "4 days, 10 minutes, 48 seconds, and 200 nanoseconds");
Trait Implementations
Constructs a new std::time::Duration, given a DurationBreakdown.
Panics
This will panic if the DurationBreakdown’s nanoseconds value is
greater than u32::MAX.
This method tests for self and other values to be equal, and is used
by ==. Read more
This method tests for !=.
Auto Trait Implementations
impl RefUnwindSafe for DurationBreakdownimpl Send for DurationBreakdownimpl Sync for DurationBreakdownimpl Unpin for DurationBreakdownimpl UnwindSafe for DurationBreakdown