//! This module contains types and implementations for the Ethiopian calendar. //! //! ```rust //! use icu::calendar::{ethiopian::Ethiopian, Date, DateTime}; //! //! // `Date` type //! let date_iso = Date::try_new_iso_date(1970, 1, 2) //! .expect("Failed to initialize ISO Date instance."); //! let date_ethiopian = Date::new_from_iso(date_iso, Ethiopian::new()); //! //! // `DateTime` type //! let datetime_iso = DateTime::try_new_iso_datetime(1970, 1, 2, 13, 1, 0) //! .expect("Failed to initialize ISO DateTime instance."); //! let datetime_ethiopian = //! DateTime::new_from_iso(datetime_iso, Ethiopian::new()); //! //! // `Date` checks //! assert_eq!(date_ethiopian.year().number, 1962); //! assert_eq!(date_ethiopian.month().ordinal, 4); //! assert_eq!(date_ethiopian.day_of_month().0, 24); //! //! // `DateTime` type //! assert_eq!(datetime_ethiopian.date.year().number, 1962); //! assert_eq!(datetime_ethiopian.date.month().ordinal, 4); //! assert_eq!(datetime_ethiopian.date.day_of_month().0, 24); //! assert_eq!(datetime_ethiopian.time.hour.number(), 13); //! assert_eq!(datetime_ethiopian.time.minute.number(), 1); //! assert_eq!(datetime_ethiopian.time.second.number(), 0); //! ```
usecrate::any_calendar::AnyCalendarKind; usecrate::calendar_arithmetic::{ArithmeticDate, CalendarArithmetic}; usecrate::iso::Iso; usecrate::{types, Calendar, CalendarError, Date, DateDuration, DateDurationUnit, DateTime, Time}; use calendrical_calculations::helpers::I32CastError; use calendrical_calculations::rata_die::RataDie; use tinystr::tinystr;
/// The number of years the Amete Alem epoch precedes the Amete Mihret epoch const AMETE_ALEM_OFFSET: i32 = 5500;
/// Which era style the ethiopian calendar uses #[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)] #[non_exhaustive] pubenum EthiopianEraStyle { /// Use an era scheme of pre- and post- Incarnation eras, /// anchored at the date of the Incarnation of Jesus in this calendar
AmeteMihret, /// Use an era scheme of the Anno Mundi era, anchored at the date of Creation /// in this calendar
AmeteAlem,
}
/// The [Ethiopian Calendar] /// /// The [Ethiopian calendar] is a solar calendar used by the Coptic Orthodox Church, with twelve normal months /// and a thirteenth small epagomenal month. /// /// This type can be used with [`Date`] or [`DateTime`] to represent dates in this calendar. /// /// It can be constructed in two modes: using the Amete Alem era scheme, or the Amete Mihret era scheme (the default), /// see [`EthiopianEraStyle`] for more info. /// /// [Ethiopian calendar]: https://en.wikipedia.org/wiki/Ethiopian_calendar /// /// # Era codes /// /// This calendar supports three era codes, based on what mode it is in. In the Amete Mihret scheme it has /// the `"incar"` and `"pre-incar"` eras, 1 Incarnation is 9 CE. In the Amete Alem scheme, it instead has a single era, /// `"mundi`, where 1 Anno Mundi is 5493 BCE. Dates before that use negative year numbers. /// /// # Month codes /// /// This calendar supports 13 solar month codes (`"M01" - "M13"`), with `"M13"` being used for the short epagomenal month /// at the end of the year. // The bool specifies whether dates should be in the Amete Alem era scheme #[derive(Copy, Clone, Debug, Hash, Default, Eq, PartialEq, PartialOrd, Ord)] pubstruct Ethiopian(pub(crate) bool);
/// The inner date type used for representing [`Date`]s of [`Ethiopian`]. See [`Date`] and [`Ethiopian`] for more details. #[derive(Copy, Clone, Debug, Hash, Eq, PartialEq, PartialOrd, Ord)] pubstruct EthiopianDateInner(ArithmeticDate<Ethiopian>);
impl CalendarArithmetic for Ethiopian { type YearInfo = ();
impl Ethiopian { /// Construct a new Ethiopian Calendar for the Amete Mihret era naming scheme pubconstfn new() -> Self { Self(false)
} /// Construct a new Ethiopian Calendar with a value specifying whether or not it is Amete Alem pubconstfn new_with_era_style(era_style: EthiopianEraStyle) -> Self { Self(matches!(era_style, EthiopianEraStyle::AmeteAlem))
} /// Set whether or not this uses the Amete Alem era scheme pubfn set_era_style(&mutself, era_style: EthiopianEraStyle) { self.0 = era_style == EthiopianEraStyle::AmeteAlem
}
/// Returns whether this has the Amete Alem era pubfn era_style(&self) -> EthiopianEraStyle { ifself.0 {
EthiopianEraStyle::AmeteAlem
} else {
EthiopianEraStyle::AmeteMihret
}
}
impl Date<Ethiopian> { /// Construct new Ethiopian Date. /// /// For the Amete Mihret era style, negative years work with /// year 0 as 1 pre-Incarnation, year -1 as 2 pre-Incarnation, /// and so on. /// /// ```rust /// use icu::calendar::ethiopian::EthiopianEraStyle; /// use icu::calendar::Date; /// /// let date_ethiopian = Date::try_new_ethiopian_date( /// EthiopianEraStyle::AmeteMihret, /// 2014, /// 8, /// 25, /// ) /// .expect("Failed to initialize Ethopic Date instance."); /// /// assert_eq!(date_ethiopian.year().number, 2014); /// assert_eq!(date_ethiopian.month().ordinal, 8); /// assert_eq!(date_ethiopian.day_of_month().0, 25); /// ``` pubfn try_new_ethiopian_date(
era_style: EthiopianEraStyle, mut year: i32,
month: u8,
day: u8,
) -> Result<Date<Ethiopian>, CalendarError> { if era_style == EthiopianEraStyle::AmeteAlem {
year -= AMETE_ALEM_OFFSET;
}
ArithmeticDate::new_from_ordinals(year, month, day)
.map(EthiopianDateInner)
.map(|inner| Date::from_raw(inner, Ethiopian::new_with_era_style(era_style)))
}
}
impl DateTime<Ethiopian> { /// Construct a new Ethiopian datetime from integers. /// /// For the Amete Mihret era style, negative years work with /// year 0 as 1 pre-Incarnation, year -1 as 2 pre-Incarnation, /// and so on. /// /// ```rust /// use icu::calendar::ethiopian::EthiopianEraStyle; /// use icu::calendar::DateTime; /// /// let datetime_ethiopian = DateTime::try_new_ethiopian_datetime( /// EthiopianEraStyle::AmeteMihret, /// 2014, /// 8, /// 25, /// 13, /// 1, /// 0, /// ) /// .expect("Failed to initialize Ethiopian DateTime instance."); /// /// assert_eq!(datetime_ethiopian.date.year().number, 2014); /// assert_eq!(datetime_ethiopian.date.month().ordinal, 8); /// assert_eq!(datetime_ethiopian.date.day_of_month().0, 25); /// assert_eq!(datetime_ethiopian.time.hour.number(), 13); /// assert_eq!(datetime_ethiopian.time.minute.number(), 1); /// assert_eq!(datetime_ethiopian.time.second.number(), 0); /// ``` pubfn try_new_ethiopian_datetime(
era_style: EthiopianEraStyle,
year: i32,
month: u8,
day: u8,
hour: u8,
minute: u8,
second: u8,
) -> Result<DateTime<Ethiopian>, CalendarError> {
Ok(DateTime {
date: Date::try_new_ethiopian_date(era_style, year, month, day)?,
time: Time::try_new(hour, minute, second, 0)?,
})
}
}
#[cfg(test)] mod test { usesuper::*;
#[test] fn test_leap_year() { // 11th September 2023 in gregorian is 6/13/2015 in ethiopian let iso_date = Date::try_new_iso_date(2023, 9, 11).unwrap(); let ethiopian_date = Ethiopian::new().date_from_iso(iso_date);
assert_eq!(ethiopian_date.0.year, 2015);
assert_eq!(ethiopian_date.0.month, 13);
assert_eq!(ethiopian_date.0.day, 6);
}
#[test] fn test_iso_to_ethiopian_conversion_and_back() { let iso_date = Date::try_new_iso_date(1970, 1, 2).unwrap(); let date_ethiopian = Date::new_from_iso(iso_date, Ethiopian::new());
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.