@@ -13,9 +13,6 @@ use crate::types::DateFields;
1313use crate :: types:: Month ;
1414use crate :: { types, Calendar , Date } ;
1515use crate :: { AsCalendar , RangeError } ;
16- use calendrical_calculations:: islamic:: {
17- ISLAMIC_EPOCH_FRIDAY , ISLAMIC_EPOCH_THURSDAY , WELL_BEHAVED_ASTRONOMICAL_RANGE ,
18- } ;
1916use calendrical_calculations:: rata_die:: RataDie ;
2017use core:: fmt:: Debug ;
2118use icu_locale_core:: preferences:: extensions:: unicode:: keywords:: {
@@ -166,96 +163,21 @@ impl Rules for AstronomicalSimulation {
166163 fn year ( & self , extended_year : i32 ) -> HijriYear {
167164 if let Some ( data) = HijriYear :: lookup (
168165 extended_year,
169- simulated_mecca_data:: STARTING_YEAR ,
170- simulated_mecca_data:: DATA ,
166+ match self . location {
167+ SimulatedLocation :: Mecca => simulated_mecca_data:: STARTING_YEAR ,
168+ } ,
169+ match self . location {
170+ SimulatedLocation :: Mecca => simulated_mecca_data:: DATA ,
171+ } ,
171172 ) {
172- return data;
173- }
174-
175- let location = match self . location {
176- SimulatedLocation :: Mecca => calendrical_calculations:: islamic:: MECCA ,
177- } ;
178-
179- let start_day = calendrical_calculations:: islamic:: fixed_from_observational_islamic (
180- extended_year,
181- 1 ,
182- 1 ,
183- location,
184- ) ;
185- let next_start_day = calendrical_calculations:: islamic:: fixed_from_observational_islamic (
186- extended_year + 1 ,
187- 1 ,
188- 1 ,
189- location,
190- ) ;
191- match ( next_start_day - start_day) as u16 {
192- 355 | 354 => ( ) ,
193- 353 => {
194- icu_provider:: log:: trace!(
195- "({}) Found year {extended_year} AH with length {}. See <https://github.com/unicode-org/icu4x/issues/4930>" ,
196- self . debug_name( ) ,
197- next_start_day - start_day
198- ) ;
199- }
200- other => {
201- debug_assert ! (
202- !WELL_BEHAVED_ASTRONOMICAL_RANGE . contains( & start_day) ,
203- "({}) Found year {extended_year} AH with length {}!" ,
204- self . debug_name( ) ,
205- other
206- )
173+ data
174+ } else {
175+ TabularAlgorithm {
176+ leap_years : TabularAlgorithmLeapYears :: TypeII ,
177+ epoch : TabularAlgorithmEpoch :: Friday ,
207178 }
179+ . year ( extended_year)
208180 }
209-
210- let month_lengths = {
211- let mut excess_days = 0 ;
212- let mut month_lengths = core:: array:: from_fn ( |month_idx| {
213- let days_in_month =
214- calendrical_calculations:: islamic:: observational_islamic_month_days (
215- extended_year,
216- month_idx as u8 + 1 ,
217- location,
218- ) ;
219- match days_in_month {
220- 29 => false ,
221- 30 => true ,
222- 31 => {
223- icu_provider:: log:: trace!(
224- "({}) Found year {extended_year} AH with month length {days_in_month} for month {}." ,
225- self . debug_name( ) ,
226- month_idx + 1
227- ) ;
228- excess_days += 1 ;
229- true
230- }
231- _ => {
232- debug_assert ! (
233- !WELL_BEHAVED_ASTRONOMICAL_RANGE . contains( & start_day) ,
234- "({}) Found year {extended_year} AH with month length {days_in_month} for month {}!" ,
235- self . debug_name( ) ,
236- month_idx + 1
237- ) ;
238- false
239- }
240- }
241- } ) ;
242- // To maintain invariants for calendar arithmetic, if astronomy finds
243- // a 31-day month, "move" the day to the first 29-day month in the
244- // same year to maintain all months at 29 or 30 days.
245- if excess_days != 0 {
246- debug_assert ! (
247- excess_days == 1 || !WELL_BEHAVED_ASTRONOMICAL_RANGE . contains( & start_day) ,
248- "({}) Found year {extended_year} AH with more than one excess day!" ,
249- self . debug_name( )
250- ) ;
251- if let Some ( l) = month_lengths. iter_mut ( ) . find ( |l| !( * * l) ) {
252- * l = true ;
253- }
254- }
255- month_lengths
256- } ;
257- HijriYear :: try_new ( extended_year, start_day, month_lengths)
258- . unwrap_or_else ( || UmmAlQura . year ( extended_year) )
259181 }
260182}
261183
@@ -498,8 +420,8 @@ pub enum TabularAlgorithmEpoch {
498420impl TabularAlgorithmEpoch {
499421 fn rata_die ( self ) -> RataDie {
500422 match self {
501- Self :: Thursday => ISLAMIC_EPOCH_THURSDAY ,
502- Self :: Friday => ISLAMIC_EPOCH_FRIDAY ,
423+ Self :: Thursday => calendrical_calculations :: islamic :: ISLAMIC_EPOCH_THURSDAY ,
424+ Self :: Friday => calendrical_calculations :: islamic :: ISLAMIC_EPOCH_FRIDAY ,
503425 }
504426 }
505427}
@@ -1275,27 +1197,27 @@ mod test {
12751197 DateCase {
12761198 year : -1245 ,
12771199 month : 12 ,
1278- day : 10 ,
1200+ day : 9 ,
12791201 } ,
12801202 DateCase {
12811203 year : -813 ,
12821204 month : 2 ,
1283- day : 25 ,
1205+ day : 23 ,
12841206 } ,
12851207 DateCase {
12861208 year : -568 ,
12871209 month : 4 ,
1288- day : 2 ,
1210+ day : 1 ,
12891211 } ,
12901212 DateCase {
12911213 year : -501 ,
12921214 month : 4 ,
1293- day : 7 ,
1215+ day : 6 ,
12941216 } ,
12951217 DateCase {
12961218 year : -157 ,
12971219 month : 10 ,
1298- day : 18 ,
1220+ day : 17 ,
12991221 } ,
13001222 DateCase {
13011223 year : -47 ,
@@ -1330,7 +1252,7 @@ mod test {
13301252 DateCase {
13311253 year : 687 ,
13321254 month : 2 ,
1333- day : 21 ,
1255+ day : 20 ,
13341256 } ,
13351257 DateCase {
13361258 year : 697 ,
@@ -1339,8 +1261,8 @@ mod test {
13391261 } ,
13401262 DateCase {
13411263 year : 793 ,
1342- month : 6 ,
1343- day : 29 ,
1264+ month : 7 ,
1265+ day : 1 ,
13441266 } ,
13451267 DateCase {
13461268 year : 839 ,
@@ -1350,7 +1272,7 @@ mod test {
13501272 DateCase {
13511273 year : 897 ,
13521274 month : 6 ,
1353- day : 2 ,
1275+ day : 1 ,
13541276 } ,
13551277 DateCase {
13561278 year : 960 ,
@@ -1370,7 +1292,7 @@ mod test {
13701292 DateCase {
13711293 year : 1091 ,
13721294 month : 6 ,
1373- day : 3 ,
1295+ day : 2 ,
13741296 } ,
13751297 DateCase {
13761298 year : 1128 ,
@@ -1380,7 +1302,7 @@ mod test {
13801302 DateCase {
13811303 year : 1182 ,
13821304 month : 2 ,
1383- day : 4 ,
1305+ day : 3 ,
13841306 } ,
13851307 DateCase {
13861308 year : 1234 ,
0 commit comments