pub struct YearMonth { /* private fields */ }
Expand description
A month of a specific year.
Implementations
sourceimpl YearMonth
impl YearMonth
sourcepub const fn new_const(year: Year, month: Month) -> Self
pub const fn new_const(year: Year, month: Month) -> Self
Create a new year-month at compile time.
Unline, Self::new()
, this takes a Year
instead of an impl Into<Year>
,
since the conversion can not be done in a const fn
.
sourcepub const fn total_days(self) -> u8
pub const fn total_days(self) -> u8
Get the total number of days in the month.
This function accounts for leap-days, so it reports 29 days for February of leap-years, and 28 days for other years.
sourcepub const fn day_of_year(self) -> u16
pub const fn day_of_year(self) -> u16
Get the day-of-year on which the month starts.
Day-of-year numbers are 1-based.
sourcepub const fn next(self) -> Self
pub const fn next(self) -> Self
Get the next month as YearMonth
.
After December, this function returns January of the next year.
sourcepub const fn prev(self) -> Self
pub const fn prev(self) -> Self
Get the previous month as YearMonth
.
After January, this function returns December of the previous year.
sourcepub const fn add_years(self, years: i16) -> Self
pub const fn add_years(self, years: i16) -> Self
Get a new YearMonth
by adding a number of years.
sourcepub const fn sub_years(self, years: i16) -> Self
pub const fn sub_years(self, years: i16) -> Self
Get a new YearMonth
by subtracting a number of years.
sourcepub const fn add_months(self, months: i32) -> Self
pub const fn add_months(self, months: i32) -> Self
Get a new YearMonth
by adding a number of months.
sourcepub const fn sub_months(self, months: i32) -> Self
pub const fn sub_months(self, months: i32) -> Self
Get a new YearMonth
by subtracting a number of months.
sourcepub const fn with_day(self, day: u8) -> Result<Date, InvalidDayOfMonth>
pub const fn with_day(self, day: u8) -> Result<Date, InvalidDayOfMonth>
Combine the year and month with a day, to create a full Date
.
sourcepub const unsafe fn with_day_unchecked(self, day: u8) -> Date
pub const unsafe fn with_day_unchecked(self, day: u8) -> Date
Combine the year and month with a day, without checking for validity.
Safety
Although this is currently not the case, future implementations may rely on date validity for memory safety
Trait Implementations
sourceimpl Ord for YearMonth
impl Ord for YearMonth
1.21.0 · sourcefn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 · sourcefn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
1.50.0 · sourcefn clamp(self, min: Self, max: Self) -> Selfwhere
Self: Sized + PartialOrd<Self>,
fn clamp(self, min: Self, max: Self) -> Selfwhere
Self: Sized + PartialOrd<Self>,
sourceimpl PartialOrd<YearMonth> for YearMonth
impl PartialOrd<YearMonth> for YearMonth
sourcefn partial_cmp(&self, other: &YearMonth) -> Option<Ordering>
fn partial_cmp(&self, other: &YearMonth) -> Option<Ordering>
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more