usecrate::cal::coptic::CopticDateInner; usecrate::cal::Coptic; usecrate::calendar_arithmetic::{ArithmeticDate, DateFieldsResolver}; usecrate::error::{
DateError, DateFromFieldsError, EcmaReferenceYearError, MonthCodeError, UnknownEraError,
}; usecrate::options::DateFromFieldsOptions; usecrate::options::{DateAddOptions, DateDifferenceOptions}; usecrate::types::DateFields; usecrate::{types, Calendar, Date, RangeError}; use calendrical_calculations::rata_die::RataDie; use tinystr::tinystr;
/// The Coptic year of the Amete Mihret epoch const AMETE_MIHRET_OFFSET: i32 = -276;
/// The Coptic year of the Amete Alem epoch const AMETE_ALEM_OFFSET: i32 = -5776;
/// Which era style the ethiopian calendar uses #[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, PartialOrd, Ord)] #[non_exhaustive] pubenum EthiopianEraStyle { /// Use the Anno Mundi era, anchored at the date of Creation, followed by the /// Incarnation era, anchored at the date of the Incarnation of Jesus
AmeteMihret, /// Use the single Anno Mundi era, anchored at the date of Creation
AmeteAlem,
}
/// The [Ethiopian Calendar](https://en.wikipedia.org/wiki/Ethiopian_calendar) /// /// The Ethiopian calendar is a variant of the [`Coptic`] calendar. It differs /// from the Coptic calendar by the names of the months as well as the era. /// /// This implementation 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. /// /// This implementation extends proleptically for dates before the calendar's creation. /// /// This corresponds to the `"ethiopic"` and `"ethioaa"` [CLDR calendars](https://unicode.org/reports/tr35/#UnicodeCalendarIdentifier), /// with `"ethiopic"` being for [`EthiopianEraStyle::AmeteMihret`] /// /// # Era codes /// /// This calendar always uses the `aa` era, where 1 Amete Alem is 5493 BCE. Dates before this era use negative years. /// Dates before that use negative year numbers. /// /// In the Amete Mihret scheme it uses the additional `am` era, 1 Amete Mihret is 9 CE. /// /// # Months and days /// /// The 13 months are called Mäskäräm (`M01`, 30 days), Ṭəqəmt (`M02`, 30 days), /// Ḫədar (`M03`, 30 days), Taḫśaś (`M04`, 30 days), Ṭərr (`M05`, 30 days), Yäkatit (`M06`, 30 days), /// Mägabit (`M07`, 30 days), Miyazya (`M08`, 30 days), Gənbo (`M09`, 30 days), /// Säne (`M10`, 30 days), Ḥamle (`M11`, 30 days), Nähase (`M12`, 30 days), Ṗagʷəmen (`M13`, 5 days). /// /// In leap years (years divisible by 4), Ṗagʷəmen gains a 6th day. /// /// Standard years thus have 365 days, and leap years 366. /// /// # Calendar drift /// /// The Ethiopian calendar has the same year lengths and leap year rules as the [`Coptic`] and /// [`Julian`](crate::cal::Julian) calendars, so it experiences the same drift of 1 day in ~128 /// years with respect to the seasons. #[derive(Copy, Clone, Debug, Hash, Eq, PartialEq, PartialOrd, Ord)] pubstruct Ethiopian(EthiopianEraStyle);
implcrate::cal::scaffold::UnstableSealed for Ethiopian {} impl Calendar for Ethiopian { type DateInner = EthiopianDateInner; type Year = <Coptic as Calendar>::Year; type DifferenceError = <Coptic as Calendar>::DifferenceError;
impl Ethiopian { /// Construct a new Ethiopian Calendar for the Amete Mihret era naming scheme pubconstfn new() -> Self { Self(EthiopianEraStyle::AmeteMihret)
}
/// Construct a new Ethiopian Calendar with an explicit [`EthiopianEraStyle`]. pubconstfn new_with_era_style(era_style: EthiopianEraStyle) -> Self { Self(era_style)
}
/// Returns the [`EthiopianEraStyle`] used by this calendar. pubfn era_style(&self) -> EthiopianEraStyle { self.0
}
}
impl Date<Ethiopian> { /// Construct new Ethiopian Date. /// /// ```rust /// use icu::calendar::cal::EthiopianEraStyle; /// use icu::calendar::Date; /// /// let date_ethiopian = /// Date::try_new_ethiopian(EthiopianEraStyle::AmeteMihret, 2014, 8, 25) /// .expect("Failed to initialize Ethopic Date instance."); /// /// assert_eq!(date_ethiopian.era_year().year, 2014); /// assert_eq!(date_ethiopian.month().ordinal, 8); /// assert_eq!(date_ethiopian.day_of_month().0, 25); /// ``` pubfn try_new_ethiopian(
era_style: EthiopianEraStyle,
year: i32,
month: u8,
day: u8,
) -> Result<Date<Ethiopian>, RangeError> { let year = Ethiopian(era_style).year_info_from_extended(year);
ArithmeticDate::try_from_ymd(year, month, day)
.map(CopticDateInner)
.map(EthiopianDateInner)
.map(|inner| Date::from_raw(inner, Ethiopian(era_style)))
}
}
#[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(2023, 9, 11).unwrap(); let date_ethiopian = Date::new_from_iso(iso_date, Ethiopian::new());
assert_eq!(date_ethiopian.extended_year(), 2015);
assert_eq!(date_ethiopian.month().ordinal, 13);
assert_eq!(date_ethiopian.day_of_month().0, 6);
}
#[test] fn test_iso_to_ethiopian_conversion_and_back() { let iso_date = Date::try_new_iso(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.