pub struct Date { /* private fields */ }Expand description
A calendar date. Construction validates it, so every Date exists.
Implementations§
Source§impl Date
impl Date
Sourcepub fn new(year: i32, month: u8, day: u8) -> Result<Self, InvalidDate>
pub fn new(year: i32, month: u8, day: u8) -> Result<Self, InvalidDate>
A date from its parts.
§Errors
Returns InvalidDate for a month outside 1–12 or a day the month lacks, or a year
outside 1–9999, which ISO strings cannot write in four digits.
Sourcepub fn parse(iso: &str) -> Result<Self, InvalidDate>
pub fn parse(iso: &str) -> Result<Self, InvalidDate>
Sourcepub fn from_days(days: i64) -> Option<Self>
pub fn from_days(days: i64) -> Option<Self>
The date days since 1970-01-01, or None outside years 1–9999.
Sourcepub fn add_days(self, delta: i64) -> Option<Self>
pub fn add_days(self, delta: i64) -> Option<Self>
The date delta days away, or None past the representable range.
Sourcepub fn add_months(self, delta: i32) -> Option<Self>
pub fn add_months(self, delta: i32) -> Option<Self>
The same day delta months away, clamped to that month’s length, as upstream’s
addMonths.
use fc_dioxus::behavior::date::Date;
let Ok(jan31) = Date::parse("2026-01-31") else { return };
assert_eq!(jan31.add_months(1).map(|d| d.to_string()), Some("2026-02-28".into()));
assert_eq!(jan31.add_months(-13).map(|d| d.to_string()), Some("2024-12-31".into()));Sourcepub fn first_of_month(self) -> Self
pub fn first_of_month(self) -> Self
The first of this date’s month.
Trait Implementations§
impl Copy for Date
impl Eq for Date
Source§impl Ord for Date
impl Ord for Date
1.21.0 (const: unstable) · 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
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the minimum of two values. Read more
Source§impl PartialOrd for Date
impl PartialOrd for Date
impl StructuralPartialEq for Date
Auto Trait Implementations§
impl Freeze for Date
impl RefUnwindSafe for Date
impl Send for Date
impl Sync for Date
impl Unpin for Date
impl UnsafeUnpin for Date
impl UnwindSafe for Date
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DependencyElement for T
Source§impl<T> InitializeFromFunction<T> for T
impl<T> InitializeFromFunction<T> for T
Source§fn initialize_from_function(f: fn() -> T) -> T
fn initialize_from_function(f: fn() -> T) -> T
Create an instance of this type from an initialization function
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<Ret> SpawnIfAsync<(), Ret> for Ret
impl<Ret> SpawnIfAsync<(), Ret> for Ret
Source§impl<T, O> SuperFrom<T> for Owhere
O: From<T>,
impl<T, O> SuperFrom<T> for Owhere
O: From<T>,
Source§fn super_from(input: T) -> O
fn super_from(input: T) -> O
Convert from a type to another type.
Source§impl<T, O, M> SuperInto<O, M> for Twhere
O: SuperFrom<T, M>,
impl<T, O, M> SuperInto<O, M> for Twhere
O: SuperFrom<T, M>,
Source§fn super_into(self) -> O
fn super_into(self) -> O
Convert from a type to another type.