usecrate::calendar_arithmetic::ArithmeticDate; usecrate::calendar_arithmetic::DateFieldsResolver; usecrate::error::{
DateError, DateFromFieldsError, EcmaReferenceYearError, MonthCodeError, UnknownEraError,
}; usecrate::options::DateFromFieldsOptions; usecrate::options::{DateAddOptions, DateDifferenceOptions}; usecrate::{types, Calendar, Date, RangeError}; use calendrical_calculations::helpers::I32CastError; use calendrical_calculations::rata_die::RataDie; use tinystr::tinystr;
/// The [Coptic Calendar](https://en.wikipedia.org/wiki/Coptic_calendar) /// /// The Coptic calendar, also called the Alexandrian Calendar, is a solar calendar that /// is influenced by both the ancient Egpytian calendar and the [`Julian`](crate::cal::Julian) /// calendar. It was introduced in Egypt under Roman rule in the first century BCE, and /// replaced for civil use in 1875, however continues to be used liturgically. /// /// This implementation extends proleptically for dates before the calendar's creation. /// /// This corresponds to the `"coptic"` [CLDR calendar](https://unicode.org/reports/tr35/#UnicodeCalendarIdentifier). /// /// # Era codes /// /// This calendar uses a single code: `am`, corresponding to the After Diocletian/Anno Martyrum /// era. 1 A.M. is equivalent to 284 C.E. /// /// # Months and days /// /// The 13 months are called Thout (`M01`, 30 days), Paopi (`M02`, 30 days), Hathor (`M03`, 30 days), /// Koiak (`M04`, 30 days), Tobi (`M05`, 30 days), Meshir (`M06`, 30 days), Paremhat (`M07`, 30 days), /// Parmouti (`M08`, 30 days), Pashons (`M09`, 30 days), Paoni (`M10`, 30 days), Epip (`M11`, 30 days), /// Mesori (`M12`, 30 days), Pi Kogi Enavot (`M13`, 5 days). /// /// In leap years (years divisible by 4), Pi Kogi Enavot gains a 6th day. /// /// Standard years thus have 365 days, and leap years 366. /// /// # Calendar drift /// /// The Coptic calendar has the same year lengths and leap year rules as the Julian calendar, /// so it experiences the same drift of 1 day in ~128 years with respect to the seasons. #[derive(Copy, Clone, Debug, Hash, Default, Eq, PartialEq, PartialOrd, Ord)] #[allow(clippy::exhaustive_structs)] // this type is stable pubstruct Coptic;
/// The inner date type used for representing [`Date`]s of [`Coptic`]. See [`Date`] and [`Coptic`] for more details. #[derive(Copy, Clone, Debug, Hash, Eq, PartialEq, PartialOrd, Ord)] pubstruct CopticDateInner(pub(crate) ArithmeticDate<Coptic>);
impl DateFieldsResolver for Coptic { type YearInfo = i32;
impl Coptic { pub(crate) fn reference_year_from_month_day(
month_code: types::ValidMonthCode,
day: u8,
) -> Result<i32, EcmaReferenceYearError> { let (ordinal_month, false) = month_code.to_tuple() else { return Err(EcmaReferenceYearError::MonthCodeNotInCalendar);
}; // December 31, 1972 occurs on 4th month, 22nd day, 1689 AM let anno_martyrum_year = if ordinal_month < 4 || (ordinal_month == 4 && day <= 22) { 1689 // Note: this must be >=6, not just == 6, since we have not yet // applied a potential Overflow::Constrain.
} elseif ordinal_month == 13 && day >= 6 { // 1687 AM is a leap year 1687
} else { 1688
};
Ok(anno_martyrum_year)
}
}
implcrate::cal::scaffold::UnstableSealed for Coptic {} impl Calendar for Coptic { type DateInner = CopticDateInner; type Year = types::EraYear; type DifferenceError = core::convert::Infallible;
#[cfg(test)] mod tests { usesuper::*; usecrate::options::{DateFromFieldsOptions, MissingFieldsStrategy, Overflow}; usecrate::types::DateFields;
#[test] fn test_coptic_regression() { // https://github.com/unicode-org/icu4x/issues/2254 let iso_date = Date::try_new_iso(-100, 3, 3).unwrap(); let coptic = iso_date.to_calendar(Coptic); let recovered_iso = coptic.to_iso();
assert_eq!(iso_date, recovered_iso);
}
#[test] fn test_from_fields_monthday_constrain() { // M13-7 is not a real day, however this should resolve to M12-6 // with Overflow::Constrain let fields = DateFields {
month_code: Some(b"M13"),
day: Some(7),
..Default::default()
}; let options = DateFromFieldsOptions {
overflow: Some(Overflow::Constrain),
missing_fields_strategy: Some(MissingFieldsStrategy::Ecma),
..Default::default()
};
let date = Date::try_from_fields(fields, options, Coptic).unwrap();
assert_eq!(date.day_of_month().0, 6, "Day was successfully constrained");
}
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.1 Sekunden
(vorverarbeitet am 2026-08-25)
¤
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.