pub trait Calendar: UnstableSealed {
type DateInner: Eq + Copy + Debug;
type Year: Debug + Into<YearInfo>;
Show 16 methods
// Required methods
fn from_codes(
&self,
era: Option<&str>,
year: i32,
month_code: MonthCode,
day: u8,
) -> Result<Self::DateInner, DateError>;
fn from_iso(&self, iso: IsoDateInner) -> Self::DateInner;
fn to_iso(&self, date: &Self::DateInner) -> IsoDateInner;
fn from_rata_die(&self, rd: RataDie) -> Self::DateInner;
fn to_rata_die(&self, date: &Self::DateInner) -> RataDie;
fn months_in_year(&self, date: &Self::DateInner) -> u8;
fn days_in_year(&self, date: &Self::DateInner) -> u16;
fn days_in_month(&self, date: &Self::DateInner) -> u8;
fn is_in_leap_year(&self, date: &Self::DateInner) -> bool;
fn year_info(&self, date: &Self::DateInner) -> Self::Year;
fn extended_year(&self, date: &Self::DateInner) -> i32;
fn month(&self, date: &Self::DateInner) -> MonthInfo;
fn day_of_month(&self, date: &Self::DateInner) -> DayOfMonth;
fn day_of_year(&self, date: &Self::DateInner) -> DayOfYear;
fn calendar_algorithm(&self) -> Option<CalendarAlgorithm>;
fn debug_name(&self) -> &'static str;
}
Expand description
A calendar implementation
Only implementors of Calendar
should care about these methods, in general users of
these calendars should use the methods on Date
instead.
Individual Calendar
implementations may have inherent utility methods
allowing for direct construction, etc.
It is still possible to implement this trait in userland (since UnstableSealed
is public),
do not do so unless you are prepared for things to occasionally break.
Required Associated Typesยง
Required Methodsยง
Sourcefn from_codes(
&self,
era: Option<&str>,
year: i32,
month_code: MonthCode,
day: u8,
) -> Result<Self::DateInner, DateError>
fn from_codes( &self, era: Option<&str>, year: i32, month_code: MonthCode, day: u8, ) -> Result<Self::DateInner, DateError>
Construct a date from era/month codes and fields
The year is extended_year if no era is provided
Sourcefn from_rata_die(&self, rd: RataDie) -> Self::DateInner
fn from_rata_die(&self, rd: RataDie) -> Self::DateInner
Construct the date from a RataDie
Sourcefn to_rata_die(&self, date: &Self::DateInner) -> RataDie
fn to_rata_die(&self, date: &Self::DateInner) -> RataDie
Obtain a RataDie
from this date
Sourcefn months_in_year(&self, date: &Self::DateInner) -> u8
fn months_in_year(&self, date: &Self::DateInner) -> u8
Count the number of months in a given year, specified by providing a date from that year
Sourcefn days_in_year(&self, date: &Self::DateInner) -> u16
fn days_in_year(&self, date: &Self::DateInner) -> u16
Count the number of days in a given year, specified by providing a date from that year
Sourcefn days_in_month(&self, date: &Self::DateInner) -> u8
fn days_in_month(&self, date: &Self::DateInner) -> u8
Count the number of days in a given month, specified by providing a date from that year/month
Sourcefn is_in_leap_year(&self, date: &Self::DateInner) -> bool
fn is_in_leap_year(&self, date: &Self::DateInner) -> bool
Calculate if a date is in a leap year
Sourcefn extended_year(&self, date: &Self::DateInner) -> i32
fn extended_year(&self, date: &Self::DateInner) -> i32
The extended year value
Sourcefn month(&self, date: &Self::DateInner) -> MonthInfo
fn month(&self, date: &Self::DateInner) -> MonthInfo
The calendar-specific month represented by date
Sourcefn day_of_month(&self, date: &Self::DateInner) -> DayOfMonth
fn day_of_month(&self, date: &Self::DateInner) -> DayOfMonth
The calendar-specific day-of-month represented by date
Sourcefn day_of_year(&self, date: &Self::DateInner) -> DayOfYear
fn day_of_year(&self, date: &Self::DateInner) -> DayOfYear
Information of the day of the year
Sourcefn calendar_algorithm(&self) -> Option<CalendarAlgorithm>
fn calendar_algorithm(&self) -> Option<CalendarAlgorithm>
Returns the CalendarAlgorithm
that is required to match
when parsing into this calendar.
If left empty, any algorithm will parse successfully.
Sourcefn debug_name(&self) -> &'static str
fn debug_name(&self) -> &'static str
Obtain a name for the calendar for debug printing
Dyn Compatibilityยง
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.