Skip to main content

TimeOfDay

Struct TimeOfDay 

Source
pub struct TimeOfDay {
    pub hour: i32,
    pub minute: i32,
}
Expand description

A value representing a time during the day, independent of the date that day might fall on or the time zone.

The time is represented by hour and minute pair. Once created, both values cannot be changed.

You can create TimeOfDay using the constructor which requires both hour and minute or using DateTime object. Hours are specified between 0 and 23, as in a 24-hour clock.

let release_time = TimeOfDay::new(15, 0); // 3:00pm
let booking = DateTime::new_with_time(&app, 2018, 10, 20, 16, 30, 4, 0, 0);
let room_booked = TimeOfDay::from_date_time(&app, &booking); // 4:30pm

See also:

  • showTimePicker, which returns this type.
  • MaterialLocalizations, which provides methods for formatting values of this type according to the chosen Locale.
  • DateTime, which represents date and time, and is subject to eras and time zones.

Fields§

§hour: i32

The selected hour, in 24 hour time from 0..23.

§minute: i32

The selected minute.

Implementations§

Source§

impl TimeOfDay

Source

pub const HOURS_PER_DAY: i32 = 24

The number of hours in one day, i.e. 24.

Source

pub const HOURS_PER_PERIOD: i32 = 12

The number of hours in one day period (see also DayPeriod), i.e. 12.

Source

pub const MINUTES_PER_HOUR: i32 = 60

The number of minutes in one hour, i.e. 60.

Source

pub const fn new(hour: i32, minute: i32) -> TimeOfDay

Creates a time of day.

The hour argument must be between 0 and 23, inclusive. The minute argument must be between 0 and 59, inclusive.

Source

pub fn now(app: &App) -> TimeOfDay

Creates a time of day based on the current time, in the local time zone.

Source

pub fn from_date_time(app: &App, time: &DateTime) -> TimeOfDay

Creates a time of day based on the given time.

The hour is set to the time’s hour and the minute is set to the time’s minute in the timezone of the given DateTime.

Source

pub fn replacing(&self, hour: Option<i32>, minute: Option<i32>) -> TimeOfDay

Returns a new TimeOfDay with the hour and/or minute replaced.

Source

pub fn period(&self) -> DayPeriod

Whether this time of day is before or after noon.

Source

pub fn hour_of_period(&self) -> i32

Which hour of the current period (e.g., am or pm) this time is.

For 12AM (midnight) and 12PM (noon) this returns 12.

Source

pub fn period_offset(&self) -> i32

The hour at which the current period starts.

Source

pub fn format(&self, app: &mut App, context: BuildContext) -> String

Returns the localized string representation of this time of day.

This is a shortcut for MaterialLocalizations::format_time_of_day.

Source

pub fn is_before(&self, other: &TimeOfDay) -> bool

Whether this TimeOfDay occurs earlier than other.

Does not account for day or sub-minute differences. This means that “00:00” of the next day is still before “23:00” of this day.

Source

pub fn is_after(&self, other: &TimeOfDay) -> bool

Whether this TimeOfDay occurs later than other.

Does not account for day or sub-minute differences. This means that “00:00” of the next day is still before “23:00” of this day.

Source

pub fn is_at_same_time_as(&self, other: &TimeOfDay) -> bool

Whether this TimeOfDay occurs at the same time as other.

Does not account for day or sub-minute differences. This means that “00:00” of the next day is still before “23:00” of this day.

Source

pub fn compare_to(&self, other: &TimeOfDay) -> Ordering

Compares this TimeOfDay object to other independent of date.

Does not account for day or sub-minute differences. This means that “00:00” of the next day is still before “23:00” of this day.

A compare_to function returns:

Trait Implementations§

Source§

impl Clone for TimeOfDay

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for TimeOfDay

Source§

impl Debug for TimeOfDay

Source§

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

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

impl Eq for TimeOfDay

Source§

impl Hash for TimeOfDay

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 TimeOfDay

Dart’s implements Comparable<TimeOfDay>: the order of TimeOfDay::compare_to.

Source§

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

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

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

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

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

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

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

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

fn clamp_to<R>(self, range: R) -> Self
where Self: Sized, R: ClampBounds<Self>,

🔬This is a nightly-only experimental API. (clamp_to)
Restrict a value to a certain range. Read more
Source§

impl PartialEq for TimeOfDay

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialOrd for TimeOfDay

Source§

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

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · 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 (const: unstable) · 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 (const: unstable) · 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 (const: unstable) · 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 StructuralPartialEq for TimeOfDay

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> AnyEq for T
where T: PartialEq + Hash + Debug + 'static,

Source§

fn eq_any(&self, other: &(dyn AnyEq + 'static)) -> bool

Dart’s operator ==. Must return false when other is a different concrete type, even if the two carry the same value.
Source§

fn hash_any(&self, state: &mut dyn Hasher)

Dart’s hashCode. Must mix in the concrete type so that two types carrying the same value do not collide.
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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> SlotValue for T
where T: Clone + Eq + Hash + Debug + 'static,

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,