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
impl MaterialDate
Sourcepub fn new(year: i32, month: u32, day: u32) -> Self
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));Sourcepub fn day(self) -> u32
pub fn day(self) -> u32
This date’s day of the month, 1..=days_in_month.
Sourcepub fn first_of_month(self) -> Self
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.
Sourcepub fn epoch_day(self) -> i64
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);Sourcepub fn days_until(self, other: Self) -> i64
pub fn days_until(self, other: Self) -> i64
Signed day count from self to other (other - self).
Sourcepub fn weekday_index(self) -> u32
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);Sourcepub fn days_in_this_month(self) -> u32
pub fn days_in_this_month(self) -> u32
How many days this date’s own month has.
Sourcepub fn add_months(self, delta: i32) -> Self
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));Sourcepub fn month_delta(self, other: Self) -> i32
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.
Sourcepub fn clamp_to(self, first: Self, last: Self) -> Self
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.
Sourcepub fn is_within(self, first: Self, last: Self) -> bool
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).
Sourcepub fn format_compact(self) -> String
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");Sourcepub fn parse_compact(text: &str) -> Option<Self>
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
impl Clone for MaterialDate
impl Copy for MaterialDate
Source§impl Debug for MaterialDate
impl Debug for MaterialDate
impl Eq for MaterialDate
Source§impl Hash for MaterialDate
impl Hash for MaterialDate
Source§impl Ord for MaterialDate
impl Ord for MaterialDate
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for MaterialDate
impl PartialEq for MaterialDate
Source§impl PartialOrd for MaterialDate
impl PartialOrd for MaterialDate
impl StructuralPartialEq for MaterialDate
Auto Trait Implementations§
impl Freeze for MaterialDate
impl RefUnwindSafe for MaterialDate
impl Send for MaterialDate
impl Sync for MaterialDate
impl Unpin for MaterialDate
impl UnsafeUnpin for MaterialDate
impl UnwindSafe for MaterialDate
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&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
impl<T> DowncastSync for T
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.