Frank Tang | 3e05d9d | 2021-11-08 14:04:04 -0800 | [diff] [blame^] | 1 | // © 2016 and later: Unicode, Inc. and others. |
| 2 | // License & terms of use: http://www.unicode.org/copyright.html |
| 3 | /******************************************************************** |
| 4 | * COPYRIGHT: |
| 5 | * Copyright (c) 2003-2013, International Business Machines Corporation |
| 6 | * and others. All Rights Reserved. |
| 7 | ******************************************************************** |
| 8 | * Calendar Case Test is a type of CalendarTest which compares the |
| 9 | * behavior of a calendar to a certain set of 'test cases', involving |
| 10 | * conversion between julian-day to fields and vice versa. |
| 11 | ********************************************************************/ |
| 12 | |
| 13 | #include "calcasts.h" |
| 14 | |
| 15 | #if !UCONFIG_NO_FORMATTING |
| 16 | // ======= 'Main' =========================== |
| 17 | |
| 18 | #include "hebrwcal.h" // for Eras |
| 19 | #include "indiancal.h" |
| 20 | #include "coptccal.h" |
| 21 | #include "ethpccal.h" |
| 22 | #include "unicode/datefmt.h" |
| 23 | |
| 24 | #define CASE(id,test) case id: name = #test; if (exec) { logln(#test "---"); logln((UnicodeString)""); test(); } break |
| 25 | |
| 26 | |
| 27 | void CalendarCaseTest::runIndexedTest( int32_t index, UBool exec, const char* &name, char* /*par*/ ) |
| 28 | { |
| 29 | if (exec) logln("TestSuite CalendarCaseTest"); |
| 30 | switch (index) { |
| 31 | CASE(0,IslamicCivil); |
| 32 | CASE(1,Hebrew); |
| 33 | CASE(2,Indian); |
| 34 | CASE(3,Coptic); |
| 35 | CASE(4,Ethiopic); |
| 36 | default: name = ""; break; |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | #undef CASE |
| 41 | |
| 42 | // ======= Utility functions ================= |
| 43 | |
| 44 | void CalendarCaseTest::doTestCases(const TestCase *cases, Calendar *cal) { |
| 45 | static const int32_t ONE_SECOND = 1000; |
| 46 | static const int32_t ONE_MINUTE = 60*ONE_SECOND; |
| 47 | static const int32_t ONE_HOUR = 60*ONE_MINUTE; |
| 48 | static const double ONE_DAY = 24*ONE_HOUR; |
| 49 | static const double JULIAN_EPOCH = -210866760000000.; // 1/1/4713 BC 12:00 |
| 50 | int32_t i; |
| 51 | UErrorCode status = U_ZERO_ERROR; |
| 52 | cal->adoptTimeZone(TimeZone::getGMT()->clone()); |
| 53 | for(i=0;cases[i].era>=0;i++) { |
| 54 | UDate t = (JULIAN_EPOCH+(ONE_DAY*cases[i].julian)); |
| 55 | |
| 56 | logln("Test case %d: julianday%f -> date %f\n", i, cases[i].julian, t); |
| 57 | |
| 58 | // Millis -> fields |
| 59 | cal->setTime(t, status); |
| 60 | |
| 61 | logln(calToStr(*cal)); |
| 62 | |
| 63 | checkField(cal, UCAL_ERA, cases[i].era, status); |
| 64 | checkField(cal, UCAL_YEAR, cases[i].year,status); |
| 65 | checkField(cal, UCAL_MONTH, cases[i].month - 1,status); |
| 66 | checkField(cal, UCAL_DATE, cases[i].day,status); |
| 67 | checkField(cal, UCAL_DAY_OF_WEEK, cases[i].dayOfWeek,status); |
| 68 | checkField(cal, UCAL_HOUR, cases[i].hour,status); |
| 69 | checkField(cal, UCAL_MINUTE, cases[i].min,status); |
| 70 | checkField(cal, UCAL_SECOND, cases[i].sec,status); |
| 71 | |
| 72 | // Fields -> millis |
| 73 | cal->clear(); |
| 74 | |
| 75 | cal->set(UCAL_ERA, cases[i].era); |
| 76 | cal->set(UCAL_YEAR, cases[i].year); |
| 77 | cal->set(UCAL_MONTH, cases[i].month - 1); |
| 78 | cal->set(UCAL_DATE, cases[i].day); |
| 79 | cal->set(UCAL_DAY_OF_WEEK, cases[i].dayOfWeek); |
| 80 | cal->set(UCAL_HOUR, cases[i].hour); |
| 81 | cal->set(UCAL_MINUTE, cases[i].min); |
| 82 | cal->set(UCAL_SECOND, cases[i].sec); |
| 83 | |
| 84 | UDate t2 = cal->getTime(status); |
| 85 | |
| 86 | if(t != t2) { |
| 87 | errln("Field->millis: Expected %.0f but got %.0f\n", t, t2); |
| 88 | logln(calToStr(*cal)); |
| 89 | } |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | UBool CalendarCaseTest::checkField(Calendar *cal, UCalendarDateFields field, int32_t value, UErrorCode &status) |
| 94 | { |
| 95 | if(U_FAILURE(status)) return FALSE; |
| 96 | int32_t res = cal->get(field, status); |
| 97 | if(U_FAILURE(status)) { |
| 98 | errln((UnicodeString)"Checking field " + fieldName(field) + " and got " + u_errorName(status)); |
| 99 | return FALSE; |
| 100 | } |
| 101 | if(res != value) { |
| 102 | errln((UnicodeString)"FAIL: Checking field " + fieldName(field) + " expected " + value + " and got " + res + UnicodeString("\n")); |
| 103 | return FALSE; |
| 104 | } else { |
| 105 | logln((UnicodeString)"Checking field " + fieldName(field) + " == " + value + UnicodeString("\n")); |
| 106 | } |
| 107 | return TRUE; |
| 108 | } |
| 109 | |
| 110 | // =========== Test Cases ===================== |
| 111 | enum { SUN=UCAL_SUNDAY, |
| 112 | MON=UCAL_MONDAY, |
| 113 | TUE=UCAL_TUESDAY, |
| 114 | WED=UCAL_WEDNESDAY, |
| 115 | THU=UCAL_THURSDAY, |
| 116 | FRI=UCAL_FRIDAY, |
| 117 | SAT=UCAL_SATURDAY}; |
| 118 | |
| 119 | void CalendarCaseTest::IslamicCivil() |
| 120 | { |
| 121 | static const TestCase tests[] = { |
| 122 | // |
| 123 | // Most of these test cases were taken from the back of |
| 124 | // "Calendrical Calculations", with some extras added to help |
| 125 | // debug a few of the problems that cropped up in development. |
| 126 | // |
| 127 | // The months in this table are 1-based rather than 0-based, |
| 128 | // because it's easier to edit that way. |
| 129 | // Islamic |
| 130 | // Julian Day Era Year Month Day WkDay Hour Min Sec |
| 131 | { 1507231.5, 0, -1245, 12, 9, SUN, 0, 0, 0}, |
| 132 | { 1660037.5, 0, -813, 2, 23, WED, 0, 0, 0}, |
| 133 | { 1746893.5, 0, -568, 4, 1, WED, 0, 0, 0}, |
| 134 | { 1770641.5, 0, -501, 4, 6, SUN, 0, 0, 0}, |
| 135 | { 1892731.5, 0, -157, 10, 17, WED, 0, 0, 0}, |
| 136 | { 1931579.5, 0, -47, 6, 3, MON, 0, 0, 0}, |
| 137 | { 1974851.5, 0, 75, 7, 13, SAT, 0, 0, 0}, |
| 138 | { 2091164.5, 0, 403, 10, 5, SUN, 0, 0, 0}, |
| 139 | { 2121509.5, 0, 489, 5, 22, SUN, 0, 0, 0}, |
| 140 | { 2155779.5, 0, 586, 2, 7, FRI, 0, 0, 0}, |
| 141 | { 2174029.5, 0, 637, 8, 7, SAT, 0, 0, 0}, |
| 142 | { 2191584.5, 0, 687, 2, 20, FRI, 0, 0, 0}, |
| 143 | { 2195261.5, 0, 697, 7, 7, SUN, 0, 0, 0}, |
| 144 | { 2229274.5, 0, 793, 7, 1, SUN, 0, 0, 0}, |
| 145 | { 2245580.5, 0, 839, 7, 6, WED, 0, 0, 0}, |
| 146 | { 2266100.5, 0, 897, 6, 1, SAT, 0, 0, 0}, |
| 147 | { 2288542.5, 0, 960, 9, 30, SAT, 0, 0, 0}, |
| 148 | { 2290901.5, 0, 967, 5, 27, SAT, 0, 0, 0}, |
| 149 | { 2323140.5, 0, 1058, 5, 18, WED, 0, 0, 0}, |
| 150 | { 2334848.5, 0, 1091, 6, 2, SUN, 0, 0, 0}, |
| 151 | { 2348020.5, 0, 1128, 8, 4, FRI, 0, 0, 0}, |
| 152 | { 2366978.5, 0, 1182, 2, 3, SUN, 0, 0, 0}, |
| 153 | { 2385648.5, 0, 1234, 10, 10, MON, 0, 0, 0}, |
| 154 | { 2392825.5, 0, 1255, 1, 11, WED, 0, 0, 0}, |
| 155 | { 2416223.5, 0, 1321, 1, 21, SUN, 0, 0, 0}, |
| 156 | { 2425848.5, 0, 1348, 3, 19, SUN, 0, 0, 0}, |
| 157 | { 2430266.5, 0, 1360, 9, 8, MON, 0, 0, 0}, |
| 158 | { 2430833.5, 0, 1362, 4, 13, MON, 0, 0, 0}, |
| 159 | { 2431004.5, 0, 1362, 10, 7, THU, 0, 0, 0}, |
| 160 | { 2448698.5, 0, 1412, 9, 13, TUE, 0, 0, 0}, |
| 161 | { 2450138.5, 0, 1416, 10, 5, SUN, 0, 0, 0}, |
| 162 | { 2465737.5, 0, 1460, 10, 12, WED, 0, 0, 0}, |
| 163 | { 2486076.5, 0, 1518, 3, 5, SUN, 0, 0, 0}, |
| 164 | { -1,-1,-1,-1,-1,-1,-1,-1,-1 } |
| 165 | }; |
| 166 | |
| 167 | UErrorCode status = U_ZERO_ERROR; |
| 168 | Calendar *c = Calendar::createInstance("ar@calendar=islamic-civil", status); |
| 169 | if (failure(status, "Calendar::createInstance", TRUE)) return; |
| 170 | c->setLenient(TRUE); |
| 171 | doTestCases(tests, c); |
| 172 | |
| 173 | static const UChar expectedUChars[] = { |
| 174 | 0x0627, 0x0644, 0x062e, 0x0645, 0x064a, 0x0633, 0x060c, 0x0020, 0x0662, 0x0662, 0x0020, |
| 175 | 0x0634, 0x0648, 0x0627, 0x0644, 0x0020, 0x0661, 0x0663, 0x0668, 0x0669, 0x0020, 0x0647, 0x0640, 0 |
| 176 | }; |
| 177 | UnicodeString result; |
| 178 | DateFormat *fmt = DateFormat::createDateInstance(DateFormat::kFull, Locale("ar_JO@calendar=islamic-civil")); |
| 179 | if (fmt == NULL) { |
| 180 | dataerrln("Error calling DateFormat::createDateInstance"); |
| 181 | delete c; |
| 182 | return; |
| 183 | } |
| 184 | |
| 185 | fmt->setTimeZone(*TimeZone::getGMT()); |
| 186 | fmt->format((UDate)2486076.5, result); |
| 187 | if (result != expectedUChars) { |
| 188 | errln((UnicodeString)"FAIL: DateFormatting failed. Got " + result + " and expected " + UnicodeString(expectedUChars) + UnicodeString("\n")); |
| 189 | errln("Maybe the resource aliasing isn't working"); |
| 190 | } |
| 191 | delete fmt; |
| 192 | delete c; |
| 193 | } |
| 194 | |
| 195 | void CalendarCaseTest::Hebrew() { |
| 196 | static const int32_t TISHRI = HebrewCalendar::TISHRI; |
| 197 | //static const int32_t HESHVAN = HebrewCalendar::HESHVAN; |
| 198 | //static const int32_t KISLEV = HebrewCalendar::KISLEV; |
| 199 | //static const int32_t TEVET = HebrewCalendar::TEVET; |
| 200 | //static const int32_t SHEVAT = HebrewCalendar::SHEVAT; |
| 201 | //static const int32_t ADAR_1 = HebrewCalendar::ADAR_1; |
| 202 | //static const int32_t ADAR = HebrewCalendar::ADAR; |
| 203 | //static const int32_t NISAN = HebrewCalendar::NISAN; |
| 204 | //static const int32_t IYAR = HebrewCalendar::IYAR; |
| 205 | //static const int32_t SIVAN = HebrewCalendar::SIVAN; |
| 206 | //static const int32_t TAMUZ = HebrewCalendar::TAMUZ; |
| 207 | static const int32_t AV = HebrewCalendar::AV; |
| 208 | static const int32_t ELUL = HebrewCalendar::ELUL; |
| 209 | |
| 210 | static const TestCase tests[] = { |
| 211 | // |
| 212 | // Most of these test cases were taken from the back of |
| 213 | // "Calendrical Calculations", with some extras added to help |
| 214 | // debug a few of the problems that cropped up in development. |
| 215 | // |
| 216 | // The months in this table are 1-based rather than 0-based, |
| 217 | // because it's easier to edit that way. |
| 218 | // |
| 219 | // Julian Day Era Year Month Day WkDay Hour Min Sec |
| 220 | {1507231.5, 0, 3174, 12, 10, SUN, 0, 0, 0}, |
| 221 | {1660037.5, 0, 3593, 3, 25, WED, 0, 0, 0}, |
| 222 | {1746893.5, 0, 3831, 1, 3, WED, 0, 0, 0}, |
| 223 | {1770641.5, 0, 3896, 1, 9, SUN, 0, 0, 0}, |
| 224 | {1892731.5, 0, 4230, 4, 18, WED, 0, 0, 0}, |
| 225 | {1931579.5, 0, 4336, 10, 4, MON, 0, 0, 0}, |
| 226 | {1974851.5, 0, 4455, 2, 13, SAT, 0, 0, 0}, |
| 227 | {2091164.5, 0, 4773, 9, 6, SUN, 0, 0, 0}, |
| 228 | {2121509.5, 0, 4856, 9, 23, SUN, 0, 0, 0}, |
| 229 | {2155779.5, 0, 4950, 8, 7, FRI, 0, 0, 0}, |
| 230 | {2174029.5, 0, 5000, 7, 8, SAT, 0, 0, 0}, |
| 231 | {2191584.5, 0, 5048, 8, 21, FRI, 0, 0, 0}, |
| 232 | {2195261.5, 0, 5058, 9, 7, SUN, 0, 0, 0}, |
| 233 | {2229274.5, 0, 5151, 11, 1, SUN, 0, 0, 0}, |
| 234 | {2245580.5, 0, 5196, 5, 7, WED, 0, 0, 0}, |
| 235 | {2266100.5, 0, 5252, 8, 3, SAT, 0, 0, 0}, |
| 236 | {2288542.5, 0, 5314, 1, 1, SAT, 0, 0, 0}, |
| 237 | {2290901.5, 0, 5320, 6, 27, SAT, 0, 0, 0}, |
| 238 | {2323140.5, 0, 5408, 10, 20, WED, 0, 0, 0}, |
| 239 | {2334551.5, 0, 5440, 1, 1, THU, 0, 0, 0}, |
| 240 | {2334581.5, 0, 5440, 2, 1, SAT, 0, 0, 0}, |
| 241 | {2334610.5, 0, 5440, 3, 1, SUN, 0, 0, 0}, |
| 242 | {2334639.5, 0, 5440, 4, 1, MON, 0, 0, 0}, |
| 243 | {2334668.5, 0, 5440, 5, 1, TUE, 0, 0, 0}, |
| 244 | {2334698.5, 0, 5440, 6, 1, THU, 0, 0, 0}, |
| 245 | {2334728.5, 0, 5440, 7, 1, SAT, 0, 0, 0}, |
| 246 | {2334757.5, 0, 5440, 8, 1, SUN, 0, 0, 0}, |
| 247 | {2334787.5, 0, 5440, 9, 1, TUE, 0, 0, 0}, |
| 248 | {2334816.5, 0, 5440, 10, 1, WED, 0, 0, 0}, |
| 249 | {2334846.5, 0, 5440, 11, 1, FRI, 0, 0, 0}, |
| 250 | {2334848.5, 0, 5440, 11, 3, SUN, 0, 0, 0}, |
| 251 | {2334934.5, 0, 5441, 1, 1, TUE, 0, 0, 0}, |
| 252 | {2348020.5, 0, 5476, 12, 5, FRI, 0, 0, 0}, |
| 253 | {2366978.5, 0, 5528, 11, 4, SUN, 0, 0, 0}, |
| 254 | {2385648.5, 0, 5579, 12, 11, MON, 0, 0, 0}, |
| 255 | {2392825.5, 0, 5599, 8, 12, WED, 0, 0, 0}, |
| 256 | {2416223.5, 0, 5663, 8, 22, SUN, 0, 0, 0}, |
| 257 | {2425848.5, 0, 5689, 12, 19, SUN, 0, 0, 0}, |
| 258 | {2430266.5, 0, 5702, 1, 8, MON, 0, 0, 0}, |
| 259 | {2430833.5, 0, 5703, 8, 14, MON, 0, 0, 0}, |
| 260 | {2431004.5, 0, 5704, 1, 8, THU, 0, 0, 0}, |
| 261 | {2448698.5, 0, 5752, 7, 12, TUE, 0, 0, 0}, |
| 262 | {2450138.5, 0, 5756, 7, 5, SUN, 0, 0, 0}, |
| 263 | {2465737.5, 0, 5799, 2, 12, WED, 0, 0, 0}, |
| 264 | {2486076.5, 0, 5854, 12, 5, SUN, 0, 0, 0}, |
| 265 | |
| 266 | // Test cases taken from a table of 14 "year types" in the Help file |
| 267 | // of the application "Hebrew Calendar" |
| 268 | {2456187.5, 0, 5773, 1, 1, MON, 0, 0, 0}, |
| 269 | {2459111.5, 0, 5781, 1, 1, SAT, 0, 0, 0}, |
| 270 | {2453647.5, 0, 5766, 1, 1, TUE, 0, 0, 0}, |
| 271 | {2462035.5, 0, 5789, 1, 1, THU, 0, 0, 0}, |
| 272 | {2458756.5, 0, 5780, 1, 1, MON, 0, 0, 0}, |
| 273 | {2460586.5, 0, 5785, 1, 1, THU, 0, 0, 0}, |
| 274 | {2463864.5, 0, 5794, 1, 1, SAT, 0, 0, 0}, |
| 275 | {2463481.5, 0, 5793, 1, 1, MON, 0, 0, 0}, |
| 276 | {2470421.5, 0, 5812, 1, 1, THU, 0, 0, 0}, |
| 277 | {2460203.5, 0, 5784, 1, 1, SAT, 0, 0, 0}, |
| 278 | {2459464.5, 0, 5782, 1, 1, TUE, 0, 0, 0}, |
| 279 | {2467142.5, 0, 5803, 1, 1, MON, 0, 0, 0}, |
| 280 | {2455448.5, 0, 5771, 1, 1, THU, 0, 0, 0}, |
| 281 | // Test cases for JB#2327 |
| 282 | // http://www.fourmilab.com/documents/calendar/ |
| 283 | // http://www.calendarhome.com/converter/ |
| 284 | // 2452465.5, 2002, JULY, 10, 5762, AV, 1, |
| 285 | // 2452494.5, 2002, AUGUST, 8, 5762, AV, 30, |
| 286 | // 2452495.5, 2002, AUGUST, 9, 5762, ELUL, 1, |
| 287 | // 2452523.5, 2002, SEPTEMBER, 6, 5762, ELUL, 29, |
| 288 | // 2452524.5, 2002, SEPTEMBER, 7, 5763, TISHRI, 1, |
| 289 | // Julian Day Era Year Month Day WkDay Hour Min Sec |
| 290 | {2452465.5, 0, 5762, AV+1, 1, WED, 0, 0, 0}, |
| 291 | {2452494.5, 0, 5762, AV+1, 30, THU, 0, 0, 0}, |
| 292 | {2452495.5, 0, 5762, ELUL+1, 1, FRI, 0, 0, 0}, |
| 293 | {2452523.5, 0, 5762, ELUL+1, 29, FRI, 0, 0, 0}, |
| 294 | {2452524.5, 0, 5763, TISHRI+1, 1, SAT, 0, 0, 0}, |
| 295 | { -1,-1,-1,-1,-1,-1,-1,-1,-1 } |
| 296 | }; |
| 297 | |
| 298 | UErrorCode status = U_ZERO_ERROR; |
| 299 | Calendar *c = Calendar::createInstance("he_HE@calendar=hebrew", status); |
| 300 | if (failure(status, "Calendar::createInstance", TRUE)) return; |
| 301 | c->setLenient(TRUE); |
| 302 | doTestCases(tests, c); |
| 303 | |
| 304 | |
| 305 | // Additional test cases for bugs found during development |
| 306 | // G.YY/MM/DD Era Year Month Day WkDay Hour Min Sec |
| 307 | //{1013, 9, 8, 0, 4774, 1, 1, TUE, 0, 0, 0}, |
| 308 | //{1239, 9, 1, 0, 5000, 1, 1, THU, 0, 0, 0}, |
| 309 | //{1240, 9,18, 0, 5001, 1, 1, TUE, 0, 0, 0}, |
| 310 | |
| 311 | |
| 312 | delete c; |
| 313 | } |
| 314 | |
| 315 | void CalendarCaseTest::Indian() { |
| 316 | // Months in indian calendar are 0-based. Here taking 1-based names: |
| 317 | static const int32_t CHAITRA = IndianCalendar::CHAITRA + 1; |
| 318 | static const int32_t VAISAKHA = IndianCalendar::VAISAKHA + 1; |
| 319 | static const int32_t JYAISTHA = IndianCalendar::JYAISTHA + 1; |
| 320 | static const int32_t ASADHA = IndianCalendar::ASADHA + 1; |
| 321 | static const int32_t SRAVANA = IndianCalendar::SRAVANA + 1 ; |
| 322 | static const int32_t BHADRA = IndianCalendar::BHADRA + 1 ; |
| 323 | static const int32_t ASVINA = IndianCalendar::ASVINA + 1 ; |
| 324 | static const int32_t KARTIKA = IndianCalendar::KARTIKA + 1 ; |
| 325 | static const int32_t AGRAHAYANA = IndianCalendar::AGRAHAYANA + 1 ; |
| 326 | static const int32_t PAUSA = IndianCalendar::PAUSA + 1 ; |
| 327 | static const int32_t MAGHA = IndianCalendar::MAGHA + 1 ; |
| 328 | static const int32_t PHALGUNA = IndianCalendar::PHALGUNA + 1 ; |
| 329 | |
| 330 | |
| 331 | static const TestCase tests[] = { |
| 332 | // Test dates generated from: |
| 333 | // http://www.fourmilab.ch/documents/calendar/ |
| 334 | |
| 335 | // A huge list of test cases to make sure that computeTime and computeFields |
| 336 | // work properly for a wide range of data in the Indian civil calendar. |
| 337 | // |
| 338 | // Julian Day Era Year Month Day WkDay Hour Min Sec |
| 339 | {1770641.5, 0, 57, ASVINA, 10, SUN, 0, 0, 0}, |
| 340 | {1892731.5, 0, 391, PAUSA, 18, WED, 0, 0, 0}, |
| 341 | {1931579.5, 0, 498, VAISAKHA, 30, MON, 0, 0, 0}, |
| 342 | {1974851.5, 0, 616, KARTIKA, 19, SAT, 0, 0, 0}, |
| 343 | {2091164.5, 0, 935, VAISAKHA, 5, SUN, 0, 0, 0}, |
| 344 | {2121509.5, 0, 1018, JYAISTHA, 3, SUN, 0, 0, 0}, |
| 345 | {2155779.5, 0, 1112, CHAITRA, 2, FRI, 0, 0, 0}, |
| 346 | {2174029.5, 0, 1161, PHALGUNA, 20, SAT, 0, 0, 0}, |
| 347 | {2191584.5, 0, 1210, CHAITRA, 13, FRI, 0, 0, 0}, |
| 348 | {2195261.5, 0, 1220, VAISAKHA, 7, SUN, 0, 0, 0}, |
| 349 | {2229274.5, 0, 1313, JYAISTHA, 22, SUN, 0, 0, 0}, |
| 350 | {2245580.5, 0, 1357, MAGHA, 14, WED, 0, 0, 0}, |
| 351 | {2266100.5, 0, 1414, CHAITRA, 20, SAT, 0, 0, 0}, |
| 352 | {2288542.5, 0, 1475, BHADRA, 28, SAT, 0, 0, 0}, |
| 353 | {2290901.5, 0, 1481, PHALGUNA, 15, SAT, 0, 0, 0}, |
| 354 | {2323140.5, 0, 1570, JYAISTHA, 20, WED, 0, 0, 0}, |
| 355 | {2334551.5, 0, 1601, BHADRA, 16, THU, 0, 0, 0}, |
| 356 | {2334581.5, 0, 1601, ASVINA, 15, SAT, 0, 0, 0}, |
| 357 | {2334610.5, 0, 1601, KARTIKA, 14, SUN, 0, 0, 0}, |
| 358 | {2334639.5, 0, 1601, AGRAHAYANA, 13, MON, 0, 0, 0}, |
| 359 | {2334668.5, 0, 1601, PAUSA, 12, TUE, 0, 0, 0}, |
| 360 | {2334698.5, 0, 1601, MAGHA, 12, THU, 0, 0, 0}, |
| 361 | {2334728.5, 0, 1601, PHALGUNA, 12, SAT, 0, 0, 0}, |
| 362 | {2334757.5, 0, 1602, CHAITRA, 11, SUN, 0, 0, 0}, |
| 363 | {2334787.5, 0, 1602, VAISAKHA, 10, TUE, 0, 0, 0}, |
| 364 | {2334816.5, 0, 1602, JYAISTHA, 8, WED, 0, 0, 0}, |
| 365 | {2334846.5, 0, 1602, ASADHA, 7, FRI, 0, 0, 0}, |
| 366 | {2334848.5, 0, 1602, ASADHA, 9, SUN, 0, 0, 0}, |
| 367 | {2348020.5, 0, 1638, SRAVANA, 2, FRI, 0, 0, 0}, |
| 368 | {2334934.5, 0, 1602, ASVINA, 2, TUE, 0, 0, 0}, |
| 369 | {2366978.5, 0, 1690, JYAISTHA, 29, SUN, 0, 0, 0}, |
| 370 | {2385648.5, 0, 1741, SRAVANA, 11, MON, 0, 0, 0}, |
| 371 | {2392825.5, 0, 1761, CHAITRA, 6, WED, 0, 0, 0}, |
| 372 | {2416223.5, 0, 1825, CHAITRA, 29, SUN, 0, 0, 0}, |
| 373 | {2425848.5, 0, 1851, BHADRA, 3, SUN, 0, 0, 0}, |
| 374 | {2430266.5, 0, 1863, ASVINA, 7, MON, 0, 0, 0}, |
| 375 | {2430833.5, 0, 1865, CHAITRA, 29, MON, 0, 0, 0}, |
| 376 | {2431004.5, 0, 1865, ASVINA, 15, THU, 0, 0, 0}, |
| 377 | {2448698.5, 0, 1913, PHALGUNA, 27, TUE, 0, 0, 0}, |
| 378 | {2450138.5, 0, 1917, PHALGUNA, 6, SUN, 0, 0, 0}, |
| 379 | {2465737.5, 0, 1960, KARTIKA, 19, WED, 0, 0, 0}, |
| 380 | {2486076.5, 0, 2016, ASADHA, 27, SUN, 0, 0, 0}, |
| 381 | { -1,-1,-1,-1,-1,-1,-1,-1,-1 } |
| 382 | }; |
| 383 | |
| 384 | UErrorCode status = U_ZERO_ERROR; |
| 385 | Calendar *c = Calendar::createInstance("hi_IN@calendar=indian", status); |
| 386 | if (failure(status, "Calendar::createInstance", TRUE)) return; |
| 387 | c->setLenient(TRUE); |
| 388 | doTestCases(tests, c); |
| 389 | |
| 390 | delete c; |
| 391 | } |
| 392 | |
| 393 | void CalendarCaseTest::Coptic() { |
| 394 | static const TestCase tests[] = { |
| 395 | // JD Era Year Month Day WkDay Hour Min Sec |
| 396 | {2401442.5, 1, 1579, 2, 20, WED, 0, 0, 0}, // Gregorian: 20/10/1862 |
| 397 | {2402422.5, 1, 1581, 10, 29, WED, 0, 0, 0}, // Gregorian: 05/07/1865 |
| 398 | {2402630.5, 1, 1582, 5, 22, MON, 0, 0, 0}, // Gregorian: 29/01/1866 |
| 399 | {2402708.5, 1, 1582, 8, 10, TUE, 0, 0, 0}, // Gregorian: 17/04/1866 |
| 400 | {2402971.5, 1, 1583, 4, 28, SAT, 0, 0, 0}, // Gregorian: 05/01/1867 |
| 401 | {2403344.5, 1, 1584, 5, 5, MON, 0, 0, 0}, // Gregorian: 13/01/1868 |
| 402 | {1721059.5, 0, 285, 5, 7, SAT, 0, 0, 0}, // Gregorian: 01/01/0000 |
| 403 | {1721425.5, 0, 284, 5, 8, MON, 0, 0, 0}, // Gregorian: 01/01/0001 |
| 404 | {1824663.5, 0, 2, 13, 6, WED, 0, 0, 0}, // Gregorian: 29/08/0283 |
| 405 | {1824664.5, 0, 1, 1, 1, THU, 0, 0, 0}, // Gregorian: 30/08/0283 |
| 406 | {1825029.5, 1, 1, 1, 1, FRI, 0, 0, 0}, // Gregorian: 29/08/0284 |
| 407 | {1825394.5, 1, 2, 1, 1, SAT, 0, 0, 0}, // Gregorian: 29/08/0285 |
| 408 | {1825759.5, 1, 3, 1, 1, SUN, 0, 0, 0}, // Gregorian: 29/08/0286 |
| 409 | {1826125.5, 1, 4, 1, 1, TUE, 0, 0, 0}, // Gregorian: 30/08/0287 |
| 410 | {1825028.5, 0, 1, 13, 5, THU, 0, 0, 0}, // Gregorian: 28/08/0284 |
| 411 | {1825393.5, 1, 1, 13, 5, FRI, 0, 0, 0}, // Gregorian: 28/08/0285 |
| 412 | {1825758.5, 1, 2, 13, 5, SAT, 0, 0, 0}, // Gregorian: 28/08/0286 |
| 413 | {1826123.5, 1, 3, 13, 5, SUN, 0, 0, 0}, // Gregorian: 28/08/0287 |
| 414 | {1826124.5, 1, 3, 13, 6, MON, 0, 0, 0}, // Gregorian: 29/08/0287 |
| 415 | // above is first coptic leap year |
| 416 | {1826489.5, 1, 4, 13, 5, TUE, 0, 0, 0}, // Gregorian: 28/08/0288 |
| 417 | {2299158.5, 1, 1299, 2, 6, WED, 0, 0, 0}, // Gregorian: 13/10/1582 |
| 418 | {2299159.5, 1, 1299, 2, 7, THU, 0, 0, 0}, // Gregorian: 14/10/1582 |
| 419 | {2299160.5, 1, 1299, 2, 8, FRI, 0, 0, 0}, // Gregorian: 15/10/1582 |
| 420 | {2299161.5, 1, 1299, 2, 9, SAT, 0, 0, 0}, // Gregorian: 16/10/1582 |
| 421 | |
| 422 | {2415020.5, 1, 1616, 4, 23, MON, 0, 0, 0}, // Gregorian: 01/01/1900 |
| 423 | {2453371.5, 1, 1721, 4, 23, SAT, 0, 0, 0}, // Gregorian: 01/01/2005 |
| 424 | {2555528.5, 1, 2000, 13, 5, FRI, 0, 0, 0}, // Gregorian: 12/09/2284 |
| 425 | { -1, -1, -1, -1, -1, -1, -1, -1, -1} |
| 426 | }; |
| 427 | |
| 428 | UErrorCode status = U_ZERO_ERROR; |
| 429 | Calendar *c = Calendar::createInstance("cop_EG@calendar=coptic", status); |
| 430 | if (failure(status, "Calendar::createInstance", TRUE)) return; |
| 431 | |
| 432 | c->setLenient(TRUE); |
| 433 | doTestCases(tests, c); |
| 434 | |
| 435 | delete c; |
| 436 | } |
| 437 | |
| 438 | void CalendarCaseTest::Ethiopic() { |
| 439 | static TestCase tests[] = { |
| 440 | // JD Era Year Month Day WkDay Hour Min Sec |
| 441 | {2401442.5, 1, 1855, 2, 20, WED, 0, 0, 0}, // Gregorian: 29/10/1862 |
| 442 | {2402422.5, 1, 1857, 10, 29, WED, 0, 0, 0}, // Gregorian: 05/07/1865 |
| 443 | {2402630.5, 1, 1858, 5, 22, MON, 0, 0, 0}, // Gregorian: 29/01/1866 |
| 444 | {2402708.5, 1, 1858, 8, 10, TUE, 0, 0, 0}, // Gregorian: 17/04/1866 |
| 445 | {2402971.5, 1, 1859, 4, 28, SAT, 0, 0, 0}, // Gregorian: 05/01/1867 |
| 446 | {2403344.5, 1, 1860, 5, 5, MON, 0, 0, 0}, // Gregorian: 13/01/1868 |
| 447 | {1721059.5, 0, 5492, 5, 7, SAT, 0, 0, 0}, // Gregorian: 01/01/0000 |
| 448 | {1721425.5, 0, 5493, 5, 8, MON, 0, 0, 0}, // Gregorian: 01/01/0001 |
| 449 | {1723854.5, 0, 5499, 13, 6, MON, 0, 0, 0}, // Gregorian: 27/08/0007 |
| 450 | |
| 451 | {1723855.5, 0, 5500, 1, 1, TUE, 0, 0, 0}, // Gregorian: 28/08/0007 |
| 452 | {1724220.5, 1, 1, 1, 1, WED, 0, 0, 0}, // Gregorian: 27/08/0008 |
| 453 | {1724585.5, 1, 2, 1, 1, THU, 0, 0, 0}, // Gregorian: 27/08/0009 |
| 454 | {1724950.5, 1, 3, 1, 1, FRI, 0, 0, 0}, // Gregorian: 27/08/0010 |
| 455 | |
| 456 | //{1724536.5, 1, 4, 1, 1, SUN, 0, 0, 0}, // Gregorian: 28/08/0011 |
| 457 | {1725316.5, 1, 4, 1, 1, SUN, 0, 0, 0}, // Gregorian: 28/08/0011 - dlf |
| 458 | {1724219.5, 0, 5500, 13, 5, TUE, 0, 0, 0}, // Gregorian: 26/08/0008 |
| 459 | {1724584.5, 1, 1, 13, 5, WED, 0, 0, 0}, // Gregorian: 26/08/0009 |
| 460 | {1724949.5, 1, 2, 13, 5, THU, 0, 0, 0}, // Gregorian: 26/08/0010 |
| 461 | {1725314.5, 1, 3, 13, 5, FRI, 0, 0, 0}, // Gregorian: 26/08/0011 |
| 462 | {1725315.5, 1, 3, 13, 6, SAT, 0, 0, 0}, // Gregorian: 27/08/0011 - first ethiopic leap year |
| 463 | //{1725560.5, 1, 4, 13, 5, SUN, 0, 0, 0}, // Gregorian: 26/08/0012 - dlf |
| 464 | {1725680.5, 1, 4, 13, 5, SUN, 0, 0, 0}, // Gregorian: 26/08/0012 |
| 465 | {2299158.5, 1, 1575, 2, 6, WED, 0, 0, 0}, // Gregorian: 13/10/1582 |
| 466 | {2299159.5, 1, 1575, 2, 7, THU, 0, 0, 0}, // Gregorian: 14/10/1582 Julian 04/10/1582 |
| 467 | |
| 468 | {2299160.5, 1, 1575, 2, 8, FRI, 0, 0, 0}, // Gregorian: 15/10/1582 |
| 469 | {2299161.5, 1, 1575, 2, 9, SAT, 0, 0, 0}, // Gregorian: 16/10/1582 |
| 470 | |
| 471 | {2415020.5, 1, 1892, 4, 23, MON, 0, 0, 0}, // Gregorian: 01/01/1900 |
| 472 | {2453371.5, 1, 1997, 4, 23, SAT, 0, 0, 0}, // Gregorian: 01/01/2005 |
| 473 | {2454719.5, 1, 2000, 13, 5, WED, 0, 0, 0}, // Gregorian: 10/09/2008 |
| 474 | { -1, -1, -1, -1, -1, -1, -1, -1, -1} |
| 475 | }; |
| 476 | |
| 477 | UErrorCode status = U_ZERO_ERROR; |
| 478 | Calendar *c = Calendar::createInstance("am_ET@calendar=ethiopic", status); |
| 479 | if (failure(status, "Calendar::createInstance", TRUE)) return; |
| 480 | c->setLenient(TRUE); |
| 481 | doTestCases(tests, c); |
| 482 | |
| 483 | delete c; |
| 484 | |
| 485 | // Testing Amete Alem mode |
| 486 | int32_t i; |
| 487 | TestCase *tcase = tests; |
| 488 | for (i = 0; tcase[i].era >= 0; i++) { |
| 489 | if (tcase[i].era == 1) { |
| 490 | tcase[i].era = 0; // Change to Amete Alem era |
| 491 | tcase[i].year += 5500; // Amete Mihret 1 = Amete Alem 5501 |
| 492 | } |
| 493 | } |
| 494 | c = Calendar::createInstance("am_ET@calendar=ethiopic-amete-alem", status); |
| 495 | if (failure(status, "Calendar::createInstance", TRUE)) return; |
| 496 | c->setLenient(TRUE); |
| 497 | doTestCases(tests, c); |
| 498 | |
| 499 | delete c; |
| 500 | } |
| 501 | |
| 502 | |
| 503 | #endif |