Watch

Struct Watch 

Source
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: i64

the starting time of the watch. This won’t change over the course of the program

§offset: i64

the offset of the watch or the time span that will be added to the start time

§meridiem: bool

whether the watch is in 12h or 24h format (true for 12h)

Implementations§

Source§

impl Watch

Source

pub fn new(time: &str, meridiem: bool) -> Self

create a new watch with the given time and meridiem option

Source

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

Source

pub fn secs_to_mil(secs: i64) -> String

convert secs to string (HH:MM:SS format)

Source

pub fn secs_to_mer(secs: i64) -> String

convert secs to string (12h format)

Source

pub fn diff_to_days(diff: i64) -> String

convert diff seconds to num of days later or before

Source

pub fn add_offset(&self) -> i64

return the end time of the watch

Source

pub fn change_meridiem(&mut self, meridiem: bool)

change the meridiem option

Trait Implementations§

Source§

impl Add<&str> for Watch

Source§

type Output = Watch

The resulting type after applying the + operator.
Source§

fn add(self, rhs: &str) -> Self::Output

Performs the + operation. Read more
Source§

impl Add<i64> for Watch

Source§

type Output = Watch

The resulting type after applying the + operator.
Source§

fn add(self, rhs: i64) -> Self::Output

Performs the + operation. Read more
Source§

impl<T: AddableToWatch + Copy> AddAssign<T> for Watch
where Watch: Add<T, Output = Watch>,

Source§

fn add_assign(&mut self, other: T)

Performs the += operation. Read more
Source§

impl Clone for Watch

Source§

fn clone(&self) -> Watch

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Watch

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Watch

Source§

fn default() -> Watch

Returns the “default value” for a type. Read more
Source§

impl Display for Watch

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Sub<&str> for Watch

Source§

type Output = Watch

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: &str) -> Self::Output

Performs the - operation. Read more
Source§

impl Sub<i64> for Watch

Source§

type Output = Watch

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: i64) -> Self::Output

Performs the - operation. Read more
Source§

impl<T: AddableToWatch + Copy> SubAssign<T> for Watch
where Watch: Sub<T, Output = Watch>,

Source§

fn sub_assign(&mut self, other: T)

Performs the -= operation. Read more
Source§

impl Copy for Watch

Auto Trait Implementations§

§

impl Freeze for Watch

§

impl RefUnwindSafe for Watch

§

impl Send for Watch

§

impl Sync for Watch

§

impl Unpin for Watch

§

impl UnwindSafe for Watch

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.