Skip to main content

DateFromFieldsError

Enum DateFromFieldsError 

Source
#[non_exhaustive]
pub enum DateFromFieldsError { Range(RangeError), UnknownEra, MonthCodeInvalidSyntax, MonthCodeNotInCalendar, MonthCodeNotInYear, InconsistentYear, InconsistentMonth, NotEnoughFields, }
Expand description

Error type for date creation via Date::try_from_fields.

๐Ÿšง This code is considered unstable; it may change at any time, in breaking or non-breaking ways, including in SemVer minor releases. Do not use this type unless you are prepared for things to occasionally break.

Graduation tracking issue: issue #7161.

โœจ Enabled with the unstable Cargo feature.

Variants (Non-exhaustive)ยง

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
ยง

Range(RangeError)

A field is out of range for its domain.

ยงExamples

use icu::calendar::error::DateFromFieldsError;
use icu::calendar::error::RangeError;
use icu::calendar::types::DateFields;
use icu::calendar::Date;
use icu::calendar::Iso;

let mut fields = DateFields::default();
fields.extended_year = Some(2000);
fields.ordinal_month = Some(13);
fields.day = Some(1);

let err = Date::try_from_fields(fields, Default::default(), Iso)
    .expect_err("no month 13 in the ISO calendar");

assert!(matches!(
    err,
    DateFromFieldsError::Range(RangeError { field: "month", .. })
));
ยง

UnknownEra

The era code is invalid for the calendar.

ยง

MonthCodeInvalidSyntax

The month code syntax is invalid.

ยงExamples

use icu::calendar::error::DateFromFieldsError;
use icu::calendar::types::DateFields;
use icu::calendar::Date;
use icu::calendar::Iso;

let mut fields = DateFields::default();
fields.extended_year = Some(2000);
fields.month_code = Some(b"????");
fields.day = Some(1);

let err = Date::try_from_fields(fields, Default::default(), Iso)
    .expect_err("month code is invalid");

assert_eq!(err, DateFromFieldsError::MonthCodeInvalidSyntax);
ยง

MonthCodeNotInCalendar

The specified month code does not exist in this calendar.

ยงExamples

use icu::calendar::cal::Hebrew;
use icu::calendar::error::DateFromFieldsError;
use icu::calendar::types::DateFields;
use icu::calendar::Date;

let mut fields = DateFields::default();
fields.extended_year = Some(5783);
fields.month_code = Some(b"M13");
fields.day = Some(1);

let err = Date::try_from_fields(fields, Default::default(), Hebrew)
    .expect_err("no month M13 in Hebrew");
assert_eq!(err, DateFromFieldsError::MonthCodeNotInCalendar);
ยง

MonthCodeNotInYear

The specified month code exists in this calendar, but not in the specified year.

ยงExamples

use icu::calendar::cal::Hebrew;
use icu::calendar::error::DateFromFieldsError;
use icu::calendar::types::DateFields;
use icu::calendar::Date;

let mut fields = DateFields::default();
fields.extended_year = Some(5783);
fields.month_code = Some(b"M05L");
fields.day = Some(1);

let err = Date::try_from_fields(fields, Default::default(), Hebrew)
    .expect_err("no month M05L in Hebrew year 5783");
assert_eq!(err, DateFromFieldsError::MonthCodeNotInYear);
ยง

InconsistentYear

The year was specified in multiple inconsistent ways.

ยงExamples

use icu::calendar::cal::Japanese;
use icu::calendar::error::DateFromFieldsError;
use icu::calendar::types::DateFields;
use icu::calendar::Date;

let mut fields = DateFields::default();
fields.era = Some(b"reiwa");
fields.era_year = Some(6);
fields.ordinal_month = Some(1);
fields.day = Some(1);

Date::try_from_fields(fields, Default::default(), Japanese::new())
    .expect("a well-defined Japanese date");

fields.extended_year = Some(1900);

let err =
    Date::try_from_fields(fields, Default::default(), Japanese::new())
        .expect_err("year 1900 is not the same as 6 Reiwa");

assert_eq!(err, DateFromFieldsError::InconsistentYear);
ยง

InconsistentMonth

The month was specified in multiple inconsistent ways.

ยงExamples

use icu::calendar::cal::Hebrew;
use icu::calendar::error::DateFromFieldsError;
use icu::calendar::types::DateFields;
use icu::calendar::Date;
use tinystr::tinystr;

let mut fields = DateFields::default();
fields.extended_year = Some(5783);
fields.month_code = Some(b"M06");
fields.ordinal_month = Some(6);
fields.day = Some(1);

Date::try_from_fields(fields, Default::default(), Hebrew)
    .expect("a well-defined Hebrew date in a common year");

fields.extended_year = Some(5784);

let err = Date::try_from_fields(fields, Default::default(), Hebrew)
    .expect_err("month M06 is not the 6th month in leap year 5784");

assert_eq!(err, DateFromFieldsError::InconsistentMonth);
ยง

NotEnoughFields

Not enough fields were specified to form a well-defined date.

ยงExamples

use icu::calendar::cal::Hebrew;
use icu::calendar::error::DateFromFieldsError;
use icu::calendar::types::DateFields;
use icu::calendar::Date;
use tinystr::tinystr;

let mut fields = DateFields::default();

fields.ordinal_month = Some(3);

let err = Date::try_from_fields(fields, Default::default(), Hebrew)
    .expect_err("need more than just an ordinal month");
assert_eq!(err, DateFromFieldsError::NotEnoughFields);

fields.era_year = Some(5783);

let err = Date::try_from_fields(fields, Default::default(), Hebrew)
    .expect_err("need more than an ordinal month and an era year");
assert_eq!(err, DateFromFieldsError::NotEnoughFields);

fields.extended_year = Some(5783);

let err = Date::try_from_fields(fields, Default::default(), Hebrew)
    .expect_err("era year still needs an era");
assert_eq!(err, DateFromFieldsError::NotEnoughFields);

fields.era = Some(b"am");

let date = Date::try_from_fields(fields, Default::default(), Hebrew)
    .expect_err("still missing the day");
assert_eq!(err, DateFromFieldsError::NotEnoughFields);

fields.day = Some(1);
let date = Date::try_from_fields(fields, Default::default(), Hebrew)
    .expect("we have enough fields!");

Trait Implementationsยง

Sourceยง

impl Clone for DateFromFieldsError

Sourceยง

fn clone(&self) -> DateFromFieldsError

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) ยท Sourceยง

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Sourceยง

impl Debug for DateFromFieldsError

Sourceยง

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Sourceยง

impl Display for DateFromFieldsError

Sourceยง

fn fmt(&self, formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Sourceยง

impl Error for DateFromFieldsError

1.30.0 ยท Sourceยง

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 ยท Sourceยง

fn description(&self) -> &str

๐Ÿ‘ŽDeprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 ยท Sourceยง

fn cause(&self) -> Option<&dyn Error>

๐Ÿ‘ŽDeprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Sourceยง

fn provide<'a>(&'a self, request: &mut Request<'a>)

๐Ÿ”ฌThis is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Sourceยง

impl From<EcmaReferenceYearError> for DateFromFieldsError

Sourceยง

fn from(value: EcmaReferenceYearError) -> Self

Converts to this type from the input type.
Sourceยง

impl From<MonthCodeError> for DateFromFieldsError

Sourceยง

fn from(value: MonthCodeError) -> Self

Converts to this type from the input type.
Sourceยง

impl From<MonthCodeParseError> for DateFromFieldsError

Sourceยง

fn from(value: MonthCodeParseError) -> Self

Converts to this type from the input type.
Sourceยง

impl From<RangeError> for DateFromFieldsError

Sourceยง

fn from(value: RangeError) -> Self

Converts to this type from the input type.
Sourceยง

impl From<UnknownEraError> for DateFromFieldsError

Sourceยง

fn from(_value: UnknownEraError) -> Self

Converts to this type from the input type.
Sourceยง

impl PartialEq for DateFromFieldsError

Sourceยง

fn eq(&self, other: &DateFromFieldsError) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) ยท Sourceยง

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Sourceยง

impl Copy for DateFromFieldsError

Sourceยง

impl StructuralPartialEq for DateFromFieldsError

Auto Trait Implementationsยง

Blanket Implementationsยง

Sourceยง

impl<T> Any for T
where T: 'static + ?Sized,

Sourceยง

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Sourceยง

impl<T> Borrow<T> for T
where T: ?Sized,

Sourceยง

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Sourceยง

impl<T> BorrowMut<T> for T
where T: ?Sized,

Sourceยง

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Sourceยง

impl<T> CloneToUninit for T
where T: Clone,

Sourceยง

unsafe fn clone_to_uninit(&self, dest: *mut u8)

๐Ÿ”ฌThis is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Sourceยง

impl<T> From<T> for T

Sourceยง

fn from(t: T) -> T

Returns the argument unchanged.

Sourceยง

impl<T, U> Into<U> for T
where U: From<T>,

Sourceยง

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Sourceยง

impl<T> ToOwned for T
where T: Clone,

Sourceยง

type Owned = T

The resulting type after obtaining ownership.
Sourceยง

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Sourceยง

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Sourceยง

impl<T> ToString for T
where T: Display + ?Sized,

Sourceยง

fn to_string(&self) -> String

Converts the given value to a String. Read more
Sourceยง

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Sourceยง

type Error = Infallible

The type returned in the event of a conversion error.
Sourceยง

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Sourceยง

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Sourceยง

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Sourceยง

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Sourceยง

impl<T> ErasedDestructor for T
where T: 'static,