pub trait Calendar: UnstableSealed {
type DateInner: Eq + Copy + PartialOrd + Debug;
type Year: Debug + Into<YearInfo>;
type DifferenceError;
Show 17 methods
// Required methods
fn from_codes(
&self,
era: Option<&str>,
year: i32,
month_code: MonthCode,
day: u8,
) -> Result<Self::DateInner, DateError>;
fn has_cheap_iso_conversion(&self) -> bool;
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 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;
// Provided methods
fn from_iso(&self, iso: IsoDateInner) -> Self::DateInner { ... }
fn to_iso(&self, date: &Self::DateInner) -> IsoDateInner { ... }
fn extended_year(&self, date: &Self::DateInner) -> i32 { ... }
}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ยง
Sourcetype DateInner: Eq + Copy + PartialOrd + Debug
type DateInner: Eq + Copy + PartialOrd + Debug
The internal type used to represent dates
Equality and ordering should observe normal calendar semantics.
Sourcetype DifferenceError
type DifferenceError
The type of error returned by until
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 the extended year if no era is provided
Sourcefn has_cheap_iso_conversion(&self) -> bool
fn has_cheap_iso_conversion(&self) -> bool
Whether from_iso/to_iso is more efficient
than from_rata_die/to_rata_die.
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 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
Provided Methodsยง
Sourcefn from_iso(&self, iso: IsoDateInner) -> Self::DateInner
fn from_iso(&self, iso: IsoDateInner) -> Self::DateInner
Construct the date from an ISO date.
Only called if HAS_CHEAP_ISO_CONVERSION is set.
Sourcefn to_iso(&self, date: &Self::DateInner) -> IsoDateInner
fn to_iso(&self, date: &Self::DateInner) -> IsoDateInner
Obtain an ISO date from this date.
Only called if HAS_CHEAP_ISO_CONVERSION is set.
Sourcefn extended_year(&self, date: &Self::DateInner) -> i32
fn extended_year(&self, date: &Self::DateInner) -> i32
The extended year.