Skip to main content

DateFieldsResolver

Trait DateFieldsResolver 

Source
pub(crate) trait DateFieldsResolver: Calendar {
    type YearInfo: Copy + Debug + PartialEq + ToExtendedYear;

    // Required methods
    fn days_in_provided_month(year: Self::YearInfo, month: u8) -> u8;
    fn months_in_provided_year(year: Self::YearInfo) -> u8;
    fn year_info_from_era(
        &self,
        era: &[u8],
        era_year: i32,
    ) -> Result<Self::YearInfo, UnknownEraError>;
    fn year_info_from_extended(&self, extended_year: i32) -> Self::YearInfo;
    fn reference_year_from_month_day(
        &self,
        month_code: ValidMonthCode,
        day: u8,
    ) -> Result<Self::YearInfo, EcmaReferenceYearError>;

    // Provided methods
    fn ordinal_month_from_code(
        &self,
        _year: &Self::YearInfo,
        month_code: ValidMonthCode,
        _options: DateFromFieldsOptions,
    ) -> Result<u8, MonthCodeError> { ... }
    fn month_code_from_ordinal(
        &self,
        _year: &Self::YearInfo,
        ordinal_month: u8,
    ) -> ValidMonthCode { ... }
}
Expand description

Trait for converting from era codes, month codes, and other fields to year/month/day ordinals.

Required Associated Types§

Source

type YearInfo: Copy + Debug + PartialEq + ToExtendedYear

This stores the year as either an i32, or a type containing more useful computational information.

Required Methods§

Source

fn days_in_provided_month(year: Self::YearInfo, month: u8) -> u8

Source

fn months_in_provided_year(year: Self::YearInfo) -> u8

Source

fn year_info_from_era( &self, era: &[u8], era_year: i32, ) -> Result<Self::YearInfo, UnknownEraError>

Converts the era and era year to a YearInfo. If the calendar does not have eras, this should always return an Err result.

Source

fn year_info_from_extended(&self, extended_year: i32) -> Self::YearInfo

Converts an extended year to a YearInfo.

Source

fn reference_year_from_month_day( &self, month_code: ValidMonthCode, day: u8, ) -> Result<Self::YearInfo, EcmaReferenceYearError>

Calculates the ECMA reference year for the month code and day, or an error if the month code and day are invalid.

Note that this is called before any potential Overflow::Constrain application, so this should accept out-of-range day values as if they are the highest possible day for the given month.

Provided Methods§

Source

fn ordinal_month_from_code( &self, _year: &Self::YearInfo, month_code: ValidMonthCode, _options: DateFromFieldsOptions, ) -> Result<u8, MonthCodeError>

Calculates the ordinal month for the given year and month code.

The default impl is for non-lunisolar calendars with 12 months!

Source

fn month_code_from_ordinal( &self, _year: &Self::YearInfo, ordinal_month: u8, ) -> ValidMonthCode

Calculates the month code from the given ordinal month and year.

The caller must ensure that the ordinal is in range.

The default impl is for non-lunisolar calendars!

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.

Implementors§