| 1 |
// This file is part of ICU4X. For terms of use, please see the file |
| 2 |
// called LICENSE at the top level of the ICU4X source tree |
| 3 |
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ). |
| 4 |
|
| 5 |
use icu_calendar::Date; |
| 6 |
use icu_calendar::cal::Hijri; |
| 7 |
use icu_calendar::cal::hijri::{ |
| 8 |
HijriYear, Rules, TabularAlgorithm, TabularAlgorithmEpoch, TabularAlgorithmLeapYears, |
| 9 |
}; |
| 10 |
|
| 11 |
/// [`Hijri`] [`Rules`] based on an astronomical simulation for Mecca. |
| 12 |
/// |
| 13 |
/// These simulations use methods published by E. M. Reingold, S. K. Shaukat, et al.[^1] |
| 14 |
/// which are not officially recognized in any region and do not match sightings |
| 15 |
/// on the ground. |
| 16 |
/// |
| 17 |
/// [^1]: See [`calendrical_calculations::islamic::observational_islamic_from_fixed`] |
| 18 |
#[derive(Debug, Clone, Copy)] |
| 19 |
struct ReingoldSimulation; |
| 20 |
|
| 21 |
impl icu_calendar::cal::scaffold::UnstableSealed for ReingoldSimulation {} |
| 22 |
impl Rules for ReingoldSimulation { |
| 23 |
fn year(&self, extended_year: i32) -> HijriYear { |
| 24 |
if !(1317..1567).contains(&extended_year) { |
| 25 |
// Reingold only works for current years |
| 26 |
return TabularAlgorithm::new( |
| 27 |
TabularAlgorithmLeapYears::TypeII, |
| 28 |
TabularAlgorithmEpoch::Friday, |
| 29 |
) |
| 30 |
.year(extended_year); |
| 31 |
} |
| 32 |
|
| 33 |
HijriYear::try_new( |
| 34 |
extended_year, |
| 35 |
core::array::from_fn::<_, 13, _>(|m| { |
| 36 |
calendrical_calculations::islamic::fixed_from_observational_islamic( |
| 37 |
extended_year + m as i32 / 12, |
| 38 |
m as u8 % 12 + 1, |
| 39 |
1, |
| 40 |
calendrical_calculations::islamic::MECCA, |
| 41 |
) |
| 42 |
}), |
| 43 |
) |
| 44 |
.unwrap() |
| 45 |
} |
| 46 |
|
| 47 |
type DateCompatibilityError = core::convert::Infallible; |
| 48 |
|
| 49 |
fn check_date_compatibility(&self, &Self: &Self) -> Result<(), Self::DateCompatibilityError> { |
| 50 |
Ok(()) |
| 51 |
} |
| 52 |
|
| 53 |
fn debug_name(&self) -> &'static str { |
| 54 |
"Hijri (Reingold, Mecca)" |
| 55 |
} |
| 56 |
} |
| 57 |
|
| 58 |
#[test] |
| 59 |
fn main() { |
| 60 |
Date::try_new_hijri_with_calendar(1390, 1, 30, Hijri(ReingoldSimulation)).unwrap(); |
| 61 |
|
| 62 |
Date::try_new_iso(2000, 5, 5) |
| 63 |
.unwrap() |
| 64 |
.to_calendar(Hijri(ReingoldSimulation)); |
| 65 |
} |