Skip to main content

MaterialDate

Struct MaterialDate 

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

A whole calendar day: year, month (1..=12), day (1..=days_in_month).

Named MaterialDate rather than a bare Date because this crate flat re-exports every widget/spec type at its root (frust_material::MaterialDate), where a bare Date would collide with any other catalog or app type of the same name — the same reason crate::MaterialTokens/crate::MaterialMotion carry the prefix.

Ordering is chronological (Ord over (year, month, day), which is equivalent to ordering by Self::epoch_day because every field is normalized on construction), so first_date <= day && day <= last_date is the bounds test the whole family uses.

Implementations§

Source§

impl MaterialDate

Source

pub fn new(year: i32, month: u32, day: u32) -> Self

The nearest real date to (year, month, day): the year clamped to MIN_YEAR..=MAX_YEAR, the month to 1..=12, the day to that month’s own length. See the module docs’ clamping note.

use frust_material::MaterialDate;

// 31 February resolves to the 29th in a leap year, the 28th otherwise.
assert_eq!(MaterialDate::new(2024, 2, 31), MaterialDate::new(2024, 2, 29));
assert_eq!(MaterialDate::new(2023, 2, 31), MaterialDate::new(2023, 2, 28));
Source

pub fn year(self) -> i32

This date’s year.

Source

pub fn month(self) -> u32

This date’s month, 1..=12.

Source

pub fn day(self) -> u32

This date’s day of the month, 1..=days_in_month.

Source

pub fn first_of_month(self) -> Self

The first of this date’s own month — the reference’s M3EDatePickerUtils.getMonth(date.year, date.month), which is how every “displayed month” value in this family is normalized.

Source

pub fn epoch_day(self) -> i64

Days since 1970-01-01 (negative before it) — Howard Hinnant’s days_from_civil. The one primitive Self::weekday_index and Self::days_until are derived from.

use frust_material::MaterialDate;

assert_eq!(MaterialDate::new(1970, 1, 1).epoch_day(), 0);
assert_eq!(MaterialDate::new(1969, 12, 31).epoch_day(), -1);
Source

pub fn days_until(self, other: Self) -> i64

Signed day count from self to other (other - self).

Source

pub fn weekday_index(self) -> u32

This date’s weekday as a Sunday-first index: 0 Sunday through 6 Saturday.

The reference reads Dart’s DateTime.weekday (Monday-first, 1..=7) and folds it with % 7 (M3ECalendarLabels.firstWeekday); this returns the folded value directly, since every consumer here — the grid’s leading-blank count and the weekday header row — wants the Sunday-first one.

use frust_material::MaterialDate;

// 2000-01-01 was a Saturday; 2026-08-20 a Thursday.
assert_eq!(MaterialDate::new(2000, 1, 1).weekday_index(), 6);
assert_eq!(MaterialDate::new(2026, 8, 20).weekday_index(), 4);
Source

pub fn days_in_this_month(self) -> u32

How many days this date’s own month has.

Source

pub fn add_months(self, delta: i32) -> Self

This date shifted by delta whole months, keeping the day of the month where the target month is long enough and shortening it where it is not — the reference’s addMonthsToMonthDate + normalizeSelectedDay pair.

use frust_material::MaterialDate;

let jan31 = MaterialDate::new(2026, 1, 31);
assert_eq!(jan31.add_months(1), MaterialDate::new(2026, 2, 28));
assert_eq!(jan31.add_months(-1), MaterialDate::new(2025, 12, 31));
Source

pub fn month_delta(self, other: Self) -> i32

Whole months from self’s month to other’s — the reference’s monthDelta. Day-of-month is ignored on both sides.

Source

pub fn clamp_to(self, first: Self, last: Self) -> Self

self clamped into first..=last (the reference’s clampDate). A reversed pair (last < first) collapses onto first, so a caller that hands the bounds in the wrong order gets a defined date rather than a panic.

Source

pub fn is_within(self, first: Self, last: Self) -> bool

Whether self lies within first..=last, inclusive — the reference’s isSelectable bounds half (its optional predicate is applied by the widget, which owns the caller-supplied closure).

Source

pub fn format_compact(self) -> String

This date in the compact, parseable mm/dd/yyyy form — Flutter’s MaterialLocalizations.formatCompactDate for en_US, which is the format the reference’s input mode both renders and parses.

See crate::DatePickerStrings for why this port ships one fixed English/US format rather than a locale-resolved one.

use frust_material::MaterialDate;

assert_eq!(MaterialDate::new(2026, 8, 20).format_compact(), "08/20/2026");
Source

pub fn parse_compact(text: &str) -> Option<Self>

Parse the compact mm/dd/yyyy form back into a date, or None if the text is not exactly that — Flutter’s parseCompactDate for en_US, which is what drives the input mode’s format error.

Rejects (rather than clamping — see the module docs): a part count other than three, any non-ASCII-digit character, an empty part, a month outside 1..=12, a day outside the month’s own length, and a year outside MIN_YEAR..=MAX_YEAR. Surrounding whitespace is trimmed first, so a paste with a trailing newline still parses.

use frust_material::MaterialDate;

assert_eq!(MaterialDate::parse_compact("08/20/2026"), Some(MaterialDate::new(2026, 8, 20)));
assert_eq!(MaterialDate::parse_compact("8/2/2026"), Some(MaterialDate::new(2026, 8, 2)));
assert_eq!(MaterialDate::parse_compact("02/30/2026"), None);
assert_eq!(MaterialDate::parse_compact("2026-08-20"), None);

Trait Implementations§

Source§

impl Clone for MaterialDate

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 MaterialDate

Source§

impl Debug for MaterialDate

Source§

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

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

impl Eq for MaterialDate

Source§

impl Hash for MaterialDate

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 MaterialDate

Source§

fn cmp(&self, other: &Self) -> 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 MaterialDate

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 MaterialDate

Source§

fn partial_cmp(&self, other: &Self) -> 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 MaterialDate

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<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 for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync> ⓘ

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

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

Source§

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

Checks if this value is equivalent to the given key. Read more
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> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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, S> SimdFrom<T, S> for T
where S: Simd,

Source§

fn simd_from(_simd: S, value: T) -> T

Source§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

Source§

fn simd_into(self, simd: S) -> T

Source§

impl<T> StorageAccess<T> for T

Source§

fn as_borrowed(&self) -> &T

Borrows the value.
Source§

fn into_taken(self) -> T

Takes the value.
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> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

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

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more