mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-07 06:25:30 +00:00
ICU-8449 Add Um al-Qura Hijri Calendar Support
X-SVN-Rev: 34053
This commit is contained in:
parent
c291c1230d
commit
e715efb8e8
5 changed files with 388 additions and 70 deletions
|
@ -6,7 +6,7 @@
|
|||
*
|
||||
* File CALENDAR.CPP
|
||||
*
|
||||
* Modification History:
|
||||
* Modification History:
|
||||
*
|
||||
* Date Name Description
|
||||
* 02/03/97 clhuang Creation.
|
||||
|
@ -329,6 +329,9 @@ static Calendar *createStandardCalendar(ECalType calType, const Locale &loc, UEr
|
|||
case CALTYPE_ISLAMIC:
|
||||
cal = new IslamicCalendar(loc, status, IslamicCalendar::ASTRONOMICAL);
|
||||
break;
|
||||
case CALTYPE_ISLAMIC_UMALQURA:
|
||||
cal = new IslamicCalendar(loc, status, IslamicCalendar::UMALQURA);
|
||||
break;
|
||||
case CALTYPE_HEBREW:
|
||||
cal = new HebrewCalendar(loc, status);
|
||||
break;
|
||||
|
@ -355,7 +358,6 @@ static Calendar *createStandardCalendar(ECalType calType, const Locale &loc, UEr
|
|||
case CALTYPE_DANGI:
|
||||
cal = new DangiCalendar(loc, status);
|
||||
break;
|
||||
case CALTYPE_ISLAMIC_UMALQURA:
|
||||
case CALTYPE_ISLAMIC_TBLA:
|
||||
case CALTYPE_ISLAMIC_RGSA:
|
||||
// Need to add handling for these, meanwhile fall through to default
|
||||
|
@ -538,33 +540,33 @@ static void U_CALLCONV
|
|||
initCalendarService(UErrorCode &status)
|
||||
{
|
||||
#ifdef U_DEBUG_CALSVC
|
||||
fprintf(stderr, "Spinning up Calendar Service\n");
|
||||
fprintf(stderr, "Spinning up Calendar Service\n");
|
||||
#endif
|
||||
ucln_i18n_registerCleanup(UCLN_I18N_CALENDAR, calendar_cleanup);
|
||||
gService = new CalendarService();
|
||||
if (gService == NULL) {
|
||||
status = U_MEMORY_ALLOCATION_ERROR;
|
||||
status = U_MEMORY_ALLOCATION_ERROR;
|
||||
return;
|
||||
}
|
||||
}
|
||||
#ifdef U_DEBUG_CALSVC
|
||||
fprintf(stderr, "Registering classes..\n");
|
||||
fprintf(stderr, "Registering classes..\n");
|
||||
#endif
|
||||
|
||||
// Register all basic instances.
|
||||
// Register all basic instances.
|
||||
gService->registerFactory(new BasicCalendarFactory(),status);
|
||||
|
||||
#ifdef U_DEBUG_CALSVC
|
||||
fprintf(stderr, "Done..\n");
|
||||
fprintf(stderr, "Done..\n");
|
||||
#endif
|
||||
|
||||
if(U_FAILURE(status)) {
|
||||
if(U_FAILURE(status)) {
|
||||
#ifdef U_DEBUG_CALSVC
|
||||
fprintf(stderr, "err (%s) registering classes, deleting service.....\n", u_errorName(status));
|
||||
fprintf(stderr, "err (%s) registering classes, deleting service.....\n", u_errorName(status));
|
||||
#endif
|
||||
delete gService;
|
||||
gService = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static ICULocaleService*
|
||||
getCalendarService(UErrorCode &status)
|
||||
|
@ -573,7 +575,6 @@ getCalendarService(UErrorCode &status)
|
|||
return gService;
|
||||
}
|
||||
|
||||
|
||||
URegistryKey Calendar::registerFactory(ICUServiceFactory* toAdopt, UErrorCode& status)
|
||||
{
|
||||
return getCalendarService(status)->registerFactory(toAdopt, status);
|
||||
|
@ -3693,3 +3694,4 @@ U_NAMESPACE_END
|
|||
|
||||
|
||||
//eof
|
||||
|
||||
|
|
|
@ -80,9 +80,11 @@ U_NAMESPACE_BEGIN
|
|||
const char *IslamicCalendar::getType() const {
|
||||
if(civil==CIVIL) {
|
||||
return "islamic-civil";
|
||||
} else {
|
||||
} else if(civil==ASTRONOMICAL){
|
||||
return "islamic";
|
||||
}
|
||||
} else {
|
||||
return "islamic-umalqura";
|
||||
}
|
||||
}
|
||||
|
||||
Calendar* IslamicCalendar::clone() const {
|
||||
|
@ -195,12 +197,21 @@ UBool IslamicCalendar::civilLeapYear(int32_t year)
|
|||
* Return the day # on which the given year starts. Days are counted
|
||||
* from the Hijri epoch, origin 0.
|
||||
*/
|
||||
int32_t IslamicCalendar::yearStart(int32_t year) {
|
||||
if (civil == CIVIL) {
|
||||
int32_t IslamicCalendar::yearStart(int32_t year) const{
|
||||
if (civil == CIVIL ||
|
||||
(civil == UMALQURA && year < UMALQURA_YEAR_START))
|
||||
{
|
||||
return (year-1)*354 + ClockMath::floorDivide((3+11*year),30);
|
||||
} else {
|
||||
} else if(civil==ASTRONOMICAL){
|
||||
return trueMonthStart(12*(year-1));
|
||||
}
|
||||
} else {
|
||||
int32_t ys = yearStart(UMALQURA_YEAR_START-1);
|
||||
ys+= handleGetYearLength(UMALQURA_YEAR_START-1);
|
||||
for(int i=UMALQURA_YEAR_START; i< year; i++){
|
||||
ys+= handleGetYearLength(i);
|
||||
}
|
||||
return ys;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -214,9 +225,15 @@ int32_t IslamicCalendar::monthStart(int32_t year, int32_t month) const {
|
|||
if (civil == CIVIL) {
|
||||
return (int32_t)uprv_ceil(29.5*month)
|
||||
+ (year-1)*354 + (int32_t)ClockMath::floorDivide((3+11*year),30);
|
||||
} else {
|
||||
} else if(civil==ASTRONOMICAL){
|
||||
return trueMonthStart(12*(year-1) + month);
|
||||
}
|
||||
} else {
|
||||
int32_t ms = yearStart(year);
|
||||
for(int i=0; i< month; i++){
|
||||
ms+= handleGetMonthLength(year, i);
|
||||
}
|
||||
return ms;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -323,15 +340,18 @@ int32_t IslamicCalendar::handleGetMonthLength(int32_t extendedYear, int32_t mont
|
|||
|
||||
int32_t length = 0;
|
||||
|
||||
if (civil == CIVIL) {
|
||||
if (civil == CIVIL ||
|
||||
(civil == UMALQURA && (extendedYear<UMALQURA_YEAR_START || extendedYear>UMALQURA_YEAR_END)) ) {
|
||||
length = 29 + (month+1) % 2;
|
||||
if (month == DHU_AL_HIJJAH && civilLeapYear(extendedYear)) {
|
||||
length++;
|
||||
}
|
||||
} else {
|
||||
} else if(civil == ASTRONOMICAL){
|
||||
month = 12*(extendedYear-1) + month;
|
||||
length = trueMonthStart(month+1) - trueMonthStart(month) ;
|
||||
}
|
||||
} else {
|
||||
length = getUmalqura_MonthLength(extendedYear - UMALQURA_YEAR_START, month);
|
||||
}
|
||||
return length;
|
||||
}
|
||||
|
||||
|
@ -340,12 +360,18 @@ int32_t IslamicCalendar::handleGetMonthLength(int32_t extendedYear, int32_t mont
|
|||
* @draft ICU 2.4
|
||||
*/
|
||||
int32_t IslamicCalendar::handleGetYearLength(int32_t extendedYear) const {
|
||||
if (civil == CIVIL) {
|
||||
if (civil == CIVIL ||
|
||||
(civil == UMALQURA && (extendedYear<UMALQURA_YEAR_START || extendedYear>UMALQURA_YEAR_END)) ) {
|
||||
return 354 + (civilLeapYear(extendedYear) ? 1 : 0);
|
||||
} else {
|
||||
} else if(civil == ASTRONOMICAL){
|
||||
int32_t month = 12*(extendedYear-1);
|
||||
return (trueMonthStart(month + 12) - trueMonthStart(month));
|
||||
}
|
||||
} else {
|
||||
int len = 0;
|
||||
for(int i=0; i<12; i++)
|
||||
len += handleGetMonthLength(extendedYear, i);
|
||||
return len;
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
|
@ -404,7 +430,7 @@ void IslamicCalendar::handleComputeFields(int32_t julianDay, UErrorCode &status)
|
|||
month = (int32_t)uprv_ceil((days - 29 - yearStart(year)) / 29.5 );
|
||||
month = month<11?month:11;
|
||||
startDate = monthStart(year, month);
|
||||
} else {
|
||||
} else if(civil == ASTRONOMICAL){
|
||||
// Guess at the number of elapsed full months since the epoch
|
||||
int32_t months = (int32_t)uprv_floor((double)days / CalendarAstronomer::SYNODIC_MONTH);
|
||||
|
||||
|
@ -429,12 +455,44 @@ void IslamicCalendar::handleComputeFields(int32_t julianDay, UErrorCode &status)
|
|||
|
||||
year = months / 12 + 1;
|
||||
month = months % 12;
|
||||
}
|
||||
} else if(civil == UMALQURA){
|
||||
int32_t umalquraStartdays = yearStart(UMALQURA_YEAR_START) ;
|
||||
if( days < umalquraStartdays){
|
||||
//Use Civil calculation
|
||||
year = (int)ClockMath::floorDivide( (double)(30 * days + 10646) , 10631.0 );
|
||||
month = (int32_t)uprv_ceil((days - 29 - yearStart(year)) / 29.5 );
|
||||
month = month<11?month:11;
|
||||
startDate = monthStart(year, month);
|
||||
}else{
|
||||
int y =UMALQURA_YEAR_START-1, m =0;
|
||||
long d = 1;
|
||||
while(d > 0){
|
||||
y++;
|
||||
d = days - yearStart(y) +1;
|
||||
if(d == handleGetYearLength(y)){
|
||||
m=11;
|
||||
break;
|
||||
}else if(d < handleGetYearLength(y) ){
|
||||
int monthLen = handleGetMonthLength(y, m);
|
||||
m=0;
|
||||
while(d > monthLen){
|
||||
d -= monthLen;
|
||||
m++;
|
||||
monthLen = handleGetMonthLength(y, m);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
year = y;
|
||||
month = m;
|
||||
}
|
||||
}
|
||||
|
||||
dayOfMonth = (days - monthStart(year, month)) + 1;
|
||||
dayOfMonth = (days - monthStart(year, month)) + 1;
|
||||
|
||||
// Now figure out the day of the year.
|
||||
dayOfYear = (days - monthStart(year, 0) + 1);
|
||||
// Now figure out the day of the year.
|
||||
dayOfYear = (days - monthStart(year, 0) + 1);
|
||||
|
||||
|
||||
internalSet(UCAL_ERA, 0);
|
||||
internalSet(UCAL_YEAR, year);
|
||||
|
@ -466,12 +524,29 @@ static UDate gSystemDefaultCenturyStart = DBL_MIN;
|
|||
static int32_t gSystemDefaultCenturyStartYear = -1;
|
||||
static UInitOnce gSystemDefaultCenturyInit = U_INITONCE_INITIALIZER;
|
||||
|
||||
|
||||
UBool IslamicCalendar::haveDefaultCentury() const
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void U_CALLCONV initializeSystemDefaultCentury()
|
||||
UDate IslamicCalendar::defaultCenturyStart() const
|
||||
{
|
||||
// lazy-evaluate systemDefaultCenturyStart
|
||||
umtx_initOnce(gSystemDefaultCenturyInit, &initializeSystemDefaultCentury);
|
||||
return gSystemDefaultCenturyStart;
|
||||
}
|
||||
|
||||
int32_t IslamicCalendar::defaultCenturyStartYear() const
|
||||
{
|
||||
// lazy-evaluate systemDefaultCenturyStartYear
|
||||
umtx_initOnce(gSystemDefaultCenturyInit, &initializeSystemDefaultCentury);
|
||||
return gSystemDefaultCenturyStartYear;
|
||||
}
|
||||
|
||||
|
||||
void U_CALLCONV
|
||||
IslamicCalendar::initializeSystemDefaultCentury()
|
||||
{
|
||||
// initialize systemDefaultCentury and systemDefaultCenturyYear based
|
||||
// on the current time. They'll be set to 80 years before
|
||||
|
@ -483,23 +558,12 @@ static void U_CALLCONV initializeSystemDefaultCentury()
|
|||
calendar.add(UCAL_YEAR, -80, status);
|
||||
|
||||
gSystemDefaultCenturyStart = calendar.getTime(status);
|
||||
gSystemDefaultCenturyStartYear = calendar.get(UCAL_YEAR, status);
|
||||
gSystemDefaultCenturyStartYear = calendar.get(UCAL_YEAR, status);
|
||||
}
|
||||
// We have no recourse upon failure unless we want to propagate the failure
|
||||
// out.
|
||||
}
|
||||
|
||||
UDate IslamicCalendar::defaultCenturyStart() const {
|
||||
// lazy-evaluate systemDefaultCenturyStart
|
||||
umtx_initOnce(gSystemDefaultCenturyInit, &initializeSystemDefaultCentury);
|
||||
return gSystemDefaultCenturyStart;
|
||||
}
|
||||
|
||||
int32_t IslamicCalendar::defaultCenturyStartYear() const {
|
||||
// lazy-evaluate systemDefaultCenturyStartYear
|
||||
umtx_initOnce(gSystemDefaultCenturyInit, &initializeSystemDefaultCentury);
|
||||
return gSystemDefaultCenturyStartYear;
|
||||
}
|
||||
|
||||
|
||||
UOBJECT_DEFINE_RTTI_IMPLEMENTATION(IslamicCalendar)
|
||||
|
|
|
@ -81,18 +81,20 @@ U_NAMESPACE_BEGIN
|
|||
* @author Steven R. Loomis
|
||||
* @internal
|
||||
*/
|
||||
class IslamicCalendar : public Calendar {
|
||||
class U_I18N_API IslamicCalendar : public Calendar {
|
||||
public:
|
||||
//-------------------------------------------------------------------------
|
||||
// Constants...
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Calendar type - civil or religious
|
||||
* Calendar type - civil or religious or um alqura
|
||||
* @internal
|
||||
*/
|
||||
enum ECivil {
|
||||
ASTRONOMICAL,
|
||||
CIVIL
|
||||
CIVIL,
|
||||
UMALQURA
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -239,7 +241,7 @@ class IslamicCalendar : public Calendar {
|
|||
* Return the day # on which the given year starts. Days are counted
|
||||
* from the Hijri epoch, origin 0.
|
||||
*/
|
||||
int32_t yearStart(int32_t year);
|
||||
int32_t yearStart(int32_t year) const;
|
||||
|
||||
/**
|
||||
* Return the day # on which the given month starts. Days are counted
|
||||
|
@ -363,7 +365,7 @@ class IslamicCalendar : public Calendar {
|
|||
* @return The class ID for all objects of this class.
|
||||
* @internal
|
||||
*/
|
||||
U_I18N_API static UClassID U_EXPORT2 getStaticClassID(void);
|
||||
/*U_I18N_API*/ static UClassID U_EXPORT2 getStaticClassID(void);
|
||||
|
||||
/**
|
||||
* return the calendar type, "buddhist".
|
||||
|
@ -409,6 +411,133 @@ class IslamicCalendar : public Calendar {
|
|||
* @internal
|
||||
*/
|
||||
virtual int32_t defaultCenturyStartYear() const;
|
||||
|
||||
private: // default century stuff.
|
||||
/**
|
||||
* The system maintains a static default century start date. This is initialized
|
||||
* the first time it is used. Before then, it is set to SYSTEM_DEFAULT_CENTURY to
|
||||
* indicate an uninitialized state. Once the system default century date and year
|
||||
* are set, they do not change.
|
||||
*/
|
||||
static UDate fgSystemDefaultCenturyStart;
|
||||
|
||||
/**
|
||||
* See documentation for systemDefaultCenturyStart.
|
||||
*/
|
||||
static int32_t fgSystemDefaultCenturyStartYear;
|
||||
|
||||
|
||||
/**
|
||||
* Default value that indicates the defaultCenturyStartYear is unitialized
|
||||
*/
|
||||
static const int32_t fgSystemDefaultCenturyYear;
|
||||
|
||||
/**
|
||||
* start of default century, as a date
|
||||
*/
|
||||
static const UDate fgSystemDefaultCentury;
|
||||
|
||||
static const int32_t UMALQURA_YEAR_START = 1318;
|
||||
static const int32_t UMALQURA_YEAR_END = 1480;
|
||||
|
||||
|
||||
static const int getUmalqura_MonthLength(int i, int j){
|
||||
|
||||
static const int UMALQURA_MONTHLENGTH[] = {
|
||||
//* 1318 -1322 */ "0101 0111 0100", "1001 0111 0110", "0100 1011 0111", "0010 0101 0111", "0101 0010 1011",
|
||||
0x0574, 0x0975, 0x06A7, 0x0257, 0x052B,
|
||||
//* 1323 -1327 */ "0110 1001 0101", "0110 1100 1010", "1010 1101 0101", "0101 0101 1011", "0010 0101 1101",
|
||||
0x0695, 0x06CA, 0x0AD5, 0x055B, 0x025B,
|
||||
//* 1328 -1332 */ "1001 0010 1101", "1100 1001 0101", "1101 0100 1010", "1110 1010 0101", "0110 1101 0010",
|
||||
0x092D, 0x0C95, 0x0D4A, 0x0E5B, 0x025B,
|
||||
//* 1333 -1337 */ "1010 1101 0101", "0101 0101 1010", "1010 1010 1011", "0100 0100 1011", "0110 1010 0101",
|
||||
0x0AD5, 0x055A, 0x0AAB, 0x044B, 0x06A5,
|
||||
//* 1338 -1342 */ "0111 0101 0010", "1011 1010 1001", "0011 0111 0100", "1010 1011 0110", "0101 0101 0110",
|
||||
0x0752, 0x0BA9, 0x0374, 0x0AB6, 0x0556,
|
||||
//* 1343 -1347 */ "1010 1010 1010", "1101 0101 0010", "1101 1010 1001", "0101 1101 0100", "1010 1110 1010",
|
||||
0x0AAA, 0x0D52, 0x0DA9, 0x05D4, 0x0AEA,
|
||||
//* 1348 -1352 */ "0100 1101 1101", "0010 0110 1110", "1001 0010 1110", "1010 1010 0110", "1101 0101 0100",
|
||||
0x04DD, 0x026E, 0x092E, 0x0AA6, 0x0D54,
|
||||
//* 1353 -1357 */ "0101 1010 1010", "0101 1011 0101", "0010 1011 0100", "1001 0011 0111", "0100 1001 1011",
|
||||
0x05AA, 0x05B5, 0x02B4, 0x0937, 0x049B,
|
||||
//* 1358 -1362 */ "1010 0100 1011", "1011 0010 0101", "1011 0101 0100", "1011 0110 1010", "0101 0110 1101",
|
||||
0x0A4B, 0x0B25, 0x0B54, 0x0B6A, 0x056D,
|
||||
//* 1363 -1367 */ "0100 1010 1101", "1010 0101 0101", "1101 0010 0101", "1110 1001 0010", "1110 1100 1001",
|
||||
0x04AD, 0x0A55, 0x0D25, 0x0E92, 0x0EC9,
|
||||
//* 1368 -1372 */ "0110 1101 0100", "1010 1110 1010", "0101 0110 1011", "0100 1010 1011", "0110 1000 0101",
|
||||
0x06D4, 0x0ADA, 0x056B, 0x04AB, 0x0685,
|
||||
//* 1373 -1377 */ "1011 0100 1001", "1011 1010 0100", "1011 1011 0010", "0101 1011 0101", "0010 1011 1010",
|
||||
0x0B49, 0x0BA4, 0x0BB2, 0x05B5, 0x02BA,
|
||||
//* 1378 -1382 */ "1001 0101 1011", "0100 1010 1011", "0101 0101 0101", "0110 1011 0010", "0110 1101 1001",
|
||||
0x095B, 0x04AB, 0x0555, 0x06B2, 0x06D9,
|
||||
//* 1383 -1387 */ "0010 1110 1100", "1001 0110 1110", "0100 1010 1110", "1010 0101 0110", "1101 0010 1010",
|
||||
0x02EC, 0x096E, 0x04AE, 0x0A56, 0x0D2A,
|
||||
//* 1388 -1392 */ "1101 0101 0101", "0101 1010 1010", "1010 1011 0101", "0100 1011 1011", "0000 0101 1011",
|
||||
0x0D55, 0x05AA, 0x0AB5, 0x04BB, 0x005B,
|
||||
//* 1393 -1397 */ "1001 0010 1011", "1010 1001 0101", "0011 0100 1010", "1011 1010 0101", "0101 1010 1010",
|
||||
0x092B, 0x0A95, 0x034A, 0x0BA5, 0x05AA,
|
||||
//* 1398 -1402 */ "1010 1011 0101", "0101 0101 0110", "1010 1001 0110", "1101 0100 1010", "1110 1010 0101",
|
||||
0x0AB5, 0x0556, 0x0A96, 0x0B4A, 0x0EA5,
|
||||
//* 1403 -1407 */ "0111 0101 0010", "0110 1110 1001", "0011 0110 1010", "1010 1010 1101", "0101 0101 0101",
|
||||
0x0752, 0x06E9, 0x036A, 0x0AAD, 0x0555,
|
||||
//* 1408 -1412 */ "1010 1010 0101", "1011 0101 0010", "1011 1010 1001", "0101 1011 0100", "1001 1011 1010",
|
||||
0x0AA5, 0x0B52, 0x0BA9, 0x05B4, 0x09BA,
|
||||
//* 1413 -1417 */ "0100 1101 1011", "0010 0101 1101", "0101 0010 1101", "1010 1010 0101", "1010 1101 0100",
|
||||
0x04DB, 0x025D, 0x052D, 0x0AA5, 0x0AD4,
|
||||
//* 1418 -1422 */ "1010 1110 1010", "0101 0110 1101", "0100 1011 1101", "0010 0011 1101", "1001 0001 1101",
|
||||
0x0AEA, 0x056D, 0x04BD, 0x023D, 0x091D,
|
||||
//* 1423 -1427 */ "1010 1001 0101", "1011 0100 1010", "1011 0101 1010", "0101 0110 1101", "0010 1011 0110",
|
||||
0x0A95, 0x0B4A, 0x0B5A, 0x056D, 0x02B6,
|
||||
//* 1428 -1432 */ "1001 0011 1011", "0100 1001 1011", "0110 0101 0101", "0110 1010 1001", "0111 0101 0100",
|
||||
0x093B, 0x049B, 0x0655, 0x06A9, 0x0754,
|
||||
//* 1433 -1437 */ "1011 0110 1010", "0101 0110 1100", "1010 1010 1101", "0101 0101 0101", "1011 0010 1001",
|
||||
0x0B6A, 0x056C, 0x0AAD, 0x0555, 0x0B29,
|
||||
//* 1438 -1442 */ "1011 1001 0010", "1011 1010 1001", "0101 1101 0100", "1010 1101 1010", "0101 0101 1010",
|
||||
0x0B92, 0x0BA9, 0x05D4, 0x0ADA, 0x055A,
|
||||
//* 1443 -1447 */ "1010 1010 1011", "0101 1001 0101", "0111 0100 1001", "0111 0110 0100", "1011 1010 1010",
|
||||
0x0AAB, 0x0595, 0x0749, 0x0764, 0x0BAA,
|
||||
//* 1448 -1452 */ "0101 1011 0101", "0010 1011 0110", "1010 0101 0110", "1110 0100 1101", "1011 0010 0101",
|
||||
0x05B5, 0x02B6, 0x0A56, 0x0E4D, 0x0B25,
|
||||
//* 1453 -1457 */ "1011 0101 0010", "1011 0110 1010", "0101 1010 1101", "0010 1010 1110", "1001 0010 1111",
|
||||
0x0B52, 0x0B6A, 0x05AD, 0x02AE, 0x092F,
|
||||
//* 1458 -1462 */ "0100 1001 0111", "0110 0100 1011", "0110 1010 0101", "0110 1010 1100", "1010 1101 0110",
|
||||
0x0497, 0x064B, 0x06A5, 0x06AC, 0x0AD6,
|
||||
//* 1463 -1467 */ "0101 0101 1101", "0100 1001 1101", "1010 0100 1101", "1101 0001 0110", "1101 1001 0101",
|
||||
0x055D, 0x049D, 0x0A4D, 0x0D16, 0x0D95,
|
||||
//* 1468 -1472 */ "0101 1010 1010", "0101 1011 0101", "0010 1001 1010", "1001 0101 1011", "0100 1010 1100",
|
||||
0x05AA, 0x05B5, 0x029A, 0x095B, 0x04AC,
|
||||
//* 1473 -1477 */ "0101 1001 0101", "0110 1100 1010", "0110 1110 0100", "1010 1110 1010", "0100 1111 0101",
|
||||
0x0595, 0x06CA, 0x06E4, 0x0AEA, 0x04F5,
|
||||
//* 1478 -1480 */ "0010 1011 0110", "1001 0101 0110", "1010 1010 1010"
|
||||
0x02B6, 0x0956, 0x0AAA
|
||||
};
|
||||
|
||||
int mask = (int) (0x01 << (11 - j)); // set mask for bit corresponding to month
|
||||
if((UMALQURA_MONTHLENGTH[i] & mask) == 0 )
|
||||
return 29;
|
||||
else
|
||||
return 30;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the beginning date of the 100-year window that dates
|
||||
* with 2-digit years are considered to fall within.
|
||||
*/
|
||||
UDate internalGetDefaultCenturyStart(void) const;
|
||||
|
||||
/**
|
||||
* Returns the first year of the 100-year window that dates with
|
||||
* 2-digit years are considered to fall within.
|
||||
*/
|
||||
int32_t internalGetDefaultCenturyStartYear(void) const;
|
||||
|
||||
/**
|
||||
* Initializes the 100-year window that dates with 2-digit years
|
||||
* are considered to fall within so that its start date is 80 years
|
||||
* before the current time.
|
||||
*/
|
||||
static void initializeSystemDefaultCentury(void);
|
||||
};
|
||||
|
||||
U_NAMESPACE_END
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include "unicode/ustring.h"
|
||||
#include "cstring.h"
|
||||
#include "unicode/localpointer.h"
|
||||
#include "islamcal.h"
|
||||
|
||||
#define mkcstr(U) u_austrcpy(calloc(8, u_strlen(U) + 1), U)
|
||||
|
||||
|
@ -278,6 +279,13 @@ void CalendarTest::runIndexedTest( int32_t index, UBool exec, const char* &name,
|
|||
logln("TestCloneLocale---"); logln("");
|
||||
TestCloneLocale();
|
||||
}
|
||||
break;
|
||||
case 31:
|
||||
name = "Test8449";
|
||||
if(exec) {
|
||||
logln("Test8449---"); logln("");
|
||||
Test8449();
|
||||
}
|
||||
break;
|
||||
default: name = ""; break;
|
||||
}
|
||||
|
@ -334,18 +342,12 @@ CalendarTest::TestGenericAPI()
|
|||
|
||||
SimpleTimeZone *zone = new SimpleTimeZone(tzoffset, tzid);
|
||||
Calendar *cal = Calendar::createInstance(zone->clone(), status);
|
||||
if (U_FAILURE(status)) {
|
||||
dataerrln(UnicodeString("FAIL: Calendar::createInstance with SimpleTimeZone::clone() failed, error ") + u_errorName(status));
|
||||
return;
|
||||
}
|
||||
if (failure(status, "Calendar::createInstance", TRUE)) return;
|
||||
|
||||
if (*zone != cal->getTimeZone()) errln("FAIL: Calendar::getTimeZone failed");
|
||||
|
||||
Calendar *cal2 = Calendar::createInstance(cal->getTimeZone(), status);
|
||||
if (U_FAILURE(status)) {
|
||||
errln(UnicodeString("FAIL: Calendar::createInstance with Calendar::getTimeZone() failed, error ") + u_errorName(status));
|
||||
return;
|
||||
}
|
||||
if (failure(status, "Calendar::createInstance")) return;
|
||||
cal->setTime(when, status);
|
||||
cal2->setTime(when, status);
|
||||
if (failure(status, "Calendar::setTime")) return;
|
||||
|
@ -490,26 +492,17 @@ CalendarTest::TestGenericAPI()
|
|||
for (i=0; i<count; ++i)
|
||||
{
|
||||
cal = Calendar::createInstance(loc[i], status);
|
||||
if (U_FAILURE(status)) {
|
||||
errln(UnicodeString("FAIL: Calendar::createInstance with Locale ") + loc[i].getName() + " failed, error " + u_errorName(status));
|
||||
return;
|
||||
}
|
||||
if (failure(status, "Calendar::createInstance")) return;
|
||||
delete cal;
|
||||
}
|
||||
}
|
||||
|
||||
cal = Calendar::createInstance(TimeZone::createDefault(), Locale::getEnglish(), status);
|
||||
if (U_FAILURE(status)) {
|
||||
errln(UnicodeString("FAIL: Calendar::createInstance with TimeZone::createDefault() for English failed, error ") + u_errorName(status));
|
||||
return;
|
||||
}
|
||||
if (failure(status, "Calendar::createInstance")) return;
|
||||
delete cal;
|
||||
|
||||
cal = Calendar::createInstance(*zone, Locale::getEnglish(), status);
|
||||
if (U_FAILURE(status)) {
|
||||
errln(UnicodeString("FAIL: Calendar::createInstance with Calendar::getTimeZone() for English failed, error ") + u_errorName(status));
|
||||
return;
|
||||
}
|
||||
if (failure(status, "Calendar::createInstance")) return;
|
||||
delete cal;
|
||||
|
||||
GregorianCalendar *gc = new GregorianCalendar(*zone, status);
|
||||
|
@ -2731,6 +2724,128 @@ void CalendarTest::TestCloneLocale(void) {
|
|||
TEST_CHECK_STATUS;
|
||||
}
|
||||
|
||||
void CalendarTest::setAndTestCalendar(Calendar* cal, int32_t initMonth, int32_t initDay, int32_t initYear, UErrorCode& status) {
|
||||
cal->clear();
|
||||
cal->setLenient(FALSE);
|
||||
cal->set(initYear, initMonth, initDay);
|
||||
int32_t day = cal->get(UCAL_DAY_OF_MONTH, status);
|
||||
int32_t month = cal->get(UCAL_MONTH, status);
|
||||
int32_t year = cal->get(UCAL_YEAR, status);
|
||||
if(U_FAILURE(status))
|
||||
return;
|
||||
|
||||
if(initDay != day || initMonth != month || initYear != year)
|
||||
{
|
||||
errln(" year init values:\tmonth %i\tday %i\tyear %i", initMonth, initDay, initYear);
|
||||
errln("values post set():\tmonth %i\tday %i\tyear %i",month, day, year);
|
||||
}
|
||||
}
|
||||
|
||||
void CalendarTest::setAndTestWholeYear(Calendar* cal, int32_t startYear, UErrorCode& status) {
|
||||
for(int32_t startMonth = 0; startMonth < 12; startMonth++) {
|
||||
for(int32_t startDay = 1; startDay < 31; startDay++ ) {
|
||||
setAndTestCalendar(cal, startMonth, startDay, startYear, status);
|
||||
if(U_FAILURE(status) && startDay == 30) {
|
||||
status = U_ZERO_ERROR;
|
||||
continue;
|
||||
}
|
||||
TEST_CHECK_STATUS;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CalendarTest::Test8449() {
|
||||
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
Locale islamicLoc("ar_SA@calendar=islamic-umalqura");
|
||||
Calendar* tstCal = Calendar::createInstance(islamicLoc, status);
|
||||
|
||||
IslamicCalendar* iCal = (IslamicCalendar*)tstCal;
|
||||
if(strcmp(iCal->getType(), "islamic-umalqura") != 0) {
|
||||
errln("wrong type of calendar created - %s", iCal->getType());
|
||||
}
|
||||
|
||||
|
||||
int32_t firstYear = 1318;
|
||||
//* use either 1 or 2 leading slashes to toggle
|
||||
int32_t lastYear = 1368; // just enough to be pretty sure
|
||||
/*/
|
||||
int32_t lastYear = 1480; // the whole shootin' match
|
||||
//*/
|
||||
|
||||
tstCal->clear();
|
||||
tstCal->setLenient(FALSE);
|
||||
|
||||
int32_t day=0, month=0, year=0, initDay = 27, initMonth = IslamicCalendar::RAJAB, initYear = 1434;
|
||||
|
||||
for( int32_t startYear = firstYear; startYear <= lastYear; startYear++) {
|
||||
setAndTestWholeYear(tstCal, startYear, status);
|
||||
status = U_ZERO_ERROR;
|
||||
}
|
||||
|
||||
initMonth = IslamicCalendar::RABI_2;
|
||||
initDay = 5;
|
||||
int32_t loopCnt = 25;
|
||||
tstCal->clear();
|
||||
setAndTestCalendar( tstCal, initMonth, initDay, initYear, status);
|
||||
TEST_CHECK_STATUS;
|
||||
|
||||
for(int x=1; x<=loopCnt; x++) {
|
||||
day = tstCal->get(UCAL_DAY_OF_MONTH,status);
|
||||
month = tstCal->get(UCAL_MONTH,status);
|
||||
year = tstCal->get(UCAL_YEAR,status);
|
||||
TEST_CHECK_STATUS;
|
||||
tstCal->roll(UCAL_DAY_OF_MONTH, TRUE, status);
|
||||
TEST_CHECK_STATUS;
|
||||
}
|
||||
|
||||
if(day != (initDay + loopCnt - 1) || month != IslamicCalendar::RABI_2 || year != 1434)
|
||||
errln("invalid values for RABI_2 date after roll of " + loopCnt);
|
||||
|
||||
|
||||
status = U_ZERO_ERROR;
|
||||
tstCal->clear();
|
||||
initMonth = 2;
|
||||
initDay = 30;
|
||||
setAndTestCalendar( tstCal, initMonth, initDay, initYear, status);
|
||||
if(U_SUCCESS(status)) {
|
||||
errln("error NOT detected status %i",status);
|
||||
errln(" init values:\tmonth %i\tday %i\tyear %i", initMonth, initDay, initYear);
|
||||
int32_t day = tstCal->get(UCAL_DAY_OF_MONTH, status);
|
||||
int32_t month = tstCal->get(UCAL_MONTH, status);
|
||||
int32_t year = tstCal->get(UCAL_YEAR, status);
|
||||
errln("values post set():\tmonth %i\tday %i\tyear %i",month, day, year);
|
||||
}
|
||||
|
||||
status = U_ZERO_ERROR;
|
||||
tstCal->clear();
|
||||
initMonth = 3;
|
||||
initDay = 30;
|
||||
setAndTestCalendar( tstCal, initMonth, initDay, initYear, status);
|
||||
TEST_CHECK_STATUS;
|
||||
|
||||
SimpleDateFormat* formatter = new SimpleDateFormat("yyyy-MM-dd", Locale::getUS(), status);
|
||||
UDate date = formatter->parse("1975-05-06", status);
|
||||
Calendar* is_cal = Calendar::createInstance(islamicLoc, status);
|
||||
is_cal->setTime(date, status);
|
||||
int32_t is_day = is_cal->get(UCAL_DAY_OF_MONTH,status);
|
||||
int32_t is_month = is_cal->get(UCAL_MONTH,status);
|
||||
int32_t is_year = is_cal->get(UCAL_YEAR,status);
|
||||
TEST_CHECK_STATUS;
|
||||
if(is_day != 29 || is_month != IslamicCalendar::RABI_2 || is_year != 1395)
|
||||
errln("unexpected conversion date month %i not %i or day %i not 20 or year %i not 1395", is_month, IslamicCalendar::RABI_2, is_day, is_year);
|
||||
|
||||
UDate date2 = is_cal->getTime(status);
|
||||
TEST_CHECK_STATUS;
|
||||
if(date2 != date) {
|
||||
errln("before(%f) and after(%f) dates don't match up!",date, date2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif /* #if !UCONFIG_NO_FORMATTING */
|
||||
|
||||
//eof
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/***********************************************************************
|
||||
* Copyright (c) 1997-2012, International Business Machines Corporation
|
||||
* Copyright (c) 1997-2013, International Business Machines Corporation
|
||||
* and others. All Rights Reserved.
|
||||
***********************************************************************/
|
||||
|
||||
|
@ -219,6 +219,7 @@ public: // package
|
|||
void Test6703(void);
|
||||
void Test3785(void);
|
||||
void Test1624(void);
|
||||
void Test8449(void);
|
||||
|
||||
/**
|
||||
* Test the time stamp array recalculation during heavy Calendar usage
|
||||
|
@ -237,6 +238,13 @@ public: // package
|
|||
void TestSkippedWallTime(void);
|
||||
|
||||
void TestCloneLocale(void);
|
||||
|
||||
/*
|
||||
* utility methods for Test8449
|
||||
*/
|
||||
void CalendarTest::setAndTestCalendar(Calendar* cal, int32_t initMonth, int32_t initDay, int32_t initYear, UErrorCode& status);
|
||||
void CalendarTest::setAndTestWholeYear(Calendar* cal, int32_t startYear, UErrorCode& status);
|
||||
|
||||
};
|
||||
|
||||
#endif /* #if !UCONFIG_NO_FORMATTING */
|
||||
|
|
Loading…
Add table
Reference in a new issue