pub struct Watch {
pub start: i64,
pub offset: i64,
pub meridiem: bool,
}Expand description
A struct that represents a watch which keeps track of the start time, offset, and meridiem.
Can be addded and subtracted with i64 and &str. i64 will be treated as seconds and &str will be
treated as a time string (e.g. “01:23:45”). The default display format is HH:MM:SS and +/- days.
§Note on i64
Using i64 to represent time in seconds has a maximum time span of several hundred billion years. This is more than enough for most use cases. There is a few microseconds added to computation time and doubling of memory usage compared to using i32. However, the tradeoff is worth it in my opinion as i32 has a max of around 68 years.
Fields§
§start: i64the starting time of the watch. This won’t change over the course of the program
offset: i64the offset of the watch or the time span that will be added to the start time
meridiem: boolwhether the watch is in 12h or 24h format (true for 12h)
Implementations§
Source§impl Watch
impl Watch
Sourcepub fn new(time: &str, meridiem: bool) -> Self
pub fn new(time: &str, meridiem: bool) -> Self
create a new watch with the given time and meridiem option
Sourcepub fn str_to_secs(time: &str, is_time_span: bool) -> i64
pub fn str_to_secs(time: &str, is_time_span: bool) -> i64
take a time string (e.g. “01:23:45 AM”) and return the number of seconds
Sourcepub fn secs_to_mil(secs: i64) -> String
pub fn secs_to_mil(secs: i64) -> String
convert secs to string (HH:MM:SS format)
Sourcepub fn secs_to_mer(secs: i64) -> String
pub fn secs_to_mer(secs: i64) -> String
convert secs to string (12h format)
Sourcepub fn diff_to_days(diff: i64) -> String
pub fn diff_to_days(diff: i64) -> String
convert diff seconds to num of days later or before
Sourcepub fn add_offset(&self) -> i64
pub fn add_offset(&self) -> i64
return the end time of the watch
Sourcepub fn change_meridiem(&mut self, meridiem: bool)
pub fn change_meridiem(&mut self, meridiem: bool)
change the meridiem option
Trait Implementations§
Source§impl<T: AddableToWatch + Copy> AddAssign<T> for Watch
impl<T: AddableToWatch + Copy> AddAssign<T> for Watch
Source§fn add_assign(&mut self, other: T)
fn add_assign(&mut self, other: T)
+= operation. Read moreSource§impl<T: AddableToWatch + Copy> SubAssign<T> for Watch
impl<T: AddableToWatch + Copy> SubAssign<T> for Watch
Source§fn sub_assign(&mut self, other: T)
fn sub_assign(&mut self, other: T)
-= operation. Read more