pub struct Duration { /* private fields */ }
Expand description
A wrapper for a duration.
Does not count in days, but can have hours >24 (up to u32::MAX
)
Precise to second-level.
Cannot be negative.
Implementations§
Source§impl Duration
impl Duration
Sourcepub fn new(h: u32, m: u32, s: u32) -> Duration
pub fn new(h: u32, m: u32, s: u32) -> Duration
Produces a new Duration.
The value is calculated from total number of seconds so a duration with a minute value of 90 would add an hour to the resulting tuple and set the minutes to 30, for example.
Sourcepub fn from_seconds(total_seconds: u64) -> Duration
pub fn from_seconds(total_seconds: u64) -> Duration
Same as Duration::new()
but takes the total number of seconds
as its argument and calculates the hours, minutes, and seconds
from that.
Sourcepub fn between(dt1: DateTimeTuple, dt2: DateTimeTuple) -> Duration
pub fn between(dt1: DateTimeTuple, dt2: DateTimeTuple) -> Duration
Calculates the Duration
between two DateTimeTuple
s.
pub fn get_hours(self) -> u32
pub fn get_minutes(self) -> u8
pub fn get_seconds(self) -> u8
Sourcepub fn to_hhmm_string(self) -> String
pub fn to_hhmm_string(self) -> String
Produces a string such as 8:30 for 8 hours and 30 minutes.
Hours field will expand as necessary; 150:30 is a possible result.
Ignores seconds.
Sourcepub fn to_hours_and_minutes_string(self) -> String
👎Deprecated since 2.1.0: Replace with to_hhmm_string()
pub fn to_hours_and_minutes_string(self) -> String
Produces a string such as 8:30 for 8 hours and 30 minutes.
Hours field will expand as necessary; 150:30 is a possible result.
Ignores seconds.
Sourcepub fn to_seconds(self) -> u64
pub fn to_seconds(self) -> u64
Gets the total number of seconds in the Duration.
Sourcepub fn to_minutes(self) -> u32
pub fn to_minutes(self) -> u32
Gets the total number of minutes in the Duration, ignoring seconds.
Sourcepub fn add_seconds(&mut self, seconds: u32)
pub fn add_seconds(&mut self, seconds: u32)
Adds a number of seconds to the Duration,
wrapping the same way Duration::new()
does.
Sourcepub fn subtract_seconds(&mut self, seconds: u32)
pub fn subtract_seconds(&mut self, seconds: u32)
Subtracts a number of seconds from the Duration,
wrapping the same way Duration::new()
does.
Sourcepub fn add_minutes(&mut self, minutes: u32)
pub fn add_minutes(&mut self, minutes: u32)
Adds a number of minutes to the Duration,
wrapping the same way Duration::new()
does.
Sourcepub fn subtract_minutes(&mut self, minutes: u32)
pub fn subtract_minutes(&mut self, minutes: u32)
Subtracts a number of minutes from the Duration,
wrapping the same way Duration::new()
does.
Sourcepub fn add_hours(&mut self, hours: u32)
pub fn add_hours(&mut self, hours: u32)
Adds a number of hours to the Duration,
wrapping the same way Duration::new()
does.
Sourcepub fn subtract_hours(&mut self, hours: u32)
pub fn subtract_hours(&mut self, hours: u32)
Subtracts a number of hours from the Duration,
wrapping the same way Duration::new()
does.
Trait Implementations§
Source§impl AddAssign for Duration
impl AddAssign for Duration
Source§fn add_assign(&mut self, other: Duration)
fn add_assign(&mut self, other: Duration)
+=
operation. Read moreSource§impl Ord for Duration
impl Ord for Duration
Source§impl PartialOrd for Duration
impl PartialOrd for Duration
Source§impl SubAssign for Duration
impl SubAssign for Duration
Source§fn sub_assign(&mut self, other: Duration)
fn sub_assign(&mut self, other: Duration)
-=
operation. Read more