Struct ExtendedTime

Source
pub struct ExtendedTime { /* private fields */ }
Expand description

An hour+minute struct that can go up to 48h.

Implementations§

Source§

impl ExtendedTime

Source

pub const MIDNIGHT_00: Self

00:00 (start of day)

Source

pub const MIDNIGHT_24: Self

24:00 (end of day)

Source

pub const MIDNIGHT_48: Self

48:00 (end of next day)

Source

pub const fn new(hour: u8, minute: u8) -> Option<Self>

Create a new extended time, this may return None if input values are out of range.

use opening_hours_syntax::ExtendedTime;

assert!(ExtendedTime::new(28, 30).is_some());
assert!(ExtendedTime::new(72, 15).is_none()); // hours are out of bound
assert!(ExtendedTime::new(24, 60).is_none()); // minutes are out of bound
Source

pub fn hour(self) -> u8

Get the number of full hours in this extended time.

use opening_hours_syntax::ExtendedTime;

let time = ExtendedTime::new(27, 35).unwrap();
assert_eq!(time.hour(), 27);
Source

pub fn minute(self) -> u8

Get the number of remaining minutes in this extended time.

use opening_hours_syntax::ExtendedTime;

let time = ExtendedTime::new(27, 35).unwrap();
assert_eq!(time.minute(), 35);
Source

pub fn add_minutes(self, minutes: i16) -> Option<Self>

Add plain minutes to the extended time and return None if this results in it being out of bounds.

use opening_hours_syntax::ExtendedTime;

let time = ExtendedTime::new(24, 0).unwrap();
assert_eq!(time.add_minutes(75), ExtendedTime::new(25, 15));
assert!(time.add_minutes(24 * 60 + 1).is_none());
assert!(time.add_minutes(-24 * 60 - 1).is_none());
Source

pub fn add_hours(self, hours: i8) -> Option<Self>

Add plain hours to the extended time and return None if this results in it being out of bounds.

use opening_hours_syntax::ExtendedTime;

let time = ExtendedTime::new(24, 15).unwrap();
assert_eq!(time.add_hours(3), ExtendedTime::new(27, 15));
assert!(time.add_hours(25).is_none());
assert!(time.add_hours(-25).is_none());
Source

pub fn mins_from_midnight(self) -> u16

Get the total number of minutes from 00:00.

use opening_hours_syntax::ExtendedTime;

let time = ExtendedTime::new(25, 15).unwrap();
assert_eq!(time.mins_from_midnight(), 25 * 60 + 15);
Source

pub fn from_mins_from_midnight(minute: u16) -> Option<Self>

Build an extended time from the total number of minutes from midnight and return None if the result is out of bounds.

use opening_hours_syntax::ExtendedTime;

assert_eq!(
    ExtendedTime::from_mins_from_midnight(26 * 60 + 15),
    ExtendedTime::new(26, 15),
);

assert!(ExtendedTime::from_mins_from_midnight(65_000).is_none());

Trait Implementations§

Source§

impl Clone for ExtendedTime

Source§

fn clone(&self) -> ExtendedTime

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 ExtendedTime

Source§

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

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

impl Display for ExtendedTime

Source§

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

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

impl From<NaiveTime> for ExtendedTime

Source§

fn from(time: NaiveTime) -> ExtendedTime

Converts to this type from the input type.
Source§

impl Hash for ExtendedTime

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for ExtendedTime

Source§

fn cmp(&self, other: &ExtendedTime) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for ExtendedTime

Source§

fn eq(&self, other: &ExtendedTime) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for ExtendedTime

Source§

fn partial_cmp(&self, other: &ExtendedTime) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl TryInto<NaiveTime> for ExtendedTime

Source§

type Error = ()

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

fn try_into(self) -> Result<NaiveTime, Self::Error>

Performs the conversion.
Source§

impl Copy for ExtendedTime

Source§

impl Eq for ExtendedTime

Source§

impl StructuralPartialEq for ExtendedTime

Auto Trait Implementations§

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.
Source§

impl<T> RuleType for T
where T: Copy + Debug + Eq + Hash + Ord,