OLD | NEW |
1 /* | 1 /* |
2 ****************************************************************************** | 2 ****************************************************************************** |
3 * Copyright (C) 2003-2014, International Business Machines Corporation | 3 * Copyright (C) 2003-2015, International Business Machines Corporation |
4 * and others. All Rights Reserved. | 4 * and others. All Rights Reserved. |
5 ****************************************************************************** | 5 ****************************************************************************** |
6 * | 6 * |
7 * File ISLAMCAL.H | 7 * File ISLAMCAL.H |
8 * | 8 * |
9 * Modification History: | 9 * Modification History: |
10 * | 10 * |
11 * Date Name Description | 11 * Date Name Description |
12 * 10/14/2003 srl ported from java IslamicCalendar | 12 * 10/14/2003 srl ported from java IslamicCalendar |
13 ***************************************************************************** | 13 ***************************************************************************** |
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 * @draft ICU 2.4 | 311 * @draft ICU 2.4 |
312 */ | 312 */ |
313 int32_t IslamicCalendar::handleGetLimit(UCalendarDateFields field, ELimitType li
mitType) const { | 313 int32_t IslamicCalendar::handleGetLimit(UCalendarDateFields field, ELimitType li
mitType) const { |
314 return LIMITS[field][limitType]; | 314 return LIMITS[field][limitType]; |
315 } | 315 } |
316 | 316 |
317 //------------------------------------------------------------------------- | 317 //------------------------------------------------------------------------- |
318 // Assorted calculation utilities | 318 // Assorted calculation utilities |
319 // | 319 // |
320 | 320 |
| 321 // we could compress this down more if we need to |
| 322 static const int8_t umAlQuraYrStartEstimateFix[] = { |
| 323 0, 0, -1, 0, -1, 0, 0, 0, 0, 0, // 1300.. |
| 324 -1, 0, 0, 0, 0, 0, 0, 0, -1, 0, // 1310.. |
| 325 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, // 1320.. |
| 326 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, // 1330.. |
| 327 0, 0, 1, 0, 0, -1, -1, 0, 0, 0, // 1340.. |
| 328 1, 0, 0, -1, 0, 0, 0, 1, 1, 0, // 1350.. |
| 329 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, // 1360.. |
| 330 0, 1, 1, 0, 0, -1, 0, 1, 0, 1, // 1370.. |
| 331 1, 0, 0, -1, 0, 1, 0, 0, 0, -1, // 1380.. |
| 332 0, 1, 0, 1, 0, 0, 0, -1, 0, 0, // 1390.. |
| 333 0, 0, -1, -1, 0, -1, 0, 1, 0, 0, // 1400.. |
| 334 0, -1, 0, 0, 0, 1, 0, 0, 0, 0, // 1410.. |
| 335 0, 1, 0, 0, -1, -1, 0, 0, 0, 1, // 1420.. |
| 336 0, 0, -1, -1, 0, -1, 0, 0, -1, -1, // 1430.. |
| 337 0, -1, 0, -1, 0, 0, -1, -1, 0, 0, // 1440.. |
| 338 0, 0, 0, 0, -1, 0, 1, 0, 1, 1, // 1450.. |
| 339 0, 0, -1, 0, 1, 0, 0, 0, 0, 0, // 1460.. |
| 340 1, 0, 1, 0, 0, 0, -1, 0, 1, 0, // 1470.. |
| 341 0, -1, -1, 0, 0, 0, 1, 0, 0, 0, // 1480.. |
| 342 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, // 1490.. |
| 343 1, 0, 0, -1, 0, 0, 0, 1, 1, 0, // 1500.. |
| 344 0, -1, 0, 1, 0, 1, 1, 0, 0, 0, // 1510.. |
| 345 0, 1, 0, 0, 0, -1, 0, 0, 0, 1, // 1520.. |
| 346 0, 0, 0, -1, 0, 0, 0, 0, 0, -1, // 1530.. |
| 347 0, -1, 0, 1, 0, 0, 0, -1, 0, 1, // 1540.. |
| 348 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, // 1550.. |
| 349 -1, 0, 0, 0, 0, 1, 0, 0, 0, -1, // 1560.. |
| 350 0, 0, 0, 0, -1, -1, 0, -1, 0, 1, // 1570.. |
| 351 0, 0, -1, -1, 0, 0, 1, 1, 0, 0, // 1580.. |
| 352 -1, 0, 0, 0, 0, 1, 0, 0, 0, 0, // 1590.. |
| 353 1 // 1600 |
| 354 }; |
| 355 |
321 /** | 356 /** |
322 * Determine whether a year is a leap year in the Islamic civil calendar | 357 * Determine whether a year is a leap year in the Islamic civil calendar |
323 */ | 358 */ |
324 UBool IslamicCalendar::civilLeapYear(int32_t year) | 359 UBool IslamicCalendar::civilLeapYear(int32_t year) |
325 { | 360 { |
326 return (14 + 11 * year) % 30 < 11; | 361 return (14 + 11 * year) % 30 < 11; |
327 } | 362 } |
328 | 363 |
329 /** | 364 /** |
330 * Return the day # on which the given year starts. Days are counted | 365 * Return the day # on which the given year starts. Days are counted |
331 * from the Hijri epoch, origin 0. | 366 * from the Hijri epoch, origin 0. |
332 */ | 367 */ |
333 int32_t IslamicCalendar::yearStart(int32_t year) const{ | 368 int32_t IslamicCalendar::yearStart(int32_t year) const{ |
334 if (cType == CIVIL || cType == TBLA || | 369 if (cType == CIVIL || cType == TBLA || |
335 (cType == UMALQURA && (year < UMALQURA_YEAR_START || year > UMALQURA_YEA
R_END))) | 370 (cType == UMALQURA && (year < UMALQURA_YEAR_START || year > UMALQURA_YEA
R_END))) |
336 { | 371 { |
337 return (year-1)*354 + ClockMath::floorDivide((3+11*year),30); | 372 return (year-1)*354 + ClockMath::floorDivide((3+11*year),30); |
338 } else if(cType==ASTRONOMICAL){ | 373 } else if(cType==ASTRONOMICAL){ |
339 return trueMonthStart(12*(year-1)); | 374 return trueMonthStart(12*(year-1)); |
340 } else { | 375 } else { |
341 int32_t ys = yearStart(UMALQURA_YEAR_START-1); | 376 year -= UMALQURA_YEAR_START; |
342 ys+= handleGetYearLength(UMALQURA_YEAR_START-1); | 377 // rounded least-squares fit of the dates previously calculated from UMA
LQURA_MONTHLENGTH iteration |
343 for(int i=UMALQURA_YEAR_START; i< year; i++){ | 378 int32_t yrStartLinearEstimate = (int32_t)((354.36720 * (double)year) + 4
60322.05 + 0.5); |
344 ys+= handleGetYearLength(i); | 379 // need a slight correction to some |
345 } | 380 return yrStartLinearEstimate + umAlQuraYrStartEstimateFix[year]; |
346 return ys; | |
347 } | 381 } |
348 } | 382 } |
349 | 383 |
350 /** | 384 /** |
351 * Return the day # on which the given month starts. Days are counted | 385 * Return the day # on which the given month starts. Days are counted |
352 * from the Hijri epoch, origin 0. | 386 * from the Hijri epoch, origin 0. |
353 * | 387 * |
354 * @param year The hijri year | 388 * @param year The hijri year |
355 * @param year The hijri month, 0-based (assumed to be in range 0..11) | 389 * @param month The hijri month, 0-based (assumed to be in range 0..11) |
356 */ | 390 */ |
357 int32_t IslamicCalendar::monthStart(int32_t year, int32_t month) const { | 391 int32_t IslamicCalendar::monthStart(int32_t year, int32_t month) const { |
358 if (cType == CIVIL || cType == TBLA) { | 392 if (cType == CIVIL || cType == TBLA) { |
359 // This does not handle months out of the range 0..11 | 393 // This does not handle months out of the range 0..11 |
360 return (int32_t)uprv_ceil(29.5*month) | 394 return (int32_t)uprv_ceil(29.5*month) |
361 + (year-1)*354 + (int32_t)ClockMath::floorDivide((3+11*year),30); | 395 + (year-1)*354 + (int32_t)ClockMath::floorDivide((3+11*year),30); |
362 } else if(cType==ASTRONOMICAL){ | 396 } else if(cType==ASTRONOMICAL){ |
363 return trueMonthStart(12*(year-1) + month); | 397 return trueMonthStart(12*(year-1) + month); |
364 } else { | 398 } else { |
365 int32_t ms = yearStart(year); | 399 int32_t ms = yearStart(year); |
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
720 } | 754 } |
721 | 755 |
722 | 756 |
723 | 757 |
724 UOBJECT_DEFINE_RTTI_IMPLEMENTATION(IslamicCalendar) | 758 UOBJECT_DEFINE_RTTI_IMPLEMENTATION(IslamicCalendar) |
725 | 759 |
726 U_NAMESPACE_END | 760 U_NAMESPACE_END |
727 | 761 |
728 #endif | 762 #endif |
729 | 763 |
OLD | NEW |