pub struct ExtendedTime { /* private fields */ }
Expand description
An hour+minute struct that can go up to 48h.
Implementations§
Source§impl ExtendedTime
impl ExtendedTime
Sourcepub const MIDNIGHT_00: Self
pub const MIDNIGHT_00: Self
00:00 (start of day)
Sourcepub const MIDNIGHT_24: Self
pub const MIDNIGHT_24: Self
24:00 (end of day)
Sourcepub const MIDNIGHT_48: Self
pub const MIDNIGHT_48: Self
48:00 (end of next day)
Sourcepub const fn new(hour: u8, minute: u8) -> Option<Self>
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
Sourcepub fn hour(self) -> u8
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);
Sourcepub fn minute(self) -> u8
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);
Sourcepub fn add_minutes(self, minutes: i16) -> Option<Self>
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());
Sourcepub fn add_hours(self, hours: i8) -> Option<Self>
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());
Sourcepub fn mins_from_midnight(self) -> u16
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);
Sourcepub fn from_mins_from_midnight(minute: u16) -> Option<Self>
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
impl Clone for ExtendedTime
Source§fn clone(&self) -> ExtendedTime
fn clone(&self) -> ExtendedTime
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for ExtendedTime
impl Debug for ExtendedTime
Source§impl Display for ExtendedTime
impl Display for ExtendedTime
Source§impl From<NaiveTime> for ExtendedTime
impl From<NaiveTime> for ExtendedTime
Source§fn from(time: NaiveTime) -> ExtendedTime
fn from(time: NaiveTime) -> ExtendedTime
Converts to this type from the input type.
Source§impl Hash for ExtendedTime
impl Hash for ExtendedTime
Source§impl Ord for ExtendedTime
impl Ord for ExtendedTime
Source§fn cmp(&self, other: &ExtendedTime) -> Ordering
fn cmp(&self, other: &ExtendedTime) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl PartialEq for ExtendedTime
impl PartialEq for ExtendedTime
Source§impl PartialOrd for ExtendedTime
impl PartialOrd for ExtendedTime
Source§impl TryInto<NaiveTime> for ExtendedTime
impl TryInto<NaiveTime> for ExtendedTime
impl Copy for ExtendedTime
impl Eq for ExtendedTime
impl StructuralPartialEq for ExtendedTime
Auto Trait Implementations§
impl Freeze for ExtendedTime
impl RefUnwindSafe for ExtendedTime
impl Send for ExtendedTime
impl Sync for ExtendedTime
impl Unpin for ExtendedTime
impl UnwindSafe for ExtendedTime
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more