Struct date_time::time_tuple::TimeTuple
source · pub struct TimeTuple { /* private fields */ }
Expand description
A wrapper for a particular time of day.
Precise to second-level.
NOTE: This cannot be 24 hours or greater - see TimeTuple::new()
for more details.
The wrapping described in TimeTuple::new()
also applies when adding and subtracting times.
Implementations§
source§impl TimeTuple
impl TimeTuple
sourcepub fn new(h: i32, m: i32, s: i32) -> TimeTuple
pub fn new(h: i32, m: i32, s: i32) -> TimeTuple
Produces a new TimeTuple.
Times of 24 hours or greater and negative times will wrap around 24 hours to always produce a positive time.
The value is calculated from total number of seconds so a time 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) -> TimeTuple
pub fn from_seconds(total_seconds: u64) -> TimeTuple
Same as TimeTuple::new()
but takes the total number of seconds
as its argument and calculates the hours, minutes, and seconds
from that.
sourcepub fn now() -> TimeTuple
pub fn now() -> TimeTuple
Returns a TimeTuple
of the current time as std::time::SystemTime
provides it.
pub fn get_hours(&self) -> u8
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 08:30 for 8 hours and 30 minutes.
Ignores seconds.
sourcepub fn to_seconds(&self) -> u32
pub fn to_seconds(&self) -> u32
Gets the total number of seconds in the tuple.
sourcepub fn add_seconds(&mut self, seconds: i32)
pub fn add_seconds(&mut self, seconds: i32)
Adds a number of seconds to the TimeTuple,
wrapping the same way TimeTuple::new()
does.
sourcepub fn subtract_seconds(&mut self, seconds: i32)
pub fn subtract_seconds(&mut self, seconds: i32)
Subtracts a number of seconds from the TimeTuple,
wrapping the same way TimeTuple::new()
does.
sourcepub fn add_minutes(&mut self, minutes: i32)
pub fn add_minutes(&mut self, minutes: i32)
Adds a number of minutes to the TimeTuple,
wrapping the same way TimeTuple::new()
does.
sourcepub fn subtract_minutes(&mut self, minutes: i32)
pub fn subtract_minutes(&mut self, minutes: i32)
Subtracts a number of minutes from the TimeTuple,
wrapping the same way TimeTuple::new()
does.
sourcepub fn add_hours(&mut self, hours: i32)
pub fn add_hours(&mut self, hours: i32)
Adds a number of hours to the TimeTuple,
wrapping the same way TimeTuple::new()
does.
sourcepub fn subtract_hours(&mut self, hours: i32)
pub fn subtract_hours(&mut self, hours: i32)
Subtracts a number of hours from the TimeTuple,
wrapping the same way TimeTuple::new()
does.
Trait Implementations§
source§impl AddAssign<TimeTuple> for TimeTuple
impl AddAssign<TimeTuple> for TimeTuple
source§fn add_assign(&mut self, other: TimeTuple)
fn add_assign(&mut self, other: TimeTuple)
+=
operation. Read moresource§impl Ord for TimeTuple
impl Ord for TimeTuple
source§impl PartialOrd<TimeTuple> for TimeTuple
impl PartialOrd<TimeTuple> for TimeTuple
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl SubAssign<TimeTuple> for TimeTuple
impl SubAssign<TimeTuple> for TimeTuple
source§fn sub_assign(&mut self, other: TimeTuple)
fn sub_assign(&mut self, other: TimeTuple)
-=
operation. Read more