1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /********************************************************************
4 * Copyright (c) 1997-2016, International Business Machines
5 * Corporation and others. All Rights Reserved.
6 ********************************************************************
10 * Modification History:
12 * Madhu Katragadda Creation
13 ********************************************************************
16 /* C API AND FUNCTIONALITY TEST FOR CALENDAR (ucol.h)*/
18 #include "unicode/utypes.h"
20 #if !UCONFIG_NO_FORMATTING
25 #include "unicode/uloc.h"
26 #include "unicode/ucal.h"
27 #include "unicode/udat.h"
28 #include "unicode/ustring.h"
36 void TestGregorianChange(void);
37 void TestFieldDifference(void);
38 void TestAddRollEra0AndEraBounds(void);
39 void TestGetTZTransition(void);
41 void TestGetWindowsTimeZoneID(void);
42 void TestGetTimeZoneIDByWindowsID(void);
44 void TestPersianCalOverflow(void);
45 void TestGetDayPeriods(); /* Apple-specific */
47 void addCalTest(TestNode
** root
);
49 void addCalTest(TestNode
** root
)
52 addTest(root
, &TestCalendar
, "tsformat/ccaltst/TestCalendar");
53 addTest(root
, &TestGetSetDateAPI
, "tsformat/ccaltst/TestGetSetDateAPI");
54 addTest(root
, &TestFieldGetSet
, "tsformat/ccaltst/TestFieldGetSet");
55 addTest(root
, &TestAddRollExtensive
, "tsformat/ccaltst/TestAddRollExtensive");
56 addTest(root
, &TestGetLimits
, "tsformat/ccaltst/TestGetLimits");
57 addTest(root
, &TestDOWProgression
, "tsformat/ccaltst/TestDOWProgression");
58 addTest(root
, &TestGMTvsLocal
, "tsformat/ccaltst/TestGMTvsLocal");
59 addTest(root
, &TestGregorianChange
, "tsformat/ccaltst/TestGregorianChange");
60 addTest(root
, &TestGetKeywordValuesForLocale
, "tsformat/ccaltst/TestGetKeywordValuesForLocale");
61 addTest(root
, &TestWeekend
, "tsformat/ccaltst/TestWeekend");
62 addTest(root
, &TestFieldDifference
, "tsformat/ccaltst/TestFieldDifference");
63 addTest(root
, &TestAmbiguousWallTime
, "tsformat/ccaltst/TestAmbiguousWallTime");
64 addTest(root
, &TestAddRollEra0AndEraBounds
, "tsformat/ccaltst/TestAddRollEra0AndEraBounds");
65 addTest(root
, &TestGetTZTransition
, "tsformat/ccaltst/TestGetTZTransition");
66 addTest(root
, &TestGetWindowsTimeZoneID
, "tsformat/ccaltst/TestGetWindowsTimeZoneID");
67 addTest(root
, &TestGetTimeZoneIDByWindowsID
, "tsformat/ccaltst/TestGetTimeZoneIDByWindowsID");
68 addTest(root
, &TestClear
, "tsformat/ccaltst/TestClear");
69 addTest(root
, &TestPersianCalOverflow
, "tsformat/ccaltst/TestPersianCalOverflow");
70 addTest(root
, &TestGetDayPeriods
, "tsformat/ccaltst/TestGetDayPeriods"); /* Apple-specific */
74 static const UChar fgGMTID
[] = { 0x0047, 0x004d, 0x0054, 0x0000 };
77 static const UChar PST
[] = {0x50, 0x53, 0x54, 0x00}; /* "PST" */
79 static const UChar EUROPE_PARIS
[] = {0x45, 0x75, 0x72, 0x6F, 0x70, 0x65, 0x2F, 0x50, 0x61, 0x72, 0x69, 0x73, 0x00}; /* "Europe/Paris" */
81 static const UChar AMERICA_LOS_ANGELES
[] = {0x41, 0x6D, 0x65, 0x72, 0x69, 0x63, 0x61, 0x2F,
82 0x4C, 0x6F, 0x73, 0x5F, 0x41, 0x6E, 0x67, 0x65, 0x6C, 0x65, 0x73, 0x00}; /* America/Los_Angeles */
86 UCalendarType calType
;
87 const char * expectedResult
;
90 static const UCalGetTypeTest ucalGetTypeTests
[] = {
91 { "en_US", UCAL_GREGORIAN
, "gregorian" },
92 { "ja_JP@calendar=japanese", UCAL_DEFAULT
, "japanese" },
93 { "th_TH", UCAL_GREGORIAN
, "gregorian" },
94 { "th_TH", UCAL_DEFAULT
, "buddhist" },
95 { "th-TH-u-ca-gregory", UCAL_DEFAULT
, "gregorian" },
96 { "ja_JP@calendar=japanese", UCAL_GREGORIAN
, "gregorian" },
97 { "fr_CH", UCAL_DEFAULT
, "gregorian" },
98 { "fr_SA", UCAL_DEFAULT
, "islamic-umalqura" },
99 { "fr_CH@rg=sazzzz", UCAL_DEFAULT
, "islamic-umalqura" },
100 { "fr_CH@calendar=japanese;rg=sazzzz", UCAL_DEFAULT
, "japanese" },
101 { "fr_TH@rg=SA", UCAL_DEFAULT
, "buddhist" }, /* ignore malformed rg tag */
102 { "th@rg=SA", UCAL_DEFAULT
, "buddhist" }, /* ignore malformed rg tag */
103 { "", UCAL_GREGORIAN
, "gregorian" },
104 { NULL
, UCAL_GREGORIAN
, "gregorian" },
105 { NULL
, 0, NULL
} /* terminator */
108 static void TestCalendar()
110 UCalendar
*caldef
= 0, *caldef2
= 0, *calfr
= 0, *calit
= 0, *calfrclone
= 0;
111 UEnumeration
* uenum
= NULL
;
112 int32_t count
, count2
, i
,j
;
115 UErrorCode status
= U_ZERO_ERROR
;
117 UDateFormat
*datdef
= 0;
119 int32_t resultlength
, resultlengthneeded
;
120 char tempMsgBuf
[256];
121 UChar zone1
[32], zone2
[32];
122 const char *tzver
= 0;
123 UChar canonicalID
[64];
124 UBool isSystemID
= FALSE
;
125 const UCalGetTypeTest
* ucalGetTypeTestPtr
;
127 #ifdef U_USE_UCAL_OBSOLETE_2_8
128 /*Testing countAvailableTimeZones*/
130 log_verbose("\nTesting ucal_countAvailableTZIDs\n");
131 count
=ucal_countAvailableTZIDs(offset
);
132 log_verbose("The number of timezone id's present with offset 0 are %d:\n", count
);
133 if(count
< 5) /* Don't hard code an exact == test here! */
134 log_err("FAIL: error in the ucal_countAvailableTZIDs - got %d expected at least 5 total\n", count
);
136 /*Testing getAvailableTZIDs*/
137 log_verbose("\nTesting ucal_getAvailableTZIDs");
138 for(i
=0;i
<count
;i
++){
139 ucal_getAvailableTZIDs(offset
, i
, &status
);
140 if(U_FAILURE(status
)){
141 log_err("FAIL: ucal_getAvailableTZIDs returned %s\n", u_errorName(status
));
143 log_verbose("%s\n", u_austrcpy(tempMsgBuf
, ucal_getAvailableTZIDs(offset
, i
, &status
)));
145 /*get Illegal TZID where index >= count*/
146 ucal_getAvailableTZIDs(offset
, i
, &status
);
147 if(status
!= U_INDEX_OUTOFBOUNDS_ERROR
){
148 log_err("FAIL:for TZID index >= count Expected INDEX_OUTOFBOUNDS_ERROR Got %s\n", u_errorName(status
));
153 /*Test ucal_openTimeZones, ucal_openCountryTimeZones and ucal_openTimeZoneIDEnumeration */
154 for (j
=0; j
<6; ++j
) {
155 const char *api
= "?";
156 const int32_t offsetMinus5
= -5*60*60*1000;
159 api
= "ucal_openTimeZones()";
160 uenum
= ucal_openTimeZones(&status
);
163 api
= "ucal_openCountryTimeZones(US)";
164 uenum
= ucal_openCountryTimeZones("US", &status
);
167 api
= "ucal_openTimeZoneIDEnumerarion(UCAL_ZONE_TYPE_CANONICAL, NULL, NULL)";
168 uenum
= ucal_openTimeZoneIDEnumeration(UCAL_ZONE_TYPE_CANONICAL
, NULL
, NULL
, &status
);
171 api
= "ucal_openTimeZoneIDEnumerarion(UCAL_ZONE_TYPE_CANONICAL_LOCATION, CA, NULL)";
172 uenum
= ucal_openTimeZoneIDEnumeration(UCAL_ZONE_TYPE_CANONICAL_LOCATION
, "CA", NULL
, &status
);
175 api
= "ucal_openTimeZoneIDEnumerarion(UCAL_ZONE_TYPE_ANY, NULL, -5 hour)";
176 uenum
= ucal_openTimeZoneIDEnumeration(UCAL_ZONE_TYPE_ANY
, NULL
, &offsetMinus5
, &status
);
179 api
= "ucal_openTimeZoneIDEnumerarion(UCAL_ZONE_TYPE_ANY, US, -5 hour)";
180 uenum
= ucal_openTimeZoneIDEnumeration(UCAL_ZONE_TYPE_ANY
, "US", &offsetMinus5
, &status
);
183 if (U_FAILURE(status
)) {
184 log_err_status(status
, "FAIL: %s failed with %s\n", api
,
185 u_errorName(status
));
189 count
= uenum_count(uenum
, &status
);
190 log_verbose("%s returned %d timezone id's:\n", api
, count
);
191 if (count
< 5) { /* Don't hard code an exact == test here! */
192 log_data_err("FAIL: in %s, got %d, expected at least 5 -> %s (Are you missing data?)\n", api
, count
, u_errorName(status
));
194 uenum_reset(uenum
, &status
);
195 if (U_FAILURE(status
)){
196 log_err("FAIL: uenum_reset for %s returned %s\n",
197 api
, u_errorName(status
));
199 for (i
=0; i
<count
; i
++) {
200 id
= uenum_next(uenum
, &len
, &status
);
201 if (U_FAILURE(status
)){
202 log_err("FAIL: uenum_next for %s returned %s\n",
203 api
, u_errorName(status
));
205 log_verbose("%s\n", id
);
208 /* Next one should be NULL */
209 id
= uenum_next(uenum
, &len
, &status
);
211 log_err("FAIL: uenum_next for %s returned %s, expected NULL\n",
218 /*Test ucal_getDSTSavings*/
219 status
= U_ZERO_ERROR
;
220 i
= ucal_getDSTSavings(fgGMTID
, &status
);
221 if (U_FAILURE(status
)) {
222 log_err("FAIL: ucal_getDSTSavings(GMT) => %s\n",
223 u_errorName(status
));
225 log_data_err("FAIL: ucal_getDSTSavings(GMT) => %d, expect 0 (Are you missing data?)\n", i
);
227 i
= ucal_getDSTSavings(PST
, &status
);
228 if (U_FAILURE(status
)) {
229 log_err("FAIL: ucal_getDSTSavings(PST) => %s\n",
230 u_errorName(status
));
231 } else if (i
!= 1*60*60*1000) {
232 log_err("FAIL: ucal_getDSTSavings(PST) => %d, expect %d\n", i
, 1*60*60*1000);
235 /*Test ucal_set/getDefaultTimeZone*/
236 status
= U_ZERO_ERROR
;
237 i
= ucal_getDefaultTimeZone(zone1
, UPRV_LENGTHOF(zone1
), &status
);
238 if (U_FAILURE(status
)) {
239 log_err("FAIL: ucal_getDefaultTimeZone() => %s\n",
240 u_errorName(status
));
242 ucal_setDefaultTimeZone(EUROPE_PARIS
, &status
);
243 if (U_FAILURE(status
)) {
244 log_err("FAIL: ucal_setDefaultTimeZone(Europe/Paris) => %s\n",
245 u_errorName(status
));
247 i
= ucal_getDefaultTimeZone(zone2
, UPRV_LENGTHOF(zone2
), &status
);
248 if (U_FAILURE(status
)) {
249 log_err("FAIL: ucal_getDefaultTimeZone() => %s\n",
250 u_errorName(status
));
252 if (u_strcmp(zone2
, EUROPE_PARIS
) != 0) {
253 log_data_err("FAIL: ucal_getDefaultTimeZone() did not return Europe/Paris (Are you missing data?)\n");
257 status
= U_ZERO_ERROR
;
258 ucal_setDefaultTimeZone(zone1
, &status
);
261 /*Test ucal_getTZDataVersion*/
262 status
= U_ZERO_ERROR
;
263 tzver
= ucal_getTZDataVersion(&status
);
264 if (U_FAILURE(status
)) {
265 log_err_status(status
, "FAIL: ucal_getTZDataVersion() => %s\n", u_errorName(status
));
266 } else if (uprv_strlen(tzver
) < 5 || uprv_strlen(tzver
) > 7 /*4 digits + 1-3 letters*/) {
267 log_err("FAIL: Bad version string was returned by ucal_getTZDataVersion\n");
269 log_verbose("PASS: ucal_getTZDataVersion returned %s\n", tzver
);
272 /*Testing ucal_getCanonicalTimeZoneID*/
273 status
= U_ZERO_ERROR
;
274 resultlength
= ucal_getCanonicalTimeZoneID(PST
, -1,
275 canonicalID
, UPRV_LENGTHOF(canonicalID
), &isSystemID
, &status
);
276 if (U_FAILURE(status
)) {
277 log_data_err("FAIL: error in ucal_getCanonicalTimeZoneID : %s\n", u_errorName(status
));
279 if (u_strcmp(AMERICA_LOS_ANGELES
, canonicalID
) != 0) {
280 log_data_err("FAIL: ucal_getCanonicalTimeZoneID(%s) returned %s : expected - %s (Are you missing data?)\n",
281 PST
, canonicalID
, AMERICA_LOS_ANGELES
);
284 log_data_err("FAIL: ucal_getCanonicalTimeZoneID(%s) set %d to isSystemID (Are you missing data?)\n",
289 /*Testing the ucal_open() function*/
290 status
= U_ZERO_ERROR
;
291 log_verbose("\nTesting the ucal_open()\n");
292 u_uastrcpy(tzID
, "PST");
293 caldef
=ucal_open(tzID
, u_strlen(tzID
), "en_US", UCAL_TRADITIONAL
, &status
);
294 if(U_FAILURE(status
)){
295 log_data_err("FAIL: error in ucal_open caldef : %s\n - (Are you missing data?)", u_errorName(status
));
298 caldef2
=ucal_open(tzID
, u_strlen(tzID
), "en_US", UCAL_TRADITIONAL
, &status
);
299 if(U_FAILURE(status
)){
300 log_data_err("FAIL: error in ucal_open caldef : %s - (Are you missing data?)\n", u_errorName(status
));
302 u_strcpy(tzID
, fgGMTID
);
303 calfr
=ucal_open(tzID
, u_strlen(tzID
), "fr_FR", UCAL_TRADITIONAL
, &status
);
304 if(U_FAILURE(status
)){
305 log_data_err("FAIL: error in ucal_open calfr : %s - (Are you missing data?)\n", u_errorName(status
));
307 calit
=ucal_open(tzID
, u_strlen(tzID
), "it_IT", UCAL_TRADITIONAL
, &status
);
308 if(U_FAILURE(status
)) {
309 log_data_err("FAIL: error in ucal_open calit : %s - (Are you missing data?)\n", u_errorName(status
));
312 /*Testing the clone() function*/
313 calfrclone
= ucal_clone(calfr
, &status
);
314 if(U_FAILURE(status
)){
315 log_data_err("FAIL: error in ucal_clone calfr : %s - (Are you missing data?)\n", u_errorName(status
));
318 /*Testing udat_getAvailable() and udat_countAvailable()*/
319 log_verbose("\nTesting getAvailableLocales and countAvailable()\n");
320 count
=ucal_countAvailable();
321 /* use something sensible w/o hardcoding the count */
323 log_verbose("PASS: ucal_countAvailable() works fine\n");
324 log_verbose("The no: of locales for which calendars are avilable are %d\n", count
);
326 log_data_err("FAIL: Error in countAvailable()\n");
329 for(i
=0;i
<count
;i
++) {
330 log_verbose("%s\n", ucal_getAvailable(i
));
334 /*Testing the equality between calendar's*/
335 log_verbose("\nTesting ucal_equivalentTo()\n");
336 if(caldef
&& caldef2
&& calfr
&& calit
) {
337 if(ucal_equivalentTo(caldef
, caldef2
) == FALSE
|| ucal_equivalentTo(caldef
, calfr
)== TRUE
||
338 ucal_equivalentTo(caldef
, calit
)== TRUE
|| ucal_equivalentTo(calfr
, calfrclone
) == FALSE
) {
339 log_data_err("FAIL: Error. equivalentTo test failed (Are you missing data?)\n");
341 log_verbose("PASS: equivalentTo test passed\n");
346 /*Testing the current time and date using ucal_getnow()*/
347 log_verbose("\nTesting the ucal_getNow function to check if it is fetching tbe current time\n");
349 /* open the date format and format the date to check the output */
350 datdef
=udat_open(UDAT_FULL
,UDAT_FULL
,NULL
, NULL
, 0,NULL
,0,&status
);
351 if(U_FAILURE(status
)){
352 log_data_err("FAIL: error in creating the dateformat : %s (Are you missing data?)\n", u_errorName(status
));
355 log_verbose("PASS: The current date and time fetched is %s\n", u_austrcpy(tempMsgBuf
, myDateFormat(datdef
, now
)) );
358 /*Testing the TimeZoneDisplayName */
359 log_verbose("\nTesting the fetching of time zone display name\n");
360 /*for the US locale */
362 resultlengthneeded
=ucal_getTimeZoneDisplayName(caldef
, UCAL_DST
, "en_US", NULL
, resultlength
, &status
);
364 if(status
==U_BUFFER_OVERFLOW_ERROR
)
367 resultlength
=resultlengthneeded
+1;
368 result
=(UChar
*)malloc(sizeof(UChar
) * resultlength
);
369 ucal_getTimeZoneDisplayName(caldef
, UCAL_DST
, "en_US", result
, resultlength
, &status
);
371 if(U_FAILURE(status
)) {
372 log_err("FAIL: Error in getting the timezone display name : %s\n", u_errorName(status
));
375 log_verbose("PASS: getting the time zone display name successful : %s, %d needed \n",
376 u_errorName(status
), resultlengthneeded
);
380 #define expectPDT "Pacific Daylight Time"
382 tzdname
=(UChar
*)malloc(sizeof(UChar
) * (sizeof(expectPDT
)+1));
383 u_uastrcpy(tzdname
, expectPDT
);
384 if(u_strcmp(tzdname
, result
)==0){
385 log_verbose("PASS: got the correct time zone display name %s\n", u_austrcpy(tempMsgBuf
, result
) );
388 log_err("FAIL: got the wrong time zone(DST) display name %s, wanted %s\n", austrdup(result
) , expectPDT
);
391 ucal_getTimeZoneDisplayName(caldef
, UCAL_SHORT_DST
, "en_US", result
, resultlength
, &status
);
392 u_uastrcpy(tzdname
, "PDT");
393 if(u_strcmp(tzdname
, result
) != 0){
394 log_err("FAIL: got the wrong time zone(SHORT_DST) display name %s, wanted %s\n", austrdup(result
), austrdup(tzdname
));
397 ucal_getTimeZoneDisplayName(caldef
, UCAL_STANDARD
, "en_US", result
, resultlength
, &status
);
398 u_uastrcpy(tzdname
, "Pacific Standard Time");
399 if(u_strcmp(tzdname
, result
) != 0){
400 log_err("FAIL: got the wrong time zone(STANDARD) display name %s, wanted %s\n", austrdup(result
), austrdup(tzdname
));
403 ucal_getTimeZoneDisplayName(caldef
, UCAL_SHORT_STANDARD
, "en_US", result
, resultlength
, &status
);
404 u_uastrcpy(tzdname
, "PST");
405 if(u_strcmp(tzdname
, result
) != 0){
406 log_err("FAIL: got the wrong time zone(SHORT_STANDARD) display name %s, wanted %s\n", austrdup(result
), austrdup(tzdname
));
410 /*testing the setAttributes and getAttributes of a UCalendar*/
411 log_verbose("\nTesting the getAttributes and set Attributes\n");
412 count
=ucal_getAttribute(calit
, UCAL_LENIENT
);
413 count2
=ucal_getAttribute(calfr
, UCAL_LENIENT
);
414 ucal_setAttribute(calit
, UCAL_LENIENT
, 0);
415 ucal_setAttribute(caldef
, UCAL_LENIENT
, count2
);
416 if( ucal_getAttribute(calit
, UCAL_LENIENT
) !=0 ||
417 ucal_getAttribute(calfr
, UCAL_LENIENT
)!=ucal_getAttribute(caldef
, UCAL_LENIENT
) )
418 log_err("FAIL: there is an error in getAttributes or setAttributes\n");
420 log_verbose("PASS: attribute set and got successfully\n");
421 /*set it back to orginal value */
422 log_verbose("Setting it back to normal\n");
423 ucal_setAttribute(calit
, UCAL_LENIENT
, count
);
424 if(ucal_getAttribute(calit
, UCAL_LENIENT
)!=count
)
425 log_err("FAIL: Error in setting the attribute back to normal\n");
427 /*setting the first day of the week to other values */
428 count
=ucal_getAttribute(calit
, UCAL_FIRST_DAY_OF_WEEK
);
429 for (i
=1; i
<=7; ++i
) {
430 ucal_setAttribute(calit
, UCAL_FIRST_DAY_OF_WEEK
,i
);
431 if (ucal_getAttribute(calit
, UCAL_FIRST_DAY_OF_WEEK
) != i
)
432 log_err("FAIL: set/getFirstDayOfWeek failed\n");
434 /*get bogus Attribute*/
435 count
=ucal_getAttribute(calit
, (UCalendarAttribute
)99); /* BOGUS_ATTRIBUTE */
437 log_err("FAIL: get/bogus attribute should return -1\n");
440 /*set it back to normal */
441 ucal_setAttribute(calit
, UCAL_FIRST_DAY_OF_WEEK
,count
);
442 /*setting minimal days of the week to other values */
443 count
=ucal_getAttribute(calit
, UCAL_MINIMAL_DAYS_IN_FIRST_WEEK
);
444 for (i
=1; i
<=7; ++i
) {
445 ucal_setAttribute(calit
, UCAL_MINIMAL_DAYS_IN_FIRST_WEEK
,i
);
446 if (ucal_getAttribute(calit
, UCAL_MINIMAL_DAYS_IN_FIRST_WEEK
) != i
)
447 log_err("FAIL: set/getMinimalDaysInFirstWeek failed\n");
449 /*set it back to normal */
450 ucal_setAttribute(calit
, UCAL_MINIMAL_DAYS_IN_FIRST_WEEK
,count
);
453 /*testing if the UCalendar's timezone is currently in day light saving's time*/
454 log_verbose("\nTesting if the UCalendar is currently in daylight saving's time\n");
455 ucal_setDateTime(caldef
, 1999, UCAL_MARCH
, 3, 10, 45, 20, &status
);
456 ucal_inDaylightTime(caldef
, &status
);
457 if(U_FAILURE(status
)) {
458 log_err("Error in ucal_inDaylightTime: %s\n", u_errorName(status
));
460 if(!ucal_inDaylightTime(caldef
, &status
))
461 log_verbose("PASS: It is not in daylight saving's time\n");
463 log_err("FAIL: It is not in daylight saving's time\n");
465 /*closing the UCalendar*/
470 ucal_close(calfrclone
);
472 /*testing ucal_getType, and ucal_open with UCAL_GREGORIAN*/
473 for (ucalGetTypeTestPtr
= ucalGetTypeTests
; ucalGetTypeTestPtr
->expectedResult
!= NULL
; ++ucalGetTypeTestPtr
) {
474 const char * localeToDisplay
= (ucalGetTypeTestPtr
->locale
!= NULL
)? ucalGetTypeTestPtr
->locale
: "<NULL>";
475 status
= U_ZERO_ERROR
;
476 caldef
= ucal_open(NULL
, 0, ucalGetTypeTestPtr
->locale
, ucalGetTypeTestPtr
->calType
, &status
);
477 if ( U_SUCCESS(status
) ) {
478 const char * calType
= ucal_getType(caldef
, &status
);
479 if ( U_SUCCESS(status
) && calType
!= NULL
) {
480 if ( uprv_strcmp( calType
, ucalGetTypeTestPtr
->expectedResult
) != 0 ) {
481 log_err("FAIL: ucal_open %s type %d does not return %s calendar\n", localeToDisplay
,
482 ucalGetTypeTestPtr
->calType
, ucalGetTypeTestPtr
->expectedResult
);
485 log_err("FAIL: ucal_open %s type %d, then ucal_getType fails\n", localeToDisplay
, ucalGetTypeTestPtr
->calType
);
489 log_err("FAIL: ucal_open %s type %d fails\n", localeToDisplay
, ucalGetTypeTestPtr
->calType
);
493 /*closing the UDateFormat used */
499 /*------------------------------------------------------*/
500 /*Testing the getMillis, setMillis, setDate and setDateTime functions extensively*/
502 static void TestGetSetDateAPI()
504 UCalendar
*caldef
= 0, *caldef2
= 0, *caldef3
= 0;
509 UDateFormat
*datdef
= 0;
510 UErrorCode status
=U_ZERO_ERROR
;
511 UDate d2
= 837039928046.0;
518 log_verbose("\nOpening the calendars()\n");
519 u_strcpy(tzID
, fgGMTID
);
520 /*open the calendars used */
521 caldef
=ucal_open(tzID
, u_strlen(tzID
), "en_US", UCAL_TRADITIONAL
, &status
);
522 caldef2
=ucal_open(tzID
, u_strlen(tzID
), "en_US", UCAL_TRADITIONAL
, &status
);
523 caldef3
=ucal_open(tzID
, u_strlen(tzID
), "en_US", UCAL_TRADITIONAL
, &status
);
524 /*open the dateformat */
525 /* this is supposed to open default date format, but later on it treats it like it is "en_US"
526 - very bad if you try to run the tests on machine where default locale is NOT "en_US" */
527 /*datdef=udat_open(UDAT_DEFAULT,UDAT_DEFAULT ,NULL,fgGMTID,-1, &status);*/
528 datdef
=udat_open(UDAT_DEFAULT
,UDAT_DEFAULT
,"en_US",fgGMTID
,-1,NULL
,0, &status
);
529 if(U_FAILURE(status
))
531 log_data_err("error in creating the dateformat : %s (Are you missing data?)\n", u_errorName(status
));
535 /*Testing getMillis and setMillis */
536 log_verbose("\nTesting the date and time fetched in millis for a calendar using getMillis\n");
537 d1
=ucal_getMillis(caldef
, &status
);
538 if(U_FAILURE(status
)){
539 log_err("Error in getMillis : %s\n", u_errorName(status
));
542 /*testing setMillis */
543 log_verbose("\nTesting the set date and time function using setMillis\n");
544 ucal_setMillis(caldef
, d2
, &status
);
545 if(U_FAILURE(status
)){
546 log_err("Error in setMillis : %s\n", u_errorName(status
));
549 /*testing if the calendar date is set properly or not */
550 d1
=ucal_getMillis(caldef
, &status
);
551 if(u_strcmp(myDateFormat(datdef
, d1
), myDateFormat(datdef
, d2
))!=0)
552 log_err("error in setMillis or getMillis\n");
553 /*-------------------*/
555 /*testing large negative millis*/
556 /*test a previously failed millis and beyond the lower bounds - ICU trac #9403 */
557 // -184303902611600000.0 - just beyond lower bounds (#9403 sets U_ILLEGAL_ARGUMENT_ERROR in strict mode)
558 // -46447814188001000.0 - fixed by #9403
560 log_verbose("\nTesting very large valid millis & invalid setMillis values (in both strict & lienent modes) detected\n");
562 testMillis
= -46447814188001000.0; // point where floorDivide in handleComputeFields failed as per #9403
563 log_verbose("using value[%lf]\n", testMillis
);
564 ucal_setAttribute(caldef3
, UCAL_LENIENT
, 0);
565 ucal_setMillis(caldef3
, testMillis
, &status
);
566 if(U_FAILURE(status
)){
567 log_err("Fail: setMillis incorrectly detected invalid value : for millis : %e : returned : %s\n", testMillis
, u_errorName(status
));
568 status
= U_ZERO_ERROR
;
571 log_verbose("\nTesting invalid setMillis values detected\n");
572 testMillis
= -184303902611600000.0;
573 log_verbose("using value[%lf]\n", testMillis
);
574 ucal_setAttribute(caldef3
, UCAL_LENIENT
, 1);
575 ucal_setMillis(caldef3
, testMillis
, &status
);
576 if(U_FAILURE(status
)){
577 log_err("Fail: setMillis incorrectly detected invalid value : for millis : %e : returned : %s\n", testMillis
, u_errorName(status
));
578 status
= U_ZERO_ERROR
;
580 dateBit
= ucal_get(caldef2
, UCAL_MILLISECOND
, &status
);
581 if(testMillis
== dateBit
)
583 log_err("Fail: error in setMillis, allowed invalid value %e : returns millisecond : %d", testMillis
, dateBit
);
585 log_verbose("Pass: setMillis correctly pinned min, returned : %d", dateBit
);
589 log_verbose("\nTesting invalid setMillis values detected\n");
590 testMillis
= -184303902611600000.0;
591 log_verbose("using value[%lf]\n", testMillis
);
592 ucal_setAttribute(caldef3
, UCAL_LENIENT
, 0);
593 ucal_setMillis(caldef3
, testMillis
, &status
);
594 if(U_FAILURE(status
)){
595 log_verbose("Pass: Illegal argument error as expected : for millis : %e : returned : %s\n", testMillis
, u_errorName(status
));
596 status
= U_ZERO_ERROR
;
598 dateBit
= ucal_get(caldef3
, UCAL_DAY_OF_MONTH
, &status
);
599 log_err("Fail: error in setMillis, allowed invalid value %e : returns DayOfMonth : %d", testMillis
, dateBit
);
601 /*-------------------*/
604 ctest_setTimeZone(NULL
, &status
);
606 /*testing ucal_setTimeZone() and ucal_getTimeZoneID function*/
607 log_verbose("\nTesting if the function ucal_setTimeZone() and ucal_getTimeZoneID work fine\n");
608 idLen
= ucal_getTimeZoneID(caldef2
, id
, UPRV_LENGTHOF(id
), &status
);
609 (void)idLen
; /* Suppress set but not used warning. */
610 if (U_FAILURE(status
)) {
611 log_err("Error in getTimeZoneID : %s\n", u_errorName(status
));
612 } else if (u_strcmp(id
, fgGMTID
) != 0) {
613 log_err("FAIL: getTimeZoneID returns a wrong ID: actual=%d, expected=%s\n", austrdup(id
), austrdup(fgGMTID
));
615 log_verbose("PASS: getTimeZoneID works fine\n");
618 ucal_setMillis(caldef2
, d2
, &status
);
619 if(U_FAILURE(status
)){
620 log_err("Error in getMillis : %s\n", u_errorName(status
));
622 hour
=ucal_get(caldef2
, UCAL_HOUR_OF_DAY
, &status
);
624 u_uastrcpy(tzID
, "PST");
625 ucal_setTimeZone(caldef2
,tzID
, 3, &status
);
626 if(U_FAILURE(status
)){
627 log_err("Error in setting the time zone using ucal_setTimeZone(): %s\n", u_errorName(status
));
630 log_verbose("ucal_setTimeZone worked fine\n");
632 idLen
= ucal_getTimeZoneID(caldef2
, id
, UPRV_LENGTHOF(id
), &status
);
633 if (U_FAILURE(status
)) {
634 log_err("Error in getTimeZoneID : %s\n", u_errorName(status
));
635 } else if (u_strcmp(id
, tzID
) != 0) {
636 log_err("FAIL: getTimeZoneID returns a wrong ID: actual=%d, expected=%s\n", austrdup(id
), austrdup(tzID
));
638 log_verbose("PASS: getTimeZoneID works fine\n");
641 if(hour
== ucal_get(caldef2
, UCAL_HOUR_OF_DAY
, &status
))
642 log_err("FAIL: Error setting the time zone doesn't change the represented time\n");
643 else if((hour
-8 + 1) != ucal_get(caldef2
, UCAL_HOUR_OF_DAY
, &status
)) /*because it is not in daylight savings time */
644 log_err("FAIL: Error setTimeZone doesn't change the represented time correctly with 8 hour offset\n");
646 log_verbose("PASS: setTimeZone works fine\n");
648 /*testing setTimeZone roundtrip */
649 log_verbose("\nTesting setTimeZone() roundtrip\n");
650 u_strcpy(tzID
, fgGMTID
);
651 ucal_setTimeZone(caldef2
, tzID
, 3, &status
);
652 if(U_FAILURE(status
)){
653 log_err("Error in setting the time zone using ucal_setTimeZone(): %s\n", u_errorName(status
));
655 if(d2
==ucal_getMillis(caldef2
, &status
))
656 log_verbose("PASS: setTimeZone roundtrip test passed\n");
658 log_err("FAIL: setTimeZone roundtrip test failed\n");
660 zoneOffset
= ucal_get(caldef2
, UCAL_ZONE_OFFSET
, &status
);
661 if(U_FAILURE(status
)){
662 log_err("Error in getting the time zone using ucal_get() after using ucal_setTimeZone(): %s\n", u_errorName(status
));
664 else if (zoneOffset
!= 0) {
665 log_err("Error in getting the time zone using ucal_get() after using ucal_setTimeZone() offset=%d\n", zoneOffset
);
668 ucal_setTimeZone(caldef2
, NULL
, -1, &status
);
669 if(U_FAILURE(status
)){
670 log_err("Error in setting the time zone using ucal_setTimeZone(): %s\n", u_errorName(status
));
672 if(ucal_getMillis(caldef2
, &status
))
673 log_verbose("PASS: setTimeZone roundtrip test passed\n");
675 log_err("FAIL: setTimeZone roundtrip test failed\n");
677 zoneOffset
= ucal_get(caldef2
, UCAL_ZONE_OFFSET
, &status
);
678 if(U_FAILURE(status
)){
679 log_err("Error in getting the time zone using ucal_get() after using ucal_setTimeZone(): %s\n", u_errorName(status
));
681 else if (zoneOffset
!= -28800000) {
682 log_err("Error in getting the time zone using ucal_get() after using ucal_setTimeZone() offset=%d\n", zoneOffset
);
685 ctest_resetTimeZone();
687 /*----------------------------* */
691 /*Testing if setDate works fine */
692 log_verbose("\nTesting the ucal_setDate() function \n");
693 u_uastrcpy(temp
, "Dec 17, 1971 at 11:05:28 PM");
694 ucal_setDate(caldef
,1971, UCAL_DECEMBER
, 17, &status
);
695 if(U_FAILURE(status
)){
696 log_err("error in setting the calendar date : %s\n", u_errorName(status
));
698 /*checking if the calendar date is set properly or not */
699 d1
=ucal_getMillis(caldef
, &status
);
700 if(u_strcmp(myDateFormat(datdef
, d1
), temp
)==0)
701 log_verbose("PASS:setDate works fine\n");
703 log_err("FAIL:Error in setDate()\n");
706 /* Testing setDate Extensively with various input values */
707 log_verbose("\nTesting ucal_setDate() extensively\n");
708 ucal_setDate(caldef
, 1999, UCAL_JANUARY
, 10, &status
);
709 verify1("1999 10th day of January is :", caldef
, datdef
, 1999, UCAL_JANUARY
, 10);
710 ucal_setDate(caldef
, 1999, UCAL_DECEMBER
, 3, &status
);
711 verify1("1999 3rd day of December is :", caldef
, datdef
, 1999, UCAL_DECEMBER
, 3);
712 ucal_setDate(caldef
, 2000, UCAL_MAY
, 3, &status
);
713 verify1("2000 3rd day of May is :", caldef
, datdef
, 2000, UCAL_MAY
, 3);
714 ucal_setDate(caldef
, 1999, UCAL_AUGUST
, 32, &status
);
715 verify1("1999 32th day of August is :", caldef
, datdef
, 1999, UCAL_SEPTEMBER
, 1);
716 ucal_setDate(caldef
, 1999, UCAL_MARCH
, 0, &status
);
717 verify1("1999 0th day of March is :", caldef
, datdef
, 1999, UCAL_FEBRUARY
, 28);
718 ucal_setDate(caldef
, 0, UCAL_MARCH
, 12, &status
);
720 /*--------------------*/
722 /*Testing if setDateTime works fine */
723 log_verbose("\nTesting the ucal_setDateTime() function \n");
724 u_uastrcpy(temp
, "May 3, 1972 at 4:30:42 PM");
725 ucal_setDateTime(caldef
,1972, UCAL_MAY
, 3, 16, 30, 42, &status
);
726 if(U_FAILURE(status
)){
727 log_err("error in setting the calendar date : %s\n", u_errorName(status
));
729 /*checking if the calendar date is set properly or not */
730 d1
=ucal_getMillis(caldef
, &status
);
731 if(u_strcmp(myDateFormat(datdef
, d1
), temp
)==0)
732 log_verbose("PASS: setDateTime works fine\n");
734 log_err("FAIL: Error in setDateTime\n");
738 /*Testing setDateTime extensively with various input values*/
739 log_verbose("\nTesting ucal_setDateTime() function extensively\n");
740 ucal_setDateTime(caldef
, 1999, UCAL_OCTOBER
, 10, 6, 45, 30, &status
);
741 verify2("1999 10th day of October at 6:45:30 is :", caldef
, datdef
, 1999, UCAL_OCTOBER
, 10, 6, 45, 30, 0 );
742 ucal_setDateTime(caldef
, 1999, UCAL_MARCH
, 3, 15, 10, 55, &status
);
743 verify2("1999 3rd day of March at 15:10:55 is :", caldef
, datdef
, 1999, UCAL_MARCH
, 3, 3, 10, 55, 1);
744 ucal_setDateTime(caldef
, 1999, UCAL_MAY
, 3, 25, 30, 45, &status
);
745 verify2("1999 3rd day of May at 25:30:45 is :", caldef
, datdef
, 1999, UCAL_MAY
, 4, 1, 30, 45, 0);
746 ucal_setDateTime(caldef
, 1999, UCAL_AUGUST
, 32, 22, 65, 40, &status
);
747 verify2("1999 32th day of August at 22:65:40 is :", caldef
, datdef
, 1999, UCAL_SEPTEMBER
, 1, 11, 5, 40,1);
748 ucal_setDateTime(caldef
, 1999, UCAL_MARCH
, 12, 0, 0, 0,&status
);
749 verify2("1999 12th day of March at 0:0:0 is :", caldef
, datdef
, 1999, UCAL_MARCH
, 12, 0, 0, 0, 0);
750 ucal_setDateTime(caldef
, 1999, UCAL_MARCH
, 12, -10, -10,0, &status
);
751 verify2("1999 12th day of March is at -10:-10:0 :", caldef
, datdef
, 1999, UCAL_MARCH
, 11, 1, 50, 0, 1);
755 /*close caldef and datdef*/
762 /*----------------------------------------------------------- */
764 * Confirm the functioning of the calendar field related functions.
766 static void TestFieldGetSet()
770 UDateFormat
*datdef
= 0;
772 UErrorCode status
=U_ZERO_ERROR
;
773 (void)d1
; /* Suppress set but not used warning. */
774 log_verbose("\nFetching pointer to UCalendar using the ucal_open()\n");
775 u_strcpy(tzID
, fgGMTID
);
776 /*open the calendar used */
777 cal
=ucal_open(tzID
, u_strlen(tzID
), "en_US", UCAL_TRADITIONAL
, &status
);
778 if (U_FAILURE(status
)) {
779 log_data_err("ucal_open failed: %s - (Are you missing data?)\n", u_errorName(status
));
782 datdef
=udat_open(UDAT_SHORT
,UDAT_SHORT
,NULL
,fgGMTID
,-1,NULL
, 0, &status
);
783 if(U_FAILURE(status
))
785 log_data_err("error in creating the dateformat : %s (Are you missing data?)\n", u_errorName(status
));
788 /*Testing ucal_get()*/
789 log_verbose("\nTesting the ucal_get() function of Calendar\n");
790 ucal_setDateTime(cal
, 1999, UCAL_MARCH
, 12, 5, 25, 30, &status
);
791 if(U_FAILURE(status
)){
792 log_data_err("error in the setDateTime() : %s (Are you missing data?)\n", u_errorName(status
));
794 if(ucal_get(cal
, UCAL_YEAR
, &status
)!=1999 || ucal_get(cal
, UCAL_MONTH
, &status
)!=2 ||
795 ucal_get(cal
, UCAL_DATE
, &status
)!=12 || ucal_get(cal
, UCAL_HOUR
, &status
)!=5)
796 log_data_err("error in ucal_get() -> %s (Are you missing data?)\n", u_errorName(status
));
797 else if(ucal_get(cal
, UCAL_DAY_OF_WEEK_IN_MONTH
, &status
)!=2 || ucal_get(cal
, UCAL_DAY_OF_WEEK
, &status
)!=6
798 || ucal_get(cal
, UCAL_WEEK_OF_MONTH
, &status
)!=2 || ucal_get(cal
, UCAL_WEEK_OF_YEAR
, &status
)!= 11)
799 log_err("FAIL: error in ucal_get()\n");
801 log_verbose("PASS: ucal_get() works fine\n");
803 /*Testing the ucal_set() , ucal_clear() functions of calendar*/
804 log_verbose("\nTesting the set, and clear field functions of calendar\n");
805 ucal_setAttribute(cal
, UCAL_LENIENT
, 0);
807 ucal_set(cal
, UCAL_YEAR
, 1997);
808 ucal_set(cal
, UCAL_MONTH
, UCAL_JUNE
);
809 ucal_set(cal
, UCAL_DATE
, 3);
810 verify1("1997 third day of June = ", cal
, datdef
, 1997, UCAL_JUNE
, 3);
812 ucal_set(cal
, UCAL_YEAR
, 1997);
813 ucal_set(cal
, UCAL_DAY_OF_WEEK
, UCAL_TUESDAY
);
814 ucal_set(cal
, UCAL_MONTH
, UCAL_JUNE
);
815 ucal_set(cal
, UCAL_DAY_OF_WEEK_IN_MONTH
, 1);
816 verify1("1997 first Tuesday in June = ", cal
, datdef
, 1997, UCAL_JUNE
, 3);
818 ucal_set(cal
, UCAL_YEAR
, 1997);
819 ucal_set(cal
, UCAL_DAY_OF_WEEK
, UCAL_TUESDAY
);
820 ucal_set(cal
, UCAL_MONTH
, UCAL_JUNE
);
821 ucal_set(cal
, UCAL_DAY_OF_WEEK_IN_MONTH
, - 1);
822 verify1("1997 last Tuesday in June = ", cal
, datdef
,1997, UCAL_JUNE
, 24);
823 /*give undesirable input */
824 status
= U_ZERO_ERROR
;
826 ucal_set(cal
, UCAL_YEAR
, 1997);
827 ucal_set(cal
, UCAL_DAY_OF_WEEK
, UCAL_TUESDAY
);
828 ucal_set(cal
, UCAL_MONTH
, UCAL_JUNE
);
829 ucal_set(cal
, UCAL_DAY_OF_WEEK_IN_MONTH
, 0);
830 d1
= ucal_getMillis(cal
, &status
);
831 if (status
!= U_ILLEGAL_ARGUMENT_ERROR
) {
832 log_err("FAIL: U_ILLEGAL_ARGUMENT_ERROR was not returned for : 1997 zero-th Tuesday in June\n");
834 log_verbose("PASS: U_ILLEGAL_ARGUMENT_ERROR as expected\n");
836 status
= U_ZERO_ERROR
;
838 ucal_set(cal
, UCAL_YEAR
, 1997);
839 ucal_set(cal
, UCAL_DAY_OF_WEEK
, UCAL_TUESDAY
);
840 ucal_set(cal
, UCAL_MONTH
, UCAL_JUNE
);
841 ucal_set(cal
, UCAL_WEEK_OF_MONTH
, 1);
842 verify1("1997 Tuesday in week 1 of June = ", cal
,datdef
, 1997, UCAL_JUNE
, 3);
844 ucal_set(cal
, UCAL_YEAR
, 1997);
845 ucal_set(cal
, UCAL_DAY_OF_WEEK
, UCAL_TUESDAY
);
846 ucal_set(cal
, UCAL_MONTH
, UCAL_JUNE
);
847 ucal_set(cal
, UCAL_WEEK_OF_MONTH
, 5);
848 verify1("1997 Tuesday in week 5 of June = ", cal
,datdef
, 1997, UCAL_JULY
, 1);
849 status
= U_ZERO_ERROR
;
851 ucal_set(cal
, UCAL_YEAR
, 1997);
852 ucal_set(cal
, UCAL_DAY_OF_WEEK
, UCAL_TUESDAY
);
853 ucal_set(cal
, UCAL_MONTH
, UCAL_JUNE
);
854 ucal_set(cal
, UCAL_WEEK_OF_MONTH
, 0);
855 ucal_setAttribute(cal
, UCAL_MINIMAL_DAYS_IN_FIRST_WEEK
,1);
856 d1
= ucal_getMillis(cal
,&status
);
857 if (status
!= U_ILLEGAL_ARGUMENT_ERROR
){
858 log_err("FAIL: U_ILLEGAL_ARGUMENT_ERROR was not returned for : 1997 Tuesday zero-th week in June\n");
860 log_verbose("PASS: U_ILLEGAL_ARGUMENT_ERROR as expected\n");
862 status
= U_ZERO_ERROR
;
864 ucal_set(cal
, UCAL_YEAR_WOY
, 1997);
865 ucal_set(cal
, UCAL_DAY_OF_WEEK
, UCAL_TUESDAY
);
866 ucal_set(cal
, UCAL_WEEK_OF_YEAR
, 1);
867 verify1("1997 Tuesday in week 1 of year = ", cal
, datdef
,1996, UCAL_DECEMBER
, 31);
869 ucal_set(cal
, UCAL_YEAR
, 1997);
870 ucal_set(cal
, UCAL_DAY_OF_WEEK
, UCAL_TUESDAY
);
871 ucal_set(cal
, UCAL_WEEK_OF_YEAR
, 10);
872 verify1("1997 Tuesday in week 10 of year = ", cal
,datdef
, 1997, UCAL_MARCH
, 4);
874 ucal_set(cal
, UCAL_YEAR
, 1999);
875 ucal_set(cal
, UCAL_DAY_OF_YEAR
, 1);
876 verify1("1999 1st day of the year =", cal
, datdef
, 1999, UCAL_JANUARY
, 1);
877 ucal_set(cal
, UCAL_MONTH
, -3);
878 d1
= ucal_getMillis(cal
,&status
);
879 if (status
!= U_ILLEGAL_ARGUMENT_ERROR
){
880 log_err("FAIL: U_ILLEGAL_ARGUMENT_ERROR was not returned for : 1999 -3th month\n");
882 log_verbose("PASS: U_ILLEGAL_ARGUMENT_ERROR as expected\n");
885 ucal_setAttribute(cal
, UCAL_LENIENT
, 1);
887 ucal_set(cal
, UCAL_MONTH
, -3);
888 verify1("1999 -3th month should be", cal
, datdef
, 1998, UCAL_OCTOBER
, 1);
891 /*testing isSet and clearField()*/
892 if(!ucal_isSet(cal
, UCAL_WEEK_OF_YEAR
))
893 log_err("FAIL: error in isSet\n");
895 log_verbose("PASS: isSet working fine\n");
896 ucal_clearField(cal
, UCAL_WEEK_OF_YEAR
);
897 if(ucal_isSet(cal
, UCAL_WEEK_OF_YEAR
))
898 log_err("FAIL: there is an error in clearField or isSet\n");
900 log_verbose("PASS :clearField working fine\n");
902 /*-------------------------------*/
916 static const TransitionItem transitionItems
[] = {
917 { "America/Caracas", 2007, UCAL_DECEMBER
, 8, 10 }, /* day before change in UCAL_ZONE_OFFSET */
918 { "US/Pacific", 2011, UCAL_MARCH
, 12, 10 }, /* day before change in UCAL_DST_OFFSET */
922 /* ------------------------------------- */
924 * Execute adding and rolling in Calendar extensively,
926 static void TestAddRollExtensive()
928 const TransitionItem
* itemPtr
;
932 UCalendarDateFields e
;
933 int32_t y
,m
,d
,hr
,min
,sec
,ms
;
934 int32_t maxlimit
= 40;
935 UErrorCode status
= U_ZERO_ERROR
;
936 y
= 1997; m
= UCAL_FEBRUARY
; d
= 1; hr
= 1; min
= 1; sec
= 0; ms
= 0;
938 log_verbose("Testing add and roll extensively\n");
940 u_uastrcpy(tzID
, "PST");
941 /*open the calendar used */
942 cal
=ucal_open(tzID
, u_strlen(tzID
), "en_US", UCAL_GREGORIAN
, &status
);;
943 if (U_FAILURE(status
)) {
944 log_data_err("ucal_open() failed : %s - (Are you missing data?)\n", u_errorName(status
));
948 ucal_set(cal
, UCAL_YEAR
, y
);
949 ucal_set(cal
, UCAL_MONTH
, m
);
950 ucal_set(cal
, UCAL_DATE
, d
);
951 ucal_setAttribute(cal
, UCAL_MINIMAL_DAYS_IN_FIRST_WEEK
,1);
953 /* Confirm that adding to various fields works.*/
954 log_verbose("\nTesting to confirm that adding to various fields works with ucal_add()\n");
955 checkDate(cal
, y
, m
, d
);
956 ucal_add(cal
,UCAL_YEAR
, 1, &status
);
957 if (U_FAILURE(status
)) { log_err("ucal_add failed: %s\n", u_errorName(status
)); return; }
959 checkDate(cal
, y
, m
, d
);
960 ucal_add(cal
,UCAL_MONTH
, 12, &status
);
961 if (U_FAILURE(status
)) { log_err("ucal_add failed: %s\n", u_errorName(status
) ); return; }
963 checkDate(cal
, y
, m
, d
);
964 ucal_add(cal
,UCAL_DATE
, 1, &status
);
965 if (U_FAILURE(status
)) { log_err("ucal_add failed: %s\n", u_errorName(status
) ); return; }
967 checkDate(cal
, y
, m
, d
);
968 ucal_add(cal
,UCAL_DATE
, 2, &status
);
969 if (U_FAILURE(status
)) { log_err("ucal_add failed: %s\n", u_errorName(status
) ); return; }
971 checkDate(cal
, y
, m
, d
);
972 ucal_add(cal
,UCAL_DATE
, 28, &status
);
973 if (U_FAILURE(status
)) { log_err("ucal_add failed: %s\n", u_errorName(status
) ); return; }
975 checkDate(cal
, y
, m
, d
);
976 ucal_add(cal
, (UCalendarDateFields
)-1, 10, &status
);
977 if(status
==U_ILLEGAL_ARGUMENT_ERROR
)
978 log_verbose("Pass: Illegal argument error as expected\n");
980 log_err("Fail: No, illegal argument error as expected. Got....: %s\n", u_errorName(status
));
985 /*confirm that applying roll to various fields works fine*/
986 log_verbose("\nTesting to confirm that ucal_roll() works\n");
987 ucal_roll(cal
, UCAL_DATE
, -1, &status
);
988 if (U_FAILURE(status
)) { log_err("ucal_roll failed: %s\n", u_errorName(status
) ); return; }
990 checkDate(cal
, y
, m
, d
);
991 ucal_roll(cal
, UCAL_MONTH
, -2, &status
);
992 if (U_FAILURE(status
)) { log_err("ucal_roll failed: %s\n", u_errorName(status
) ); return; }
994 checkDate(cal
, y
, m
, d
);
995 ucal_roll(cal
, UCAL_DATE
, 1, &status
);
996 if (U_FAILURE(status
)) { log_err("ucal_roll failed: %s\n", u_errorName(status
) ); return; }
998 checkDate(cal
, y
, m
, d
);
999 ucal_roll(cal
, UCAL_MONTH
, -12, &status
);
1000 if (U_FAILURE(status
)) { log_err("ucal_roll failed: %s\n", u_errorName(status
) ); return; }
1001 checkDate(cal
, y
, m
, d
);
1002 ucal_roll(cal
, UCAL_YEAR
, -1, &status
);
1003 if (U_FAILURE(status
)) { log_err("ucal_roll failed: %s\n", u_errorName(status
) ); return; }
1005 checkDate(cal
, y
, m
, d
);
1006 ucal_roll(cal
, UCAL_DATE
, 29, &status
);
1007 if (U_FAILURE(status
)) { log_err("ucal_roll failed: %s\n", u_errorName(status
) ); return; }
1009 checkDate(cal
, y
, m
, d
);
1010 ucal_roll(cal
, (UCalendarDateFields
)-1, 10, &status
);
1011 if(status
==U_ILLEGAL_ARGUMENT_ERROR
)
1012 log_verbose("Pass: illegal arguement error as expected\n");
1014 log_err("Fail: no illegal argument error got..: %s\n", u_errorName(status
));
1017 status
=U_ZERO_ERROR
;
1019 ucal_setDateTime(cal
, 1999, UCAL_FEBRUARY
, 28, 10, 30, 45, &status
);
1020 if(U_FAILURE(status
)){
1021 log_err("error is setting the datetime: %s\n", u_errorName(status
));
1023 ucal_add(cal
, UCAL_MONTH
, 1, &status
);
1024 checkDate(cal
, 1999, UCAL_MARCH
, 28);
1025 ucal_add(cal
, UCAL_MILLISECOND
, 1000, &status
);
1026 checkDateTime(cal
, 1999, UCAL_MARCH
, 28, 10, 30, 46, 0, UCAL_MILLISECOND
);
1029 /*--------------- */
1030 status
=U_ZERO_ERROR
;
1031 /* Testing add and roll extensively */
1032 log_verbose("\nTesting the ucal_add() and ucal_roll() functions extensively\n");
1033 y
= 1997; m
= UCAL_FEBRUARY
; d
= 1; hr
= 1; min
= 1; sec
= 0; ms
= 0;
1034 cal
=ucal_open(tzID
, u_strlen(tzID
), "en_US", UCAL_TRADITIONAL
, &status
);
1035 if (U_FAILURE(status
)) {
1036 log_err("ucal_open failed: %s\n", u_errorName(status
));
1039 ucal_set(cal
, UCAL_YEAR
, y
);
1040 ucal_set(cal
, UCAL_MONTH
, m
);
1041 ucal_set(cal
, UCAL_DATE
, d
);
1042 ucal_set(cal
, UCAL_HOUR
, hr
);
1043 ucal_set(cal
, UCAL_MINUTE
, min
);
1044 ucal_set(cal
, UCAL_SECOND
,sec
);
1045 ucal_set(cal
, UCAL_MILLISECOND
, ms
);
1046 ucal_setAttribute(cal
, UCAL_MINIMAL_DAYS_IN_FIRST_WEEK
,1);
1047 status
=U_ZERO_ERROR
;
1049 log_verbose("\nTesting UCalendar add...\n");
1050 for(e
= UCAL_YEAR
;e
< UCAL_FIELD_COUNT
; e
=(UCalendarDateFields
)((int32_t)e
+ 1)) {
1052 status
= U_ZERO_ERROR
;
1053 for (i
= 0; i
< limit
; i
++) {
1054 ucal_add(cal
, e
, 1, &status
);
1055 if (U_FAILURE(status
)) { limit
= i
; status
= U_ZERO_ERROR
; }
1057 for (i
= 0; i
< limit
; i
++) {
1058 ucal_add(cal
, e
, -1, &status
);
1059 if (U_FAILURE(status
)) {
1060 log_err("ucal_add -1 failed: %s\n", u_errorName(status
));
1064 checkDateTime(cal
, y
, m
, d
, hr
, min
, sec
, ms
, e
);
1066 log_verbose("\nTesting calendar ucal_roll()...\n");
1067 for(e
= UCAL_YEAR
;e
< UCAL_FIELD_COUNT
; e
=(UCalendarDateFields
)((int32_t)e
+ 1)) {
1069 status
= U_ZERO_ERROR
;
1070 for (i
= 0; i
< limit
; i
++) {
1071 ucal_roll(cal
, e
, 1, &status
);
1072 if (U_FAILURE(status
)) {
1074 status
= U_ZERO_ERROR
;
1077 for (i
= 0; i
< limit
; i
++) {
1078 ucal_roll(cal
, e
, -1, &status
);
1079 if (U_FAILURE(status
)) {
1080 log_err("ucal_roll -1 failed: %s\n", u_errorName(status
));
1084 checkDateTime(cal
, y
, m
, d
, hr
, min
, sec
, ms
, e
);
1088 /*--------------- */
1089 log_verbose("\nTesting ucal_add() across ZONE_OFFSET and DST_OFFSE transitions.\n");
1090 for (itemPtr
= transitionItems
; itemPtr
->zone
!= NULL
; itemPtr
++) {
1091 status
=U_ZERO_ERROR
;
1092 u_uastrcpy(tzID
, itemPtr
->zone
);
1093 cal
=ucal_open(tzID
, u_strlen(tzID
), "en_US", UCAL_GREGORIAN
, &status
);
1094 if (U_FAILURE(status
)) {
1095 log_err("ucal_open failed for zone %s: %s\n", itemPtr
->zone
, u_errorName(status
));
1098 ucal_setDateTime(cal
, itemPtr
->year
, itemPtr
->month
, itemPtr
->day
, itemPtr
->hour
, 0, 0, &status
);
1099 ucal_add(cal
, UCAL_DATE
, 1, &status
);
1100 hr
= ucal_get(cal
, UCAL_HOUR_OF_DAY
, &status
);
1101 if ( U_FAILURE(status
) ) {
1102 log_err("ucal_add failed adding day across transition for zone %s: %s\n", itemPtr
->zone
, u_errorName(status
));
1103 } else if ( hr
!= itemPtr
->hour
) {
1104 log_err("ucal_add produced wrong hour %d when adding day across transition for zone %s\n", hr
, itemPtr
->zone
);
1106 ucal_add(cal
, UCAL_DATE
, -1, &status
);
1107 hr
= ucal_get(cal
, UCAL_HOUR_OF_DAY
, &status
);
1108 if ( U_FAILURE(status
) ) {
1109 log_err("ucal_add failed subtracting day across transition for zone %s: %s\n", itemPtr
->zone
, u_errorName(status
));
1110 } else if ( hr
!= itemPtr
->hour
) {
1111 log_err("ucal_add produced wrong hour %d when subtracting day across transition for zone %s\n", hr
, itemPtr
->zone
);
1118 /*------------------------------------------------------ */
1119 /*Testing the Limits for various Fields of Calendar*/
1120 static void TestGetLimits()
1123 int32_t min
, max
, gr_min
, le_max
, ac_min
, ac_max
, val
;
1125 UErrorCode status
= U_ZERO_ERROR
;
1128 u_uastrcpy(tzID
, "PST");
1129 /*open the calendar used */
1130 cal
=ucal_open(tzID
, u_strlen(tzID
), "en_US", UCAL_GREGORIAN
, &status
);;
1131 if (U_FAILURE(status
)) {
1132 log_data_err("ucal_open() for gregorian calendar failed in TestGetLimits: %s - (Are you missing data?)\n", u_errorName(status
));
1136 log_verbose("\nTesting the getLimits function for various fields\n");
1140 ucal_setDate(cal
, 1999, UCAL_MARCH
, 5, &status
); /* Set the date to be March 5, 1999 */
1141 val
= ucal_get(cal
, UCAL_DAY_OF_WEEK
, &status
);
1142 min
= ucal_getLimit(cal
, UCAL_DAY_OF_WEEK
, UCAL_MINIMUM
, &status
);
1143 max
= ucal_getLimit(cal
, UCAL_DAY_OF_WEEK
, UCAL_MAXIMUM
, &status
);
1144 if ( (min
!= UCAL_SUNDAY
|| max
!= UCAL_SATURDAY
) && (min
> val
&& val
> max
) && (val
!= UCAL_FRIDAY
)){
1145 log_err("FAIL: Min/max bad\n");
1146 log_err("FAIL: Day of week %d out of range\n", val
);
1147 log_err("FAIL: FAIL: Day of week should be SUNDAY Got %d\n", val
);
1150 log_verbose("getLimits successful\n");
1152 val
= ucal_get(cal
, UCAL_DAY_OF_WEEK_IN_MONTH
, &status
);
1153 min
= ucal_getLimit(cal
, UCAL_DAY_OF_WEEK_IN_MONTH
, UCAL_MINIMUM
, &status
);
1154 max
= ucal_getLimit(cal
, UCAL_DAY_OF_WEEK_IN_MONTH
, UCAL_MAXIMUM
, &status
);
1155 if ( (min
!= 0 || max
!= 5 ) && (min
> val
&& val
> max
) && (val
!= 1)){
1156 log_err("FAIL: Min/max bad\n");
1157 log_err("FAIL: Day of week in month %d out of range\n", val
);
1158 log_err("FAIL: FAIL: Day of week in month should be SUNDAY Got %d\n", val
);
1162 log_verbose("getLimits successful\n");
1164 min
=ucal_getLimit(cal
, UCAL_MONTH
, UCAL_MINIMUM
, &status
);
1165 max
=ucal_getLimit(cal
, UCAL_MONTH
, UCAL_MAXIMUM
, &status
);
1166 gr_min
=ucal_getLimit(cal
, UCAL_MONTH
, UCAL_GREATEST_MINIMUM
, &status
);
1167 le_max
=ucal_getLimit(cal
, UCAL_MONTH
, UCAL_LEAST_MAXIMUM
, &status
);
1168 ac_min
=ucal_getLimit(cal
, UCAL_MONTH
, UCAL_ACTUAL_MINIMUM
, &status
);
1169 ac_max
=ucal_getLimit(cal
, UCAL_MONTH
, UCAL_ACTUAL_MAXIMUM
, &status
);
1170 if(U_FAILURE(status
)){
1171 log_err("Error in getLimits: %s\n", u_errorName(status
));
1173 if(min
!=0 || max
!=11 || gr_min
!=0 || le_max
!=11 || ac_min
!=0 || ac_max
!=11)
1174 log_err("There is and error in getLimits in fetching the values\n");
1176 log_verbose("getLimits successful\n");
1178 ucal_setDateTime(cal
, 1999, UCAL_MARCH
, 5, 4, 10, 35, &status
);
1179 val
=ucal_get(cal
, UCAL_HOUR_OF_DAY
, &status
);
1180 min
=ucal_getLimit(cal
, UCAL_HOUR_OF_DAY
, UCAL_MINIMUM
, &status
);
1181 max
=ucal_getLimit(cal
, UCAL_HOUR_OF_DAY
, UCAL_MAXIMUM
, &status
);
1182 gr_min
=ucal_getLimit(cal
, UCAL_MINUTE
, UCAL_GREATEST_MINIMUM
, &status
);
1183 le_max
=ucal_getLimit(cal
, UCAL_MINUTE
, UCAL_LEAST_MAXIMUM
, &status
);
1184 ac_min
=ucal_getLimit(cal
, UCAL_MINUTE
, UCAL_ACTUAL_MINIMUM
, &status
);
1185 ac_max
=ucal_getLimit(cal
, UCAL_SECOND
, UCAL_ACTUAL_MAXIMUM
, &status
);
1186 if( (min
!=0 || max
!= 11 || gr_min
!=0 || le_max
!=60 || ac_min
!=0 || ac_max
!=60) &&
1187 (min
>val
&& val
>max
) && val
!=4){
1189 log_err("FAIL: Min/max bad\n");
1190 log_err("FAIL: Hour of Day %d out of range\n", val
);
1191 log_err("FAIL: HOUR_OF_DAY should be 4 Got %d\n", val
);
1194 log_verbose("getLimits successful\n");
1197 /*get BOGUS_LIMIT type*/
1198 val
=ucal_getLimit(cal
, UCAL_SECOND
, (UCalendarLimitType
)99, &status
);
1200 log_err("FAIL: ucal_getLimit() with BOGUS type should return -1\n");
1202 status
=U_ZERO_ERROR
;
1210 /* ------------------------------------- */
1213 * Test that the days of the week progress properly when add is called repeatedly
1214 * for increments of 24 days.
1216 static void TestDOWProgression()
1218 int32_t initialDOW
, DOW
, newDOW
, expectedDOW
;
1220 UDateFormat
*datfor
= 0;
1223 UErrorCode status
= U_ZERO_ERROR
;
1225 char tempMsgBuf
[256];
1226 u_strcpy(tzID
, fgGMTID
);
1227 /*open the calendar used */
1228 cal
=ucal_open(tzID
, u_strlen(tzID
), "en_US", UCAL_TRADITIONAL
, &status
);;
1229 if (U_FAILURE(status
)) {
1230 log_data_err("ucal_open failed: %s - (Are you missing data?)\n", u_errorName(status
));
1234 datfor
=udat_open(UDAT_MEDIUM
,UDAT_MEDIUM
,NULL
, fgGMTID
,-1,NULL
, 0, &status
);
1235 if(U_FAILURE(status
)){
1236 log_data_err("error in creating the dateformat : %s (Are you missing data?)\n", u_errorName(status
));
1240 ucal_setDate(cal
, 1999, UCAL_JANUARY
, 1, &status
);
1242 log_verbose("\nTesting the DOW progression\n");
1244 initialDOW
= ucal_get(cal
, UCAL_DAY_OF_WEEK
, &status
);
1245 if (U_FAILURE(status
)) { log_data_err("ucal_get() failed: %s (Are you missing data?)\n", u_errorName(status
) ); return; }
1246 newDOW
= initialDOW
;
1249 log_verbose("DOW = %d...\n", DOW
);
1250 date1
=ucal_getMillis(cal
, &status
);
1251 if(U_FAILURE(status
)){ log_err("ucal_getMiilis() failed: %s\n", u_errorName(status
)); return;}
1252 log_verbose("%s\n", u_austrcpy(tempMsgBuf
, myDateFormat(datfor
, date1
)));
1254 ucal_add(cal
,UCAL_DAY_OF_WEEK
, delta
, &status
);
1255 if (U_FAILURE(status
)) { log_err("ucal_add() failed: %s\n", u_errorName(status
)); return; }
1257 newDOW
= ucal_get(cal
, UCAL_DAY_OF_WEEK
, &status
);
1258 if (U_FAILURE(status
)) { log_err("ucal_get() failed: %s\n", u_errorName(status
)); return; }
1259 expectedDOW
= 1 + (DOW
+ delta
- 1) % 7;
1260 date1
=ucal_getMillis(cal
, &status
);
1261 if(U_FAILURE(status
)){ log_err("ucal_getMiilis() failed: %s\n", u_errorName(status
)); return;}
1262 if (newDOW
!= expectedDOW
) {
1263 log_err("Day of week should be %d instead of %d on %s", expectedDOW
, newDOW
,
1264 u_austrcpy(tempMsgBuf
, myDateFormat(datfor
, date1
)) );
1268 while (newDOW
!= initialDOW
);
1274 /* ------------------------------------- */
1277 * Confirm that the offset between local time and GMT behaves as expected.
1279 static void TestGMTvsLocal()
1281 log_verbose("\nTesting the offset between the GMT and local time\n");
1282 testZones(1999, 1, 1, 12, 0, 0);
1283 testZones(1999, 4, 16, 18, 30, 0);
1284 testZones(1998, 12, 17, 19, 0, 0);
1287 /* ------------------------------------- */
1289 static void testZones(int32_t yr
, int32_t mo
, int32_t dt
, int32_t hr
, int32_t mn
, int32_t sc
)
1291 int32_t offset
,utc
, expected
;
1292 UCalendar
*gmtcal
= 0, *cal
= 0;
1295 UDateFormat
*datfor
= 0;
1296 UErrorCode status
= U_ZERO_ERROR
;
1298 char tempMsgBuf
[256];
1300 u_strcpy(tzID
, fgGMTID
);
1301 gmtcal
=ucal_open(tzID
, 3, "en_US", UCAL_TRADITIONAL
, &status
);;
1302 if (U_FAILURE(status
)) {
1303 log_data_err("ucal_open failed: %s - (Are you missing data?)\n", u_errorName(status
));
1306 u_uastrcpy(tzID
, "PST");
1307 cal
= ucal_open(tzID
, 3, "en_US", UCAL_TRADITIONAL
, &status
);
1308 if (U_FAILURE(status
)) {
1309 log_err("ucal_open failed: %s\n", u_errorName(status
));
1313 datfor
=udat_open(UDAT_MEDIUM
,UDAT_MEDIUM
,NULL
, fgGMTID
,-1,NULL
, 0, &status
);
1314 if(U_FAILURE(status
)){
1315 log_data_err("error in creating the dateformat : %s (Are you missing data?)\n", u_errorName(status
));
1318 ucal_setDateTime(gmtcal
, yr
, mo
- 1, dt
, hr
, mn
, sc
, &status
);
1319 if (U_FAILURE(status
)) {
1320 log_data_err("ucal_setDateTime failed: %s (Are you missing data?)\n", u_errorName(status
));
1323 ucal_set(gmtcal
, UCAL_MILLISECOND
, 0);
1324 date1
= ucal_getMillis(gmtcal
, &status
);
1325 if (U_FAILURE(status
)) {
1326 log_err("ucal_getMillis failed: %s\n", u_errorName(status
));
1329 log_verbose("date = %s\n", u_austrcpy(tempMsgBuf
, myDateFormat(datfor
, date1
)) );
1332 ucal_setMillis(cal
, date1
, &status
);
1333 if (U_FAILURE(status
)) {
1334 log_err("ucal_setMillis() failed: %s\n", u_errorName(status
));
1338 offset
= ucal_get(cal
, UCAL_ZONE_OFFSET
, &status
);
1339 offset
+= ucal_get(cal
, UCAL_DST_OFFSET
, &status
);
1341 if (U_FAILURE(status
)) {
1342 log_err("ucal_get() failed: %s\n", u_errorName(status
));
1345 temp
=(double)((double)offset
/ 1000.0 / 60.0 / 60.0);
1346 /*printf("offset for %s %f hr\n", austrdup(myDateFormat(datfor, date1)), temp);*/
1348 utc
= ((ucal_get(cal
, UCAL_HOUR_OF_DAY
, &status
) * 60 +
1349 ucal_get(cal
, UCAL_MINUTE
, &status
)) * 60 +
1350 ucal_get(cal
, UCAL_SECOND
, &status
)) * 1000 +
1351 ucal_get(cal
, UCAL_MILLISECOND
, &status
) - offset
;
1352 if (U_FAILURE(status
)) {
1353 log_err("ucal_get() failed: %s\n", u_errorName(status
));
1357 expected
= ((hr
* 60 + mn
) * 60 + sc
) * 1000;
1358 if (utc
!= expected
) {
1359 temp
=(double)(utc
- expected
)/ 1000 / 60 / 60.0;
1360 log_err("FAIL: Discrepancy of %d millis = %fhr\n", utc
-expected
, temp
);
1363 log_verbose("PASS: the offset between local and GMT is correct\n");
1369 /* ------------------------------------- */
1374 /* INTERNAL FUNCTIONS USED */
1375 /*------------------------------------------------------------------------------------------- */
1377 /* ------------------------------------- */
1378 static void checkDateTime(UCalendar
* c
,
1379 int32_t y
, int32_t m
, int32_t d
,
1380 int32_t hr
, int32_t min
, int32_t sec
,
1381 int32_t ms
, UCalendarDateFields field
)
1384 UErrorCode status
= U_ZERO_ERROR
;
1385 if (ucal_get(c
, UCAL_YEAR
, &status
) != y
||
1386 ucal_get(c
, UCAL_MONTH
, &status
) != m
||
1387 ucal_get(c
, UCAL_DATE
, &status
) != d
||
1388 ucal_get(c
, UCAL_HOUR
, &status
) != hr
||
1389 ucal_get(c
, UCAL_MINUTE
, &status
) != min
||
1390 ucal_get(c
, UCAL_SECOND
, &status
) != sec
||
1391 ucal_get(c
, UCAL_MILLISECOND
, &status
) != ms
) {
1392 log_err("U_FAILURE for field %d, Expected y/m/d h:m:s:ms of %d/%d/%d %d:%d:%d:%d got %d/%d/%d %d:%d:%d:%d\n",
1393 (int32_t)field
, y
, m
+ 1, d
, hr
, min
, sec
, ms
,
1394 ucal_get(c
, UCAL_YEAR
, &status
),
1395 ucal_get(c
, UCAL_MONTH
, &status
) + 1,
1396 ucal_get(c
, UCAL_DATE
, &status
),
1397 ucal_get(c
, UCAL_HOUR
, &status
),
1398 ucal_get(c
, UCAL_MINUTE
, &status
) + 1,
1399 ucal_get(c
, UCAL_SECOND
, &status
),
1400 ucal_get(c
, UCAL_MILLISECOND
, &status
) );
1402 if (U_FAILURE(status
)){
1403 log_err("ucal_get failed: %s\n", u_errorName(status
));
1409 log_verbose("Confirmed: %d/%d/%d %d:%d:%d:%d\n", y
, m
+ 1, d
, hr
, min
, sec
, ms
);
1413 /* ------------------------------------- */
1414 static void checkDate(UCalendar
* c
, int32_t y
, int32_t m
, int32_t d
)
1416 UErrorCode status
= U_ZERO_ERROR
;
1417 if (ucal_get(c
,UCAL_YEAR
, &status
) != y
||
1418 ucal_get(c
, UCAL_MONTH
, &status
) != m
||
1419 ucal_get(c
, UCAL_DATE
, &status
) != d
) {
1421 log_err("FAILURE: Expected y/m/d of %d/%d/%d got %d/%d/%d\n", y
, m
+ 1, d
,
1422 ucal_get(c
, UCAL_YEAR
, &status
),
1423 ucal_get(c
, UCAL_MONTH
, &status
) + 1,
1424 ucal_get(c
, UCAL_DATE
, &status
) );
1426 if (U_FAILURE(status
)) {
1427 log_err("ucal_get failed: %s\n", u_errorName(status
));
1432 log_verbose("Confirmed: %d/%d/%d\n", y
, m
+ 1, d
);
1437 /* ------------------------------------- */
1439 /* ------------------------------------- */
1441 static void verify1(const char* msg
, UCalendar
* c
, UDateFormat
* dat
, int32_t year
, int32_t month
, int32_t day
)
1444 UErrorCode status
= U_ZERO_ERROR
;
1445 if (ucal_get(c
, UCAL_YEAR
, &status
) == year
&&
1446 ucal_get(c
, UCAL_MONTH
, &status
) == month
&&
1447 ucal_get(c
, UCAL_DATE
, &status
) == day
) {
1448 if (U_FAILURE(status
)) {
1449 log_err("FAIL: Calendar::get failed: %s\n", u_errorName(status
));
1452 log_verbose("PASS: %s\n", msg
);
1453 d1
=ucal_getMillis(c
, &status
);
1454 if (U_FAILURE(status
)) {
1455 log_err("ucal_getMillis failed: %s\n", u_errorName(status
));
1458 /*log_verbose(austrdup(myDateFormat(dat, d1)) );*/
1461 log_err("FAIL: %s\n", msg
);
1462 d1
=ucal_getMillis(c
, &status
);
1463 if (U_FAILURE(status
)) {
1464 log_err("ucal_getMillis failed: %s\n", u_errorName(status
) );
1467 log_err("Got %s Expected %d/%d/%d \n", austrdup(myDateFormat(dat
, d1
)), year
, month
+ 1, day
);
1474 /* ------------------------------------ */
1475 static void verify2(const char* msg
, UCalendar
* c
, UDateFormat
* dat
, int32_t year
, int32_t month
, int32_t day
,
1476 int32_t hour
, int32_t min
, int32_t sec
, int32_t am_pm
)
1479 UErrorCode status
= U_ZERO_ERROR
;
1480 char tempMsgBuf
[256];
1482 if (ucal_get(c
, UCAL_YEAR
, &status
) == year
&&
1483 ucal_get(c
, UCAL_MONTH
, &status
) == month
&&
1484 ucal_get(c
, UCAL_DATE
, &status
) == day
&&
1485 ucal_get(c
, UCAL_HOUR
, &status
) == hour
&&
1486 ucal_get(c
, UCAL_MINUTE
, &status
) == min
&&
1487 ucal_get(c
, UCAL_SECOND
, &status
) == sec
&&
1488 ucal_get(c
, UCAL_AM_PM
, &status
) == am_pm
){
1489 if (U_FAILURE(status
)) {
1490 log_err("FAIL: Calendar::get failed: %s\n", u_errorName(status
));
1493 log_verbose("PASS: %s\n", msg
);
1494 d1
=ucal_getMillis(c
, &status
);
1495 if (U_FAILURE(status
)) {
1496 log_err("ucal_getMillis failed: %s\n", u_errorName(status
));
1499 log_verbose("%s\n" , u_austrcpy(tempMsgBuf
, myDateFormat(dat
, d1
)) );
1502 log_err("FAIL: %s\n", msg
);
1503 d1
=ucal_getMillis(c
, &status
);
1504 if (U_FAILURE(status
)) {
1505 log_err("ucal_getMillis failed: %s\n", u_errorName(status
));
1508 log_err("Got %s Expected %d/%d/%d/ %d:%d:%d %s\n", austrdup(myDateFormat(dat
, d1
)),
1509 year
, month
+ 1, day
, hour
, min
, sec
, (am_pm
==0) ? "AM": "PM");
1517 void TestGregorianChange() {
1518 static const UChar utc
[] = { 0x45, 0x74, 0x63, 0x2f, 0x47, 0x4d, 0x54, 0 }; /* "Etc/GMT" */
1519 const int32_t dayMillis
= 86400 * INT64_C(1000); /* 1 day = 86400 seconds */
1522 UErrorCode errorCode
= U_ZERO_ERROR
;
1524 /* Test ucal_setGregorianChange() on a Gregorian calendar. */
1525 errorCode
= U_ZERO_ERROR
;
1526 cal
= ucal_open(utc
, -1, "", UCAL_GREGORIAN
, &errorCode
);
1527 if(U_FAILURE(errorCode
)) {
1528 log_data_err("ucal_open(UTC) failed: %s - (Are you missing data?)\n", u_errorName(errorCode
));
1531 ucal_setGregorianChange(cal
, -365 * (dayMillis
* (UDate
)1), &errorCode
);
1532 if(U_FAILURE(errorCode
)) {
1533 log_err("ucal_setGregorianChange(1969) failed: %s\n", u_errorName(errorCode
));
1535 date
= ucal_getGregorianChange(cal
, &errorCode
);
1536 if(U_FAILURE(errorCode
) || date
!= -365 * (dayMillis
* (UDate
)1)) {
1537 log_err("ucal_getGregorianChange() failed: %s, date = %f\n", u_errorName(errorCode
), date
);
1542 /* Test ucal_setGregorianChange() on a non-Gregorian calendar where it should fail. */
1543 errorCode
= U_ZERO_ERROR
;
1544 cal
= ucal_open(utc
, -1, "th@calendar=buddhist", UCAL_TRADITIONAL
, &errorCode
);
1545 if(U_FAILURE(errorCode
)) {
1546 log_err("ucal_open(UTC, non-Gregorian) failed: %s\n", u_errorName(errorCode
));
1549 ucal_setGregorianChange(cal
, -730 * (dayMillis
* (UDate
)1), &errorCode
);
1550 if(errorCode
!= U_UNSUPPORTED_ERROR
) {
1551 log_err("ucal_setGregorianChange(non-Gregorian calendar) did not yield U_UNSUPPORTED_ERROR but %s\n",
1552 u_errorName(errorCode
));
1554 errorCode
= U_ZERO_ERROR
;
1555 date
= ucal_getGregorianChange(cal
, &errorCode
);
1556 if(errorCode
!= U_UNSUPPORTED_ERROR
) {
1557 log_err("ucal_getGregorianChange(non-Gregorian calendar) did not yield U_UNSUPPORTED_ERROR but %s\n",
1558 u_errorName(errorCode
));
1563 static void TestGetKeywordValuesForLocale() {
1564 #define PREFERRED_SIZE 16
1565 #define MAX_NUMBER_OF_KEYWORDS 5
1566 const char *PREFERRED
[PREFERRED_SIZE
][MAX_NUMBER_OF_KEYWORDS
+1] = {
1567 { "root", "gregorian", NULL
, NULL
, NULL
, NULL
},
1568 { "und", "gregorian", NULL
, NULL
, NULL
, NULL
},
1569 { "en_US", "gregorian", NULL
, NULL
, NULL
, NULL
},
1570 { "en_029", "gregorian", NULL
, NULL
, NULL
, NULL
},
1571 { "th_TH", "buddhist", "gregorian", NULL
, NULL
, NULL
},
1572 { "und_TH", "buddhist", "gregorian", NULL
, NULL
, NULL
},
1573 { "en_TH", "buddhist", "gregorian", NULL
, NULL
, NULL
},
1574 { "he_IL", "gregorian", "hebrew", "islamic", "islamic-civil", "islamic-tbla" },
1575 { "ar_EG", "gregorian", "coptic", "islamic", "islamic-civil", "islamic-tbla" },
1576 { "ja", "gregorian", "japanese", NULL
, NULL
, NULL
},
1577 { "ps_Guru_IN", "gregorian", "indian", NULL
, NULL
, NULL
},
1578 { "th@calendar=gregorian", "buddhist", "gregorian", NULL
, NULL
, NULL
},
1579 { "en@calendar=islamic", "gregorian", NULL
, NULL
, NULL
, NULL
},
1580 { "zh_TW", "gregorian", "roc", "chinese", NULL
, NULL
},
1581 { "ar_IR", "persian", "gregorian", "islamic", "islamic-civil", "islamic-tbla" },
1582 { "th@rg=SAZZZZ", "islamic-umalqura", "islamic-rgsa", "islamic", "gregorian", NULL
},
1584 const int32_t EXPECTED_SIZE
[PREFERRED_SIZE
] = { 1, 1, 1, 1, 2, 2, 2, 5, 5, 2, 2, 2, 1, 3, 5, 4 };
1585 UErrorCode status
= U_ZERO_ERROR
;
1587 UEnumeration
*all
, *pref
;
1588 const char *loc
= NULL
;
1589 UBool matchPref
, matchAll
;
1591 int32_t valueLength
;
1592 UList
*ALLList
= NULL
;
1594 UEnumeration
*ALL
= ucal_getKeywordValuesForLocale("calendar", uloc_getDefault(), FALSE
, &status
);
1595 if (U_SUCCESS(status
)) {
1596 for (i
= 0; i
< PREFERRED_SIZE
; i
++) {
1599 loc
= PREFERRED
[i
][0];
1600 pref
= ucal_getKeywordValuesForLocale("calendar", loc
, TRUE
, &status
);
1607 if (U_SUCCESS(status
) && uenum_count(pref
, &status
) == EXPECTED_SIZE
[i
]) {
1609 for (j
= 0; j
< EXPECTED_SIZE
[i
]; j
++) {
1610 if ((value
= uenum_next(pref
, &valueLength
, &status
)) != NULL
&& U_SUCCESS(status
)) {
1611 if (uprv_strcmp(value
, PREFERRED
[i
][j
+1]) != 0) {
1617 log_err("ERROR getting keyword value for locale \"%s\"\n", loc
);
1624 log_err("FAIL: Preferred values for locale \"%s\" does not match expected.\n", loc
);
1629 all
= ucal_getKeywordValuesForLocale("calendar", loc
, FALSE
, &status
);
1631 size
= uenum_count(all
, &status
);
1633 if (U_SUCCESS(status
) && size
== uenum_count(ALL
, &status
)) {
1635 ALLList
= ulist_getListFromEnum(ALL
);
1636 for (j
= 0; j
< size
; j
++) {
1637 if ((value
= uenum_next(all
, &valueLength
, &status
)) != NULL
&& U_SUCCESS(status
)) {
1638 if (!ulist_containsString(ALLList
, value
, uprv_strlen(value
))) {
1639 log_err("Locale %s have %s not in ALL\n", loc
, value
);
1645 log_err("ERROR getting \"all\" keyword value for locale \"%s\"\n", loc
);
1651 log_err("FAIL: All values for locale \"%s\" does not match expected.\n", loc
);
1657 log_err_status(status
, "Failed to get ALL keyword values for default locale %s: %s.\n", uloc_getDefault(), u_errorName(status
));
1663 * Weekend tests, ported from
1664 * icu4j/trunk/main/tests/core/src/com/ibm/icu/dev/test/calendar/IBMCalendarTest.java
1665 * and extended a bit. Notes below from IBMCalendarTest.java ...
1666 * This test tests for specific locale data. This is probably okay
1667 * as far as US data is concerned, but if the Arabic/Yemen data
1668 * changes, this test will have to be updated.
1676 int32_t millisecOffset
;
1680 const char * locale
;
1681 const TestWeekendDates
* dates
;
1683 } TestWeekendDatesList
;
1685 static const TestWeekendDates weekendDates_en_US
[] = {
1686 { 2000, UCAL_MARCH
, 17, 23, 0, 0 }, /* Fri 23:00 */
1687 { 2000, UCAL_MARCH
, 18, 0, -1, 0 }, /* Fri 23:59:59.999 */
1688 { 2000, UCAL_MARCH
, 18, 0, 0, 1 }, /* Sat 00:00 */
1689 { 2000, UCAL_MARCH
, 18, 15, 0, 1 }, /* Sat 15:00 */
1690 { 2000, UCAL_MARCH
, 19, 23, 0, 1 }, /* Sun 23:00 */
1691 { 2000, UCAL_MARCH
, 20, 0, -1, 1 }, /* Sun 23:59:59.999 */
1692 { 2000, UCAL_MARCH
, 20, 0, 0, 0 }, /* Mon 00:00 */
1693 { 2000, UCAL_MARCH
, 20, 8, 0, 0 }, /* Mon 08:00 */
1695 static const TestWeekendDates weekendDates_ar_OM
[] = {
1696 { 2000, UCAL_MARCH
, 15, 23, 0, 0 }, /* Wed 23:00 */
1697 { 2000, UCAL_MARCH
, 16, 0, -1, 0 }, /* Wed 23:59:59.999 */
1698 { 2000, UCAL_MARCH
, 16, 0, 0, 0 }, /* Thu 00:00 */
1699 { 2000, UCAL_MARCH
, 16, 15, 0, 0 }, /* Thu 15:00 */
1700 { 2000, UCAL_MARCH
, 17, 23, 0, 1 }, /* Fri 23:00 */
1701 { 2000, UCAL_MARCH
, 18, 0, -1, 1 }, /* Fri 23:59:59.999 */
1702 { 2000, UCAL_MARCH
, 18, 0, 0, 1 }, /* Sat 00:00 */
1703 { 2000, UCAL_MARCH
, 18, 8, 0, 1 }, /* Sat 08:00 */
1705 static const TestWeekendDatesList testDates
[] = {
1706 { "en_US", weekendDates_en_US
, UPRV_LENGTHOF(weekendDates_en_US
) },
1707 { "ar_OM", weekendDates_ar_OM
, UPRV_LENGTHOF(weekendDates_ar_OM
) },
1711 UCalendarDaysOfWeek dayOfWeek
;
1712 UCalendarWeekdayType dayType
;
1713 int32_t transition
; /* transition time if dayType is UCAL_WEEKEND_ONSET or UCAL_WEEKEND_CEASE; else must be 0 */
1716 const char * locale
;
1717 const TestDaysOfWeek
* days
;
1719 } TestDaysOfWeekList
;
1721 static const TestDaysOfWeek daysOfWeek_en_US
[] = {
1722 { UCAL_MONDAY
, UCAL_WEEKDAY
, 0 },
1723 { UCAL_FRIDAY
, UCAL_WEEKDAY
, 0 },
1724 { UCAL_SATURDAY
, UCAL_WEEKEND
, 0 },
1725 { UCAL_SUNDAY
, UCAL_WEEKEND
, 0 },
1727 static const TestDaysOfWeek daysOfWeek_ar_OM
[] = { /* Friday:Saturday */
1728 { UCAL_WEDNESDAY
,UCAL_WEEKDAY
, 0 },
1729 { UCAL_THURSDAY
, UCAL_WEEKDAY
, 0 },
1730 { UCAL_FRIDAY
, UCAL_WEEKEND
, 0 },
1731 { UCAL_SATURDAY
, UCAL_WEEKEND
, 0 },
1733 static const TestDaysOfWeek daysOfWeek_hi_IN
[] = { /* Sunday only */
1734 { UCAL_MONDAY
, UCAL_WEEKDAY
, 0 },
1735 { UCAL_FRIDAY
, UCAL_WEEKDAY
, 0 },
1736 { UCAL_SATURDAY
, UCAL_WEEKDAY
, 0 },
1737 { UCAL_SUNDAY
, UCAL_WEEKEND
, 0 },
1739 static const TestDaysOfWeekList testDays
[] = {
1740 { "en_US", daysOfWeek_en_US
, UPRV_LENGTHOF(daysOfWeek_en_US
) },
1741 { "ar_OM", daysOfWeek_ar_OM
, UPRV_LENGTHOF(daysOfWeek_ar_OM
) },
1742 { "hi_IN", daysOfWeek_hi_IN
, UPRV_LENGTHOF(daysOfWeek_hi_IN
) },
1743 { "en_US@rg=OMZZZZ", daysOfWeek_ar_OM
, UPRV_LENGTHOF(daysOfWeek_ar_OM
) },
1744 { "hi@rg=USZZZZ", daysOfWeek_en_US
, UPRV_LENGTHOF(daysOfWeek_en_US
) },
1747 static const UChar logDateFormat
[] = { 0x0045,0x0045,0x0045,0x0020,0x004D,0x004D,0x004D,0x0020,0x0064,0x0064,0x0020,0x0079,
1748 0x0079,0x0079,0x0079,0x0020,0x0047,0x0020,0x0048,0x0048,0x003A,0x006D,0x006D,0x003A,
1749 0x0073,0x0073,0x002E,0x0053,0x0053,0x0053,0 }; /* "EEE MMM dd yyyy G HH:mm:ss.SSS" */
1750 enum { kFormattedDateMax
= 2*UPRV_LENGTHOF(logDateFormat
) };
1752 static void TestWeekend() {
1753 const TestWeekendDatesList
* testDatesPtr
= testDates
;
1754 const TestDaysOfWeekList
* testDaysPtr
= testDays
;
1755 int32_t count
, subCount
;
1757 UErrorCode fmtStatus
= U_ZERO_ERROR
;
1758 UDateFormat
* fmt
= udat_open(UDAT_NONE
, UDAT_NONE
, "en", NULL
, 0, NULL
, 0, &fmtStatus
);
1759 if (U_SUCCESS(fmtStatus
)) {
1760 udat_applyPattern(fmt
, FALSE
, logDateFormat
, -1);
1762 log_data_err("Unable to create UDateFormat - %s\n", u_errorName(fmtStatus
));
1765 for (count
= UPRV_LENGTHOF(testDates
); count
-- > 0; ++testDatesPtr
) {
1766 UErrorCode status
= U_ZERO_ERROR
;
1767 UCalendar
* cal
= ucal_open(NULL
, 0, testDatesPtr
->locale
, UCAL_GREGORIAN
, &status
);
1768 log_verbose("locale: %s\n", testDatesPtr
->locale
);
1769 if (U_SUCCESS(status
)) {
1770 const TestWeekendDates
* weekendDatesPtr
= testDatesPtr
->dates
;
1771 for (subCount
= testDatesPtr
->numDates
; subCount
--; ++weekendDatesPtr
) {
1774 char fmtDateBytes
[kFormattedDateMax
] = "<could not format test date>"; /* initialize for failure */
1777 ucal_setDateTime(cal
, weekendDatesPtr
->year
, weekendDatesPtr
->month
, weekendDatesPtr
->day
,
1778 weekendDatesPtr
->hour
, 0, 0, &status
);
1779 dateToTest
= ucal_getMillis(cal
, &status
) + weekendDatesPtr
->millisecOffset
;
1780 isWeekend
= ucal_isWeekend(cal
, dateToTest
, &status
);
1781 if (U_SUCCESS(fmtStatus
)) {
1782 UChar fmtDate
[kFormattedDateMax
];
1783 (void)udat_format(fmt
, dateToTest
, fmtDate
, kFormattedDateMax
, NULL
, &fmtStatus
);
1784 if (U_SUCCESS(fmtStatus
)) {
1785 u_austrncpy(fmtDateBytes
, fmtDate
, kFormattedDateMax
);
1786 fmtDateBytes
[kFormattedDateMax
-1] = 0;
1788 fmtStatus
= U_ZERO_ERROR
;
1791 if ( U_FAILURE(status
) ) {
1792 log_err("FAIL: locale %s date %s isWeekend() status %s\n", testDatesPtr
->locale
, fmtDateBytes
, u_errorName(status
) );
1793 status
= U_ZERO_ERROR
;
1794 } else if ( (isWeekend
!=0) != (weekendDatesPtr
->isWeekend
!=0) ) {
1795 log_err("FAIL: locale %s date %s isWeekend %d, expected the opposite\n", testDatesPtr
->locale
, fmtDateBytes
, isWeekend
);
1797 log_verbose("OK: locale %s date %s isWeekend %d\n", testDatesPtr
->locale
, fmtDateBytes
, isWeekend
);
1802 log_data_err("FAIL: ucal_open for locale %s failed: %s - (Are you missing data?)\n", testDatesPtr
->locale
, u_errorName(status
) );
1805 if (U_SUCCESS(fmtStatus
)) {
1809 for (count
= UPRV_LENGTHOF(testDays
); count
-- > 0; ++testDaysPtr
) {
1810 UErrorCode status
= U_ZERO_ERROR
;
1811 UCalendar
* cal
= ucal_open(NULL
, 0, testDaysPtr
->locale
, UCAL_GREGORIAN
, &status
);
1812 log_verbose("locale: %s\n", testDaysPtr
->locale
);
1813 if (U_SUCCESS(status
)) {
1814 const TestDaysOfWeek
* daysOfWeekPtr
= testDaysPtr
->days
;
1815 for (subCount
= testDaysPtr
->numDays
; subCount
--; ++daysOfWeekPtr
) {
1816 int32_t transition
= 0;
1817 UCalendarWeekdayType dayType
= ucal_getDayOfWeekType(cal
, daysOfWeekPtr
->dayOfWeek
, &status
);
1818 if ( dayType
== UCAL_WEEKEND_ONSET
|| dayType
== UCAL_WEEKEND_CEASE
) {
1819 transition
= ucal_getWeekendTransition(cal
, daysOfWeekPtr
->dayOfWeek
, &status
);
1821 if ( U_FAILURE(status
) ) {
1822 log_err("FAIL: locale %s DOW %d getDayOfWeekType() status %s\n", testDaysPtr
->locale
, daysOfWeekPtr
->dayOfWeek
, u_errorName(status
) );
1823 status
= U_ZERO_ERROR
;
1824 } else if ( dayType
!= daysOfWeekPtr
->dayType
|| transition
!= daysOfWeekPtr
->transition
) {
1825 log_err("FAIL: locale %s DOW %d type %d, expected %d\n", testDaysPtr
->locale
, daysOfWeekPtr
->dayOfWeek
, dayType
, daysOfWeekPtr
->dayType
);
1827 log_verbose("OK: locale %s DOW %d type %d\n", testDaysPtr
->locale
, daysOfWeekPtr
->dayOfWeek
, dayType
);
1832 log_data_err("FAIL: ucal_open for locale %s failed: %s - (Are you missing data?)\n", testDaysPtr
->locale
, u_errorName(status
) );
1838 * TestFieldDifference
1842 const UChar
* timezone
;
1843 const char * locale
;
1846 UBool progressive
; /* TRUE to compute progressive difference for each field, FALSE to reset calendar after each call */
1852 int32_t sDiff
; /* 0x7FFFFFFF indicates overflow error expected */
1855 static const UChar tzUSPacific
[] = { 0x55,0x53,0x2F,0x50,0x61,0x63,0x69,0x66,0x69,0x63,0 }; /* "US/Pacific" */
1856 static const UChar tzGMT
[] = { 0x47,0x4D,0x54,0 }; /* "GMT" */
1858 static const TFDItem tfdItems
[] = {
1859 /* timezone locale start target progres yDf MDf dDf HDf mDf sDf */
1860 /* For these we compute the progressive difference for each field - not resetting the calendar after each call */
1861 { tzUSPacific
, "en_US", 1267459800000.0, 1277772600000.0, TRUE
, 0, 3, 27, 9, 40, 0 }, /* 2010-Mar-01 08:10 -> 2010-Jun-28 17:50 */
1862 { tzUSPacific
, "en_US", 1267459800000.0, 1299089280000.0, TRUE
, 1, 0, 1, 1, 58, 0 }, /* 2010-Mar-01 08:10 -> 2011-Mar-02 10:08 */
1863 /* For these we compute the total difference for each field - resetting the calendar after each call */
1864 { tzGMT
, "en_US", 0.0, 1073692800000.0, FALSE
, 34, 408, 12427, 298248, 17894880, 1073692800 }, /* 1970-Jan-01 00:00 -> 2004-Jan-10 00:00 */
1865 { tzGMT
, "en_US", 0.0, 1073779200000.0, FALSE
, 34, 408, 12428, 298272, 17896320, 1073779200 }, /* 1970-Jan-01 00:00 -> 2004-Jan-11 00:00 */
1866 { tzGMT
, "en_US", 0.0, 2147472000000.0, FALSE
, 68, 816, 24855, 596520, 35791200, 2147472000 }, /* 1970-Jan-01 00:00 -> 2038-Jan-19 00:00 */
1867 { tzGMT
, "en_US", 0.0, 2147558400000.0, FALSE
, 68, 816, 24856, 596544, 35792640, 0x7FFFFFFF }, /* 1970-Jan-01 00:00 -> 2038-Jan-20 00:00, seconds diff overflow */
1868 { tzGMT
, "en_US", 0.0, -1073692800000.0, FALSE
, -34,-408,-12427,-298248,-17894880,-1073692800 }, /* 1970-Jan-01 00:00 -> 1935-Dec-24 00:00 */
1869 { tzGMT
, "en_US", 0.0, -1073779200000.0, FALSE
, -34,-408,-12428,-298272,-17896320,-1073779200 }, /* 1970-Jan-01 00:00 -> 1935-Dec-23 00:00 */
1870 /* check fwd/backward on either side of era boundary and across era boundary */
1871 { tzGMT
, "en_US", -61978089600000.0,-61820409600000.0, FALSE
, 4, 59, 1825, 43800, 2628000, 157680000 }, /* CE 5-Dec-31 00:00 -> CE 10-Dec-30 00:00 */
1872 { tzGMT
, "en_US", -61820409600000.0,-61978089600000.0, FALSE
, -4, -59, -1825, -43800, -2628000, -157680000 }, /* CE 10-Dec-30 00:00 -> CE 5-Dec-31 00:00 */
1873 { tzGMT
, "en_US", -62451129600000.0,-62293449600000.0, FALSE
, 4, 59, 1825, 43800, 2628000, 157680000 }, /* BCE 10-Jan-04 00:00 -> BCE 5-Jan-03 00:00 */
1874 { tzGMT
, "en_US", -62293449600000.0,-62451129600000.0, FALSE
, -4, -59, -1825, -43800, -2628000, -157680000 }, /* BCE 5-Jan-03 00:00 -> BCE 10-Jan-04 00:00 */
1875 { tzGMT
, "en_US", -62293449600000.0,-61978089600000.0, FALSE
, 9, 119, 3650, 87600, 5256000, 315360000 }, /* BCE 5-Jan-03 00:00 -> CE 5-Dec-31 00:00 */
1876 { tzGMT
, "en_US", -61978089600000.0,-62293449600000.0, FALSE
, -9,-119, -3650, -87600, -5256000, -315360000 }, /* CE 5-Dec-31 00:00 -> BCE 5-Jan-03 00:00 */
1877 { tzGMT
, "en@calendar=roc", -1672704000000.0, -1515024000000.0, FALSE
, 4, 59, 1825, 43800, 2628000, 157680000 }, /* MG 5-Dec-30 00:00 -> MG 10-Dec-29 00:00 */
1878 { tzGMT
, "en@calendar=roc", -1515024000000.0, -1672704000000.0, FALSE
, -4, -59, -1825, -43800, -2628000, -157680000 }, /* MG 10-Dec-29 00:00 -> MG 5-Dec-30 00:00 */
1879 { tzGMT
, "en@calendar=roc", -2145744000000.0, -1988064000000.0, FALSE
, 4, 59, 1825, 43800, 2628000, 157680000 }, /* BMG 10-Jan-03 00:00 -> BMG 5-Jan-02 00:00 */
1880 { tzGMT
, "en@calendar=roc", -1988064000000.0, -2145744000000.0, FALSE
, -4, -59, -1825, -43800, -2628000, -157680000 }, /* BMG 5-Jan-02 00:00 -> BMG 10-Jan-03 00:00 */
1881 { tzGMT
, "en@calendar=roc", -1988064000000.0, -1672704000000.0, FALSE
, 9, 119, 3650, 87600, 5256000, 315360000 }, /* BMG 5-Jan-02 00:00 -> MG 5-Dec-30 00:00 */
1882 { tzGMT
, "en@calendar=roc", -1672704000000.0, -1988064000000.0, FALSE
, -9,-119, -3650, -87600, -5256000, -315360000 }, /* MG 5-Dec-30 00:00 -> BMG 5-Jan-02 00:00 */
1883 { tzGMT
, "en@calendar=coptic",-53026531200000.0,-52868851200000.0, FALSE
, 4, 64, 1825, 43800, 2628000, 157680000 }, /* Er1 5-Nas-05 00:00 -> Er1 10-Nas-04 00:00 */
1884 { tzGMT
, "en@calendar=coptic",-52868851200000.0,-53026531200000.0, FALSE
, -4, -64, -1825, -43800, -2628000, -157680000 }, /* Er1 10-Nas-04 00:00 -> Er1 5-Nas-05 00:00 */
1885 { tzGMT
, "en@calendar=coptic",-53499571200000.0,-53341891200000.0, FALSE
, 4, 64, 1825, 43800, 2628000, 157680000 }, /* Er0 10-Tou-04 00:00 -> Er0 5-Tou-02 00:00 */
1886 { tzGMT
, "en@calendar=coptic",-53341891200000.0,-53499571200000.0, FALSE
, -4, -64, -1825, -43800, -2628000, -157680000 }, /* Er0 5-Tou-02 00:00 -> Er0 10-Tou-04 00:00 */
1887 { tzGMT
, "en@calendar=coptic",-53341891200000.0,-53026531200000.0, FALSE
, 9, 129, 3650, 87600, 5256000, 315360000 }, /* Er0 5-Tou-02 00:00 -> Er1 5-Nas-05 00:00 */
1888 { tzGMT
, "en@calendar=coptic",-53026531200000.0,-53341891200000.0, FALSE
, -9,-129, -3650, -87600, -5256000, -315360000 }, /* Er1 5-Nas-05 00:00 -> Er0 5-Tou-02 00:00 */
1889 { NULL
, NULL
, 0.0, 0.0, FALSE
, 0, 0, 0, 0, 0, 0 } /* terminator */
1892 void TestFieldDifference() {
1893 const TFDItem
* tfdItemPtr
;
1894 for (tfdItemPtr
= tfdItems
; tfdItemPtr
->timezone
!= NULL
; tfdItemPtr
++) {
1895 UErrorCode status
= U_ZERO_ERROR
;
1896 UCalendar
* ucal
= ucal_open(tfdItemPtr
->timezone
, -1, tfdItemPtr
->locale
, UCAL_DEFAULT
, &status
);
1897 if (U_FAILURE(status
)) {
1898 log_err("FAIL: for locale \"%s\", ucal_open had status %s\n", tfdItemPtr
->locale
, u_errorName(status
) );
1900 int32_t yDf
, MDf
, dDf
, HDf
, mDf
, sDf
;
1901 if (tfdItemPtr
->progressive
) {
1902 ucal_setMillis(ucal
, tfdItemPtr
->start
, &status
);
1903 yDf
= ucal_getFieldDifference(ucal
, tfdItemPtr
->target
, UCAL_YEAR
, &status
);
1904 MDf
= ucal_getFieldDifference(ucal
, tfdItemPtr
->target
, UCAL_MONTH
, &status
);
1905 dDf
= ucal_getFieldDifference(ucal
, tfdItemPtr
->target
, UCAL_DATE
, &status
);
1906 HDf
= ucal_getFieldDifference(ucal
, tfdItemPtr
->target
, UCAL_HOUR
, &status
);
1907 mDf
= ucal_getFieldDifference(ucal
, tfdItemPtr
->target
, UCAL_MINUTE
, &status
);
1908 sDf
= ucal_getFieldDifference(ucal
, tfdItemPtr
->target
, UCAL_SECOND
, &status
);
1909 if (U_FAILURE(status
)) {
1910 log_err("FAIL: for locale \"%s\", start %.1f, target %.1f, ucal_setMillis or ucal_getFieldDifference had status %s\n",
1911 tfdItemPtr
->locale
, tfdItemPtr
->start
, tfdItemPtr
->target
, u_errorName(status
) );
1912 } else if ( yDf
!= tfdItemPtr
->yDiff
||
1913 MDf
!= tfdItemPtr
->MDiff
||
1914 dDf
!= tfdItemPtr
->dDiff
||
1915 HDf
!= tfdItemPtr
->HDiff
||
1916 mDf
!= tfdItemPtr
->mDiff
||
1917 sDf
!= tfdItemPtr
->sDiff
) {
1918 log_data_err("FAIL: for locale \"%s\", start %.1f, target %.1f, expected y-M-d-H-m-s progressive diffs %d-%d-%d-%d-%d-%d, got %d-%d-%d-%d-%d-%d\n",
1919 tfdItemPtr
->locale
, tfdItemPtr
->start
, tfdItemPtr
->target
,
1920 tfdItemPtr
->yDiff
, tfdItemPtr
->MDiff
, tfdItemPtr
->dDiff
, tfdItemPtr
->HDiff
, tfdItemPtr
->mDiff
, tfdItemPtr
->sDiff
,
1921 yDf
, MDf
, dDf
, HDf
, mDf
, sDf
);
1924 ucal_setMillis(ucal
, tfdItemPtr
->start
, &status
);
1925 yDf
= ucal_getFieldDifference(ucal
, tfdItemPtr
->target
, UCAL_YEAR
, &status
);
1926 ucal_setMillis(ucal
, tfdItemPtr
->start
, &status
);
1927 MDf
= ucal_getFieldDifference(ucal
, tfdItemPtr
->target
, UCAL_MONTH
, &status
);
1928 ucal_setMillis(ucal
, tfdItemPtr
->start
, &status
);
1929 dDf
= ucal_getFieldDifference(ucal
, tfdItemPtr
->target
, UCAL_DATE
, &status
);
1930 ucal_setMillis(ucal
, tfdItemPtr
->start
, &status
);
1931 HDf
= ucal_getFieldDifference(ucal
, tfdItemPtr
->target
, UCAL_HOUR
, &status
);
1932 ucal_setMillis(ucal
, tfdItemPtr
->start
, &status
);
1933 mDf
= ucal_getFieldDifference(ucal
, tfdItemPtr
->target
, UCAL_MINUTE
, &status
);
1934 if (U_FAILURE(status
)) {
1935 log_err("FAIL: for locale \"%s\", start %.1f, target %.1f, ucal_setMillis or ucal_getFieldDifference (y-M-d-H-m) had status %s\n",
1936 tfdItemPtr
->locale
, tfdItemPtr
->start
, tfdItemPtr
->target
, u_errorName(status
) );
1937 } else if ( yDf
!= tfdItemPtr
->yDiff
||
1938 MDf
!= tfdItemPtr
->MDiff
||
1939 dDf
!= tfdItemPtr
->dDiff
||
1940 HDf
!= tfdItemPtr
->HDiff
||
1941 mDf
!= tfdItemPtr
->mDiff
) {
1942 log_data_err("FAIL: for locale \"%s\", start %.1f, target %.1f, expected y-M-d-H-m total diffs %d-%d-%d-%d-%d, got %d-%d-%d-%d-%d\n",
1943 tfdItemPtr
->locale
, tfdItemPtr
->start
, tfdItemPtr
->target
,
1944 tfdItemPtr
->yDiff
, tfdItemPtr
->MDiff
, tfdItemPtr
->dDiff
, tfdItemPtr
->HDiff
, tfdItemPtr
->mDiff
,
1945 yDf
, MDf
, dDf
, HDf
, mDf
);
1947 ucal_setMillis(ucal
, tfdItemPtr
->start
, &status
);
1948 sDf
= ucal_getFieldDifference(ucal
, tfdItemPtr
->target
, UCAL_SECOND
, &status
);
1949 if (tfdItemPtr
->sDiff
!= 0x7FFFFFFF) {
1950 if (U_FAILURE(status
)) {
1951 log_err("FAIL: for locale \"%s\", start %.1f, target %.1f, ucal_setMillis or ucal_getFieldDifference (seconds) had status %s\n",
1952 tfdItemPtr
->locale
, tfdItemPtr
->start
, tfdItemPtr
->target
, u_errorName(status
) );
1953 } else if (sDf
!= tfdItemPtr
->sDiff
) {
1954 log_data_err("FAIL: for locale \"%s\", start %.1f, target %.1f, expected seconds progressive diff %d, got %d\n",
1955 tfdItemPtr
->locale
, tfdItemPtr
->start
, tfdItemPtr
->target
, tfdItemPtr
->sDiff
, sDf
);
1957 } else if (!U_FAILURE(status
)) {
1958 log_err("FAIL: for locale \"%s\", start %.1f, target %.1f, for ucal_getFieldDifference (seconds) expected overflow error, got none\n",
1959 tfdItemPtr
->locale
, tfdItemPtr
->start
, tfdItemPtr
->target
);
1967 void TestAmbiguousWallTime() {
1968 UErrorCode status
= U_ZERO_ERROR
;
1973 u_uastrcpy(tzID
, "America/New_York");
1974 ucal
= ucal_open(tzID
, -1, NULL
, UCAL_DEFAULT
, &status
);
1975 if (U_FAILURE(status
)) {
1976 log_err("FAIL: Failed to create a calendar");
1980 if (ucal_getAttribute(ucal
, UCAL_REPEATED_WALL_TIME
) != UCAL_WALLTIME_LAST
) {
1981 log_err("FAIL: Default UCAL_REPEATED_WALL_TIME value is not UCAL_WALLTIME_LAST");
1984 if (ucal_getAttribute(ucal
, UCAL_SKIPPED_WALL_TIME
) != UCAL_WALLTIME_LAST
) {
1985 log_err("FAIL: Default UCAL_SKIPPED_WALL_TIME value is not UCAL_WALLTIME_LAST");
1988 /* UCAL_WALLTIME_FIRST on US fall transition */
1989 ucal_setAttribute(ucal
, UCAL_REPEATED_WALL_TIME
, UCAL_WALLTIME_FIRST
);
1991 ucal_setDateTime(ucal
, 2011, 11-1, 6, 1, 30, 0, &status
);
1992 t
= ucal_getMillis(ucal
, &status
);
1993 expected
= 1320557400000.0; /* 2011-11-06T05:30:00Z */
1994 if (U_FAILURE(status
)) {
1995 log_err("FAIL: Calculating time 2011-11-06 01:30:00 with UCAL_WALLTIME_FIRST - %s\n", u_errorName(status
));
1996 status
= U_ZERO_ERROR
;
1997 } else if (t
!= expected
) {
1998 log_data_err("FAIL: 2011-11-06 01:30:00 with UCAL_WALLTIME_FIRST - got: %f, expected: %f\n", t
, expected
);
2001 /* UCAL_WALLTIME_LAST on US fall transition */
2002 ucal_setAttribute(ucal
, UCAL_REPEATED_WALL_TIME
, UCAL_WALLTIME_LAST
);
2004 ucal_setDateTime(ucal
, 2011, 11-1, 6, 1, 30, 0, &status
);
2005 t
= ucal_getMillis(ucal
, &status
);
2006 expected
= 1320561000000.0; /* 2011-11-06T06:30:00Z */
2007 if (U_FAILURE(status
)) {
2008 log_err("FAIL: Calculating time 2011-11-06 01:30:00 with UCAL_WALLTIME_LAST - %s\n", u_errorName(status
));
2009 status
= U_ZERO_ERROR
;
2010 } else if (t
!= expected
) {
2011 log_data_err("FAIL: 2011-11-06 01:30:00 with UCAL_WALLTIME_LAST - got: %f, expected: %f\n", t
, expected
);
2014 /* UCAL_WALLTIME_FIRST on US spring transition */
2015 ucal_setAttribute(ucal
, UCAL_SKIPPED_WALL_TIME
, UCAL_WALLTIME_FIRST
);
2017 ucal_setDateTime(ucal
, 2011, 3-1, 13, 2, 30, 0, &status
);
2018 t
= ucal_getMillis(ucal
, &status
);
2019 expected
= 1299997800000.0; /* 2011-03-13T06:30:00Z */
2020 if (U_FAILURE(status
)) {
2021 log_err("FAIL: Calculating time 2011-03-13 02:30:00 with UCAL_WALLTIME_FIRST - %s\n", u_errorName(status
));
2022 status
= U_ZERO_ERROR
;
2023 } else if (t
!= expected
) {
2024 log_data_err("FAIL: 2011-03-13 02:30:00 with UCAL_WALLTIME_FIRST - got: %f, expected: %f\n", t
, expected
);
2027 /* UCAL_WALLTIME_LAST on US spring transition */
2028 ucal_setAttribute(ucal
, UCAL_SKIPPED_WALL_TIME
, UCAL_WALLTIME_LAST
);
2030 ucal_setDateTime(ucal
, 2011, 3-1, 13, 2, 30, 0, &status
);
2031 t
= ucal_getMillis(ucal
, &status
);
2032 expected
= 1300001400000.0; /* 2011-03-13T07:30:00Z */
2033 if (U_FAILURE(status
)) {
2034 log_err("FAIL: Calculating time 2011-03-13 02:30:00 with UCAL_WALLTIME_LAST - %s\n", u_errorName(status
));
2035 status
= U_ZERO_ERROR
;
2036 } else if (t
!= expected
) {
2037 log_data_err("FAIL: 2011-03-13 02:30:00 with UCAL_WALLTIME_LAST - got: %f, expected: %f\n", t
, expected
);
2040 /* UCAL_WALLTIME_NEXT_VALID on US spring transition */
2041 ucal_setAttribute(ucal
, UCAL_SKIPPED_WALL_TIME
, UCAL_WALLTIME_NEXT_VALID
);
2043 ucal_setDateTime(ucal
, 2011, 3-1, 13, 2, 30, 0, &status
);
2044 t
= ucal_getMillis(ucal
, &status
);
2045 expected
= 1299999600000.0; /* 2011-03-13T07:00:00Z */
2046 if (U_FAILURE(status
)) {
2047 log_err("FAIL: Calculating time 2011-03-13 02:30:00 with UCAL_WALLTIME_NEXT_VALID - %s\n", u_errorName(status
));
2048 status
= U_ZERO_ERROR
;
2049 } else if (t
!= expected
) {
2050 log_data_err("FAIL: 2011-03-13 02:30:00 with UCAL_WALLTIME_NEXT_VALID - got: %f, expected: %f\n", t
, expected
);
2053 /* non-lenient on US spring transition */
2054 ucal_setAttribute(ucal
, UCAL_LENIENT
, 0);
2056 ucal_setDateTime(ucal
, 2011, 3-1, 13, 2, 30, 0, &status
);
2057 t
= ucal_getMillis(ucal
, &status
);
2058 if (U_SUCCESS(status
)) {
2059 /* must return error */
2060 log_data_err("FAIL: Non-lenient did not fail with 2011-03-13 02:30:00\n");
2061 status
= U_ZERO_ERROR
;
2068 * TestAddRollEra0AndEraBounds, for #9226
2072 const char * locale
;
2073 UBool era0YearsGoBackwards
; /* until we have API to get this, per #9393 */
2076 static const EraTestItem eraTestItems
[] = {
2077 /* calendars with non-modern era 0 that goes backwards, max era == 1 */
2078 { "en@calendar=gregorian", TRUE
},
2079 { "en@calendar=roc", TRUE
},
2080 { "en@calendar=coptic", TRUE
},
2081 /* calendars with non-modern era 0 that goes forwards, max era > 1 */
2082 { "en@calendar=japanese", FALSE
},
2083 { "en@calendar=chinese", FALSE
},
2084 /* calendars with non-modern era 0 that goes forwards, max era == 1 */
2085 { "en@calendar=ethiopic", FALSE
},
2086 /* calendars with only one era = 0, forwards */
2087 { "en@calendar=buddhist", FALSE
},
2088 { "en@calendar=hebrew", FALSE
},
2089 { "en@calendar=islamic", FALSE
},
2090 { "en@calendar=indian", FALSE
},
2091 { "en@calendar=persian", FALSE
},
2092 { "en@calendar=ethiopic-amete-alem", FALSE
},
2096 static const UChar zoneGMT
[] = { 0x47,0x4D,0x54,0 };
2098 void TestAddRollEra0AndEraBounds() {
2099 const EraTestItem
* eraTestItemPtr
;
2100 for (eraTestItemPtr
= eraTestItems
; eraTestItemPtr
->locale
!= NULL
; eraTestItemPtr
++) {
2101 UErrorCode status
= U_ZERO_ERROR
;
2102 UCalendar
*ucalTest
= ucal_open(zoneGMT
, -1, eraTestItemPtr
->locale
, UCAL_DEFAULT
, &status
);
2103 if ( U_SUCCESS(status
) ) {
2104 int32_t yrBefore
, yrAfter
, yrMax
, eraAfter
, eraMax
, eraNow
;
2106 status
= U_ZERO_ERROR
;
2107 ucal_clear(ucalTest
);
2108 ucal_set(ucalTest
, UCAL_YEAR
, 2);
2109 ucal_set(ucalTest
, UCAL_ERA
, 0);
2110 yrBefore
= ucal_get(ucalTest
, UCAL_YEAR
, &status
);
2111 ucal_add(ucalTest
, UCAL_YEAR
, 1, &status
);
2112 yrAfter
= ucal_get(ucalTest
, UCAL_YEAR
, &status
);
2113 if (U_FAILURE(status
)) {
2114 log_err("FAIL: set era 0 year 2 then add 1 year and get year for %s, error %s\n",
2115 eraTestItemPtr
->locale
, u_errorName(status
));
2116 } else if ( (eraTestItemPtr
->era0YearsGoBackwards
&& yrAfter
>yrBefore
) ||
2117 (!eraTestItemPtr
->era0YearsGoBackwards
&& yrAfter
<yrBefore
) ) {
2118 log_err("FAIL: era 0 add 1 year does not move forward in time for %s\n", eraTestItemPtr
->locale
);
2121 status
= U_ZERO_ERROR
;
2122 ucal_clear(ucalTest
);
2123 ucal_set(ucalTest
, UCAL_YEAR
, 2);
2124 ucal_set(ucalTest
, UCAL_ERA
, 0);
2125 yrBefore
= ucal_get(ucalTest
, UCAL_YEAR
, &status
);
2126 ucal_roll(ucalTest
, UCAL_YEAR
, 1, &status
);
2127 yrAfter
= ucal_get(ucalTest
, UCAL_YEAR
, &status
);
2128 if (U_FAILURE(status
)) {
2129 log_err("FAIL: set era 0 year 2 then roll 1 year and get year for %s, error %s\n",
2130 eraTestItemPtr
->locale
, u_errorName(status
));
2131 } else if ( (eraTestItemPtr
->era0YearsGoBackwards
&& yrAfter
>yrBefore
) ||
2132 (!eraTestItemPtr
->era0YearsGoBackwards
&& yrAfter
<yrBefore
) ) {
2133 log_err("FAIL: era 0 roll 1 year does not move forward in time for %s\n", eraTestItemPtr
->locale
);
2136 status
= U_ZERO_ERROR
;
2137 ucal_clear(ucalTest
);
2138 ucal_set(ucalTest
, UCAL_YEAR
, 1);
2139 ucal_set(ucalTest
, UCAL_ERA
, 0);
2140 if (eraTestItemPtr
->era0YearsGoBackwards
) {
2141 ucal_roll(ucalTest
, UCAL_YEAR
, 1, &status
); /* roll forward in time to era 0 boundary */
2142 yrAfter
= ucal_get(ucalTest
, UCAL_YEAR
, &status
);
2143 eraAfter
= ucal_get(ucalTest
, UCAL_ERA
, &status
);
2144 if (U_FAILURE(status
)) {
2145 log_err("FAIL: set era 0 year 1 then roll 1 year and get year,era for %s, error %s\n",
2146 eraTestItemPtr
->locale
, u_errorName(status
));
2147 /* all calendars with era0YearsGoBackwards have "unbounded" era0 year values, so we should pin at yr 1 */
2148 } else if (eraAfter
!= 0 || yrAfter
!= 1) {
2149 log_err("FAIL: era 0 roll 1 year from year 1 does not stay within era or pin to year 1 for %s (get era %d year %d)\n",
2150 eraTestItemPtr
->locale
, eraAfter
, yrAfter
);
2153 /* roll backward in time to where era 0 years go negative, except for the Chinese
2154 calendar, which uses negative eras instead of having years outside the range 1-60 */
2155 const char * calType
= ucal_getType(ucalTest
, &status
);
2156 ucal_roll(ucalTest
, UCAL_YEAR
, -2, &status
);
2157 yrAfter
= ucal_get(ucalTest
, UCAL_YEAR
, &status
);
2158 eraAfter
= ucal_get(ucalTest
, UCAL_ERA
, &status
);
2159 if (U_FAILURE(status
)) {
2160 log_err("FAIL: set era 0 year 1 then roll -2 years and get year,era for %s, error %s\n",
2161 eraTestItemPtr
->locale
, u_errorName(status
));
2162 } else if ( uprv_strcmp(calType
,"chinese")!=0 && (eraAfter
!= 0 || yrAfter
!= -1) ) {
2163 log_err("FAIL: era 0 roll -2 years from year 1 does not stay within era or produce year -1 for %s (get era %d year %d)\n",
2164 eraTestItemPtr
->locale
, eraAfter
, yrAfter
);
2168 status
= U_ZERO_ERROR
;
2169 ucal_clear(ucalTest
);
2171 int32_t eraMin
= ucal_getLimit(ucalTest
, UCAL_ERA
, UCAL_MINIMUM
, &status
);
2172 const char * calType
= ucal_getType(ucalTest
, &status
);
2173 if (eraMin
!= 0 && uprv_strcmp(calType
, "chinese") != 0) {
2174 log_err("FAIL: ucal_getLimit returns minimum era %d (should be 0) for calType %s, error %s\n", eraMin
, calType
, u_errorName(status
));
2178 status
= U_ZERO_ERROR
;
2179 ucal_clear(ucalTest
);
2180 ucal_set(ucalTest
, UCAL_YEAR
, 1);
2181 ucal_set(ucalTest
, UCAL_ERA
, 0);
2182 eraMax
= ucal_getLimit(ucalTest
, UCAL_ERA
, UCAL_MAXIMUM
, &status
);
2183 if ( U_SUCCESS(status
) && eraMax
> 0 ) {
2184 /* try similar tests for era 1 (if calendar has it), in which years always go forward */
2185 status
= U_ZERO_ERROR
;
2186 ucal_clear(ucalTest
);
2187 ucal_set(ucalTest
, UCAL_YEAR
, 2);
2188 ucal_set(ucalTest
, UCAL_ERA
, 1);
2189 yrBefore
= ucal_get(ucalTest
, UCAL_YEAR
, &status
);
2190 ucal_add(ucalTest
, UCAL_YEAR
, 1, &status
);
2191 yrAfter
= ucal_get(ucalTest
, UCAL_YEAR
, &status
);
2192 if (U_FAILURE(status
)) {
2193 log_err("FAIL: set era 1 year 2 then add 1 year and get year for %s, error %s\n",
2194 eraTestItemPtr
->locale
, u_errorName(status
));
2195 } else if ( yrAfter
<yrBefore
) {
2196 log_err("FAIL: era 1 add 1 year does not move forward in time for %s\n", eraTestItemPtr
->locale
);
2199 status
= U_ZERO_ERROR
;
2200 ucal_clear(ucalTest
);
2201 ucal_set(ucalTest
, UCAL_YEAR
, 2);
2202 ucal_set(ucalTest
, UCAL_ERA
, 1);
2203 yrBefore
= ucal_get(ucalTest
, UCAL_YEAR
, &status
);
2204 ucal_roll(ucalTest
, UCAL_YEAR
, 1, &status
);
2205 yrAfter
= ucal_get(ucalTest
, UCAL_YEAR
, &status
);
2206 if (U_FAILURE(status
)) {
2207 log_err("FAIL: set era 1 year 2 then roll 1 year and get year for %s, error %s\n",
2208 eraTestItemPtr
->locale
, u_errorName(status
));
2209 } else if ( yrAfter
<yrBefore
) {
2210 log_err("FAIL: era 1 roll 1 year does not move forward in time for %s\n", eraTestItemPtr
->locale
);
2213 status
= U_ZERO_ERROR
;
2214 ucal_clear(ucalTest
);
2215 ucal_set(ucalTest
, UCAL_YEAR
, 1);
2216 ucal_set(ucalTest
, UCAL_ERA
, 1);
2217 yrMax
= ucal_getLimit(ucalTest
, UCAL_YEAR
, UCAL_ACTUAL_MAXIMUM
, &status
); /* max year value for era 1 */
2218 ucal_roll(ucalTest
, UCAL_YEAR
, -1, &status
); /* roll down which should pin or wrap to end */
2219 yrAfter
= ucal_get(ucalTest
, UCAL_YEAR
, &status
);
2220 eraAfter
= ucal_get(ucalTest
, UCAL_ERA
, &status
);
2221 if (U_FAILURE(status
)) {
2222 log_err("FAIL: set era 1 year 1 then roll -1 year and get year,era for %s, error %s\n",
2223 eraTestItemPtr
->locale
, u_errorName(status
));
2224 /* if yrMax is reasonable we should wrap to that, else we should pin at yr 1 */
2225 } else if (yrMax
>= 32768) {
2226 if (eraAfter
!= 1 || yrAfter
!= 1) {
2227 log_err("FAIL: era 1 roll -1 year from year 1 does not stay within era or pin to year 1 for %s (get era %d year %d)\n",
2228 eraTestItemPtr
->locale
, eraAfter
, yrAfter
);
2230 } else if (eraAfter
!= 1 || yrAfter
!= yrMax
) {
2231 log_err("FAIL: era 1 roll -1 year from year 1 does not stay within era or wrap to year %d for %s (get era %d year %d)\n",
2232 yrMax
, eraTestItemPtr
->locale
, eraAfter
, yrAfter
);
2234 /* now roll up which should wrap to beginning */
2235 ucal_roll(ucalTest
, UCAL_YEAR
, 1, &status
); /* now roll up which should wrap to beginning */
2236 yrAfter
= ucal_get(ucalTest
, UCAL_YEAR
, &status
);
2237 eraAfter
= ucal_get(ucalTest
, UCAL_ERA
, &status
);
2238 if (U_FAILURE(status
)) {
2239 log_err("FAIL: era 1 roll 1 year from end and get year,era for %s, error %s\n",
2240 eraTestItemPtr
->locale
, u_errorName(status
));
2241 } else if (eraAfter
!= 1 || yrAfter
!= 1) {
2242 log_err("FAIL: era 1 roll 1 year from year %d does not stay within era or wrap to year 1 for %s (get era %d year %d)\n",
2243 yrMax
, eraTestItemPtr
->locale
, eraAfter
, yrAfter
);
2247 /* if current era > 1, try the same roll tests for current era */
2248 ucal_setMillis(ucalTest
, ucal_getNow(), &status
);
2249 eraNow
= ucal_get(ucalTest
, UCAL_ERA
, &status
);
2250 if ( U_SUCCESS(status
) && eraNow
> 1 ) {
2251 status
= U_ZERO_ERROR
;
2252 ucal_clear(ucalTest
);
2253 ucal_set(ucalTest
, UCAL_YEAR
, 1);
2254 ucal_set(ucalTest
, UCAL_ERA
, eraNow
);
2255 yrMax
= ucal_getLimit(ucalTest
, UCAL_YEAR
, UCAL_ACTUAL_MAXIMUM
, &status
); /* max year value for this era */
2256 ucal_roll(ucalTest
, UCAL_YEAR
, -1, &status
);
2257 yrAfter
= ucal_get(ucalTest
, UCAL_YEAR
, &status
);
2258 eraAfter
= ucal_get(ucalTest
, UCAL_ERA
, &status
);
2259 if (U_FAILURE(status
)) {
2260 log_err("FAIL: set era %d year 1 then roll -1 year and get year,era for %s, error %s\n",
2261 eraNow
, eraTestItemPtr
->locale
, u_errorName(status
));
2262 /* if yrMax is reasonable we should wrap to that, else we should pin at yr 1 */
2263 } else if (yrMax
>= 32768) {
2264 if (eraAfter
!= eraNow
|| yrAfter
!= 1) {
2265 log_err("FAIL: era %d roll -1 year from year 1 does not stay within era or pin to year 1 for %s (get era %d year %d)\n",
2266 eraNow
, eraTestItemPtr
->locale
, eraAfter
, yrAfter
);
2268 } else if (eraAfter
!= eraNow
|| yrAfter
!= yrMax
) {
2269 log_err("FAIL: era %d roll -1 year from year 1 does not stay within era or wrap to year %d for %s (get era %d year %d)\n",
2270 eraNow
, yrMax
, eraTestItemPtr
->locale
, eraAfter
, yrAfter
);
2272 /* now roll up which should wrap to beginning */
2273 ucal_roll(ucalTest
, UCAL_YEAR
, 1, &status
); /* now roll up which should wrap to beginning */
2274 yrAfter
= ucal_get(ucalTest
, UCAL_YEAR
, &status
);
2275 eraAfter
= ucal_get(ucalTest
, UCAL_ERA
, &status
);
2276 if (U_FAILURE(status
)) {
2277 log_err("FAIL: era %d roll 1 year from end and get year,era for %s, error %s\n",
2278 eraNow
, eraTestItemPtr
->locale
, u_errorName(status
));
2279 } else if (eraAfter
!= eraNow
|| yrAfter
!= 1) {
2280 log_err("FAIL: era %d roll 1 year from year %d does not stay within era or wrap to year 1 for %s (get era %d year %d)\n",
2281 eraNow
, yrMax
, eraTestItemPtr
->locale
, eraAfter
, yrAfter
);
2287 ucal_close(ucalTest
);
2289 log_data_err("FAIL: ucal_open fails for zone GMT, locale %s, UCAL_DEFAULT\n", eraTestItemPtr
->locale
);
2295 * TestGetTZTransition, for #9606
2299 const char *descrip
; /* test description */
2300 const UChar
* zoneName
; /* pointer to zero-terminated zone name */
2301 int32_t year
; /* starting point for test is gregorian calendar noon on day specified by y,M,d here */
2304 UBool hasPrev
; /* does it have a previous transition from starting point? If so we test inclusive from that */
2305 UBool hasNext
; /* does it have a next transition from starting point? If so we test inclusive from that */
2308 /* have zoneGMT above */
2309 static const UChar zoneUSPacific
[] = { 0x55,0x53,0x2F,0x50,0x61,0x63,0x69,0x66,0x69,0x63,0 }; /* "US/Pacific" */
2310 static const UChar zoneCairo
[] = { 0x41,0x66,0x72,0x69,0x63,0x61,0x2F,0x43,0x61,0x69,0x72,0x6F,0 }; /* "Africa/Cairo", DST cancelled since 2011 */
2311 static const UChar zoneIceland
[] = { 0x41,0x74,0x6C,0x61,0x6E,0x74,0x69,0x63,0x2F,0x52,0x65,0x79,0x6B,0x6A,0x61,0x76,0x69,0x6B,0 }; /* "Atlantic/Reykjavik", always on DST (since when?) */
2313 static const TZTransitionItem tzTransitionItems
[] = {
2314 { "USPacific mid 2012", zoneUSPacific
, 2012, UCAL_JULY
, 1, TRUE
, TRUE
},
2315 { "USPacific mid 100", zoneUSPacific
, 100, UCAL_JULY
, 1, FALSE
, TRUE
}, /* no transitions before 100 CE... */
2316 { "Cairo mid 2012", zoneCairo
, 2012, UCAL_JULY
, 1, TRUE
, TRUE
}, /* DST cancelled since 2011 (Changed since 2014c) */
2317 { "Iceland mid 2012", zoneIceland
, 2012, UCAL_JULY
, 1, TRUE
, FALSE
}, /* always on DST */
2318 { NULL
, NULL
, 0, 0, 0, FALSE
, FALSE
} /* terminator */
2321 void TestGetTZTransition() {
2322 UErrorCode status
= U_ZERO_ERROR
;
2323 UCalendar
* ucal
= ucal_open(zoneGMT
, -1, "en", UCAL_GREGORIAN
, &status
);
2324 if ( U_SUCCESS(status
) ) {
2325 const TZTransitionItem
* itemPtr
;
2326 for (itemPtr
= tzTransitionItems
; itemPtr
->descrip
!= NULL
; itemPtr
++) {
2328 ucal_setTimeZone(ucal
, itemPtr
->zoneName
, -1, &status
);
2329 ucal_setDateTime(ucal
, itemPtr
->year
, itemPtr
->month
, itemPtr
->day
, 12, 0, 0, &status
);
2330 curMillis
= ucal_getMillis(ucal
, &status
);
2331 (void)curMillis
; /* Suppress set but not used warning. */
2332 if ( U_SUCCESS(status
) ) {
2333 UDate transition1
, transition2
;
2336 result
= ucal_getTimeZoneTransitionDate(ucal
, UCAL_TZ_TRANSITION_PREVIOUS
, &transition1
, &status
);
2337 if (U_FAILURE(status
) || result
!= itemPtr
->hasPrev
) {
2338 log_data_err("FAIL: %s ucal_getTimeZoneTransitionDate prev status %s, expected result %d but got %d\n",
2339 itemPtr
->descrip
, u_errorName(status
), itemPtr
->hasPrev
, result
);
2340 } else if (result
) {
2341 ucal_setMillis(ucal
, transition1
, &status
);
2342 result
= ucal_getTimeZoneTransitionDate(ucal
, UCAL_TZ_TRANSITION_PREVIOUS_INCLUSIVE
, &transition2
, &status
);
2343 if (U_FAILURE(status
) || !result
|| transition2
!= transition1
) {
2344 log_err("FAIL: %s ucal_getTimeZoneTransitionDate prev_inc status %s, result %d, expected date %.1f but got %.1f\n",
2345 itemPtr
->descrip
, u_errorName(status
), result
, transition1
, transition2
);
2348 status
= U_ZERO_ERROR
;
2350 result
= ucal_getTimeZoneTransitionDate(ucal
, UCAL_TZ_TRANSITION_NEXT
, &transition1
, &status
);
2351 if (U_FAILURE(status
) || result
!= itemPtr
->hasNext
) {
2352 log_data_err("FAIL: %s ucal_getTimeZoneTransitionDate next status %s, expected result %d but got %d\n",
2353 itemPtr
->descrip
, u_errorName(status
), itemPtr
->hasNext
, result
);
2354 } else if (result
) {
2355 ucal_setMillis(ucal
, transition1
, &status
);
2356 result
= ucal_getTimeZoneTransitionDate(ucal
, UCAL_TZ_TRANSITION_NEXT_INCLUSIVE
, &transition2
, &status
);
2357 if (U_FAILURE(status
) || !result
|| transition2
!= transition1
) {
2358 log_err("FAIL: %s ucal_getTimeZoneTransitionDate next_inc status %s, result %d, expected date %.1f but got %.1f\n",
2359 itemPtr
->descrip
, u_errorName(status
), result
, transition1
, transition2
);
2362 status
= U_ZERO_ERROR
;
2364 log_data_err("FAIL setup: can't setup calendar for %s, status %s\n",
2365 itemPtr
->descrip
, u_errorName(status
));
2366 status
= U_ZERO_ERROR
;
2371 log_data_err("FAIL setup: ucal_open status %s\n", u_errorName(status
));
2375 static const UChar winEastern
[] = /* Eastern Standard Time */
2376 {0x45,0x61,0x73,0x74,0x65,0x72,0x6E,0x20,0x53,0x74,0x61,0x6E,0x64,0x61,0x72,0x64,0x20,0x54,0x69,0x6D,0x65,0x00};
2378 static const UChar tzNewYork
[] = /* America/New_York */
2379 {0x41,0x6D,0x65,0x72,0x69,0x63,0x61,0x2F,0x4E,0x65,0x77,0x5F,0x59,0x6F,0x72,0x6B,0x00};
2380 static const UChar tzTronto
[] = /* America/Toronto */
2381 {0x41,0x6D,0x65,0x72,0x69,0x63,0x61,0x2F,0x54,0x6F,0x72,0x6F,0x6E,0x74,0x6F,0x00};
2383 static const UChar sBogus
[] = /* Bogus */
2384 {0x42,0x6F,0x67,0x75,0x73,0x00};
2386 void TestGetWindowsTimeZoneID() {
2392 status
= U_ZERO_ERROR
;
2393 len
= ucal_getWindowsTimeZoneID(tzNewYork
, u_strlen(tzNewYork
), winID
, UPRV_LENGTHOF(winID
), &status
);
2394 if (U_FAILURE(status
)) {
2395 log_data_err("FAIL: Windows ID for America/New_York, status %s\n", u_errorName(status
));
2396 } else if (len
!= u_strlen(winEastern
) || u_strncmp(winID
, winEastern
, len
) != 0) {
2397 log_data_err("FAIL: Windows ID for America/New_York\n");
2401 status
= U_ZERO_ERROR
;
2402 len
= ucal_getWindowsTimeZoneID(tzTronto
, u_strlen(tzTronto
), winID
, UPRV_LENGTHOF(winID
), &status
);
2403 if (U_FAILURE(status
)) {
2404 log_data_err("FAIL: Windows ID for America/Toronto, status %s\n", u_errorName(status
));
2405 } else if (len
!= u_strlen(winEastern
) || u_strncmp(winID
, winEastern
, len
) != 0) {
2406 log_data_err("FAIL: Windows ID for America/Toronto\n");
2410 status
= U_ZERO_ERROR
;
2411 len
= ucal_getWindowsTimeZoneID(sBogus
, u_strlen(sBogus
), winID
, UPRV_LENGTHOF(winID
), &status
);
2412 if (U_FAILURE(status
)) {
2413 log_data_err("FAIL: Windows ID for Bogus, status %s\n", u_errorName(status
));
2414 } else if (len
!= 0) {
2415 log_data_err("FAIL: Windows ID for Bogus\n");
2420 void TestGetTimeZoneIDByWindowsID() {
2426 status
= U_ZERO_ERROR
;
2427 len
= ucal_getTimeZoneIDForWindowsID(winEastern
, -1, NULL
, tzID
, UPRV_LENGTHOF(tzID
), &status
);
2428 if (U_FAILURE(status
)) {
2429 log_data_err("FAIL: TZ ID for Eastern Standard Time, status %s\n", u_errorName(status
));
2430 } else if (len
!= u_strlen(tzNewYork
) || u_strncmp(tzID
, tzNewYork
, len
) != 0) {
2431 log_err("FAIL: TZ ID for Eastern Standard Time\n");
2435 status
= U_ZERO_ERROR
;
2436 len
= ucal_getTimeZoneIDForWindowsID(winEastern
, u_strlen(winEastern
), "US", tzID
, UPRV_LENGTHOF(tzID
), &status
);
2437 if (U_FAILURE(status
)) {
2438 log_data_err("FAIL: TZ ID for Eastern Standard Time - US, status %s\n", u_errorName(status
));
2439 } else if (len
!= u_strlen(tzNewYork
) || u_strncmp(tzID
, tzNewYork
, len
) != 0) {
2440 log_err("FAIL: TZ ID for Eastern Standard Time - US\n");
2444 status
= U_ZERO_ERROR
;
2445 len
= ucal_getTimeZoneIDForWindowsID(winEastern
, u_strlen(winEastern
), "CA", tzID
, UPRV_LENGTHOF(tzID
), &status
);
2446 if (U_FAILURE(status
)) {
2447 log_data_err("FAIL: TZ ID for Eastern Standard Time - CA, status %s\n", u_errorName(status
));
2448 } else if (len
!= u_strlen(tzTronto
) || u_strncmp(tzID
, tzTronto
, len
) != 0) {
2449 log_err("FAIL: TZ ID for Eastern Standard Time - CA\n");
2454 status
= U_ZERO_ERROR
;
2455 len
= ucal_getTimeZoneIDForWindowsID(sBogus
, -1, NULL
, tzID
, UPRV_LENGTHOF(tzID
), &status
);
2456 if (U_FAILURE(status
)) {
2457 log_data_err("FAIL: TZ ID for Bogus, status %s\n", u_errorName(status
));
2458 } else if (len
!= 0) {
2459 log_err("FAIL: TZ ID for Bogus\n");
2465 const char * localeWithCal
;
2467 } LocaleWithCalendarAndClearDate
;
2469 static const LocaleWithCalendarAndClearDate calAndClearDates
[] = {
2470 // ucal_clear sets era grego
2471 // this date for GMT in cal date
2472 { "en@calendar=gregorian", 0.0 }, // 1 1970-01-01
2473 { "en@calendar=iso8601", 0.0 }, // 1 1970-01-01
2474 { "en@calendar=buddhist", 0.0 }, // 0 1970-01-01
2475 { "en@calendar=japanese", 0.0 }, // 234 1970-01-01
2476 { "en@calendar=roc", 0.0 }, // 1 1970-01-01
2477 { "en@calendar=chinese", 444528000000.0 }, // 78 1984-02-02
2478 { "en@calendar=dangi", 444528000000.0 }, // 78 1984-02-02
2479 { "en@calendar=coptic", -53184211200000.0 }, // 1 284-08-29
2480 { "en@calendar=ethiopic", -61894108800000.0 }, // 1 8-08-29
2481 { "en@calendar=ethiopic-amete-alem", -61894108800000.0 }, // 0 8-08-29
2482 { "en@calendar=hebrew", -180799776000000.0 }, // 0 3761-10-07
2483 { "en@calendar=indian", -59667235200000.0 }, // 0 79-03-24
2484 { "en@calendar=islamic", -42521673600000.0 }, // 0 622-07-15
2485 { "en@calendar=islamic-civil", -42521587200000.0 }, // 0 622-07-16
2486 { "en@calendar=islamic-tbla", -42521673600000.0 }, // 0 622-07-15
2487 { "en@calendar=islamic-umalqura", -42521587200000.0 }, // 0 622-07-16
2488 { "en@calendar=persian", -42531955200000.0 }, // 0 622-03-18
2493 const LocaleWithCalendarAndClearDate
* calAndClearDatesPtr
;
2494 for (calAndClearDatesPtr
= calAndClearDates
; calAndClearDatesPtr
->localeWithCal
!= NULL
; calAndClearDatesPtr
++) {
2495 UErrorCode status
= U_ZERO_ERROR
;
2496 UCalendar
* ucal
= ucal_open(zoneGMT
, -1, calAndClearDatesPtr
->localeWithCal
, UCAL_DEFAULT
, &status
);
2497 if ( U_FAILURE(status
) ) {
2498 log_data_err("FAIL: ucal_open for locale %s, status %s\n", calAndClearDatesPtr
->localeWithCal
, u_errorName(status
));
2502 date
= ucal_getMillis(ucal
, &status
);
2503 if ( U_FAILURE(status
) ) {
2504 log_err("FAIL: ucal_clear, ucal_getMillis for locale %s, status %s\n", calAndClearDatesPtr
->localeWithCal
, u_errorName(status
));
2505 } else if (date
!= calAndClearDatesPtr
->clearDate
) {
2506 log_err("FAIL: ucal_clear, ucal_getMillis for locale %s, expected %.1f, got %.1f\n", calAndClearDatesPtr
->localeWithCal
, calAndClearDatesPtr
->clearDate
, date
);
2513 void TestPersianCalOverflow() {
2514 const char * locale
= "bs_Cyrl@calendar=persian";
2515 UErrorCode status
= U_ZERO_ERROR
;
2516 UCalendar
* ucal
= ucal_open(NULL
, 0, locale
, UCAL_DEFAULT
, &status
);
2517 if ( U_FAILURE(status
) ) {
2518 log_data_err("FAIL: ucal_open for locale %s, status %s\n", locale
, u_errorName(status
));
2520 int32_t maxMonth
= ucal_getLimit(ucal
, UCAL_MONTH
, UCAL_MAXIMUM
, &status
);
2521 int32_t maxDayOfMonth
= ucal_getLimit(ucal
, UCAL_DATE
, UCAL_MAXIMUM
, &status
);
2522 if ( U_FAILURE(status
) ) {
2523 log_err("FAIL: ucal_getLimit MONTH/DATE for locale %s, status %s\n", locale
, u_errorName(status
));
2525 int32_t jd
, month
, dayOfMonth
;
2526 for (jd
= 67023580; jd
<= 67023584; jd
++) { // year 178171, int32_t overflow if jd >= 67023582
2527 status
= U_ZERO_ERROR
;
2529 ucal_set(ucal
, UCAL_JULIAN_DAY
, jd
);
2530 month
= ucal_get(ucal
, UCAL_MONTH
, &status
);
2531 dayOfMonth
= ucal_get(ucal
, UCAL_DATE
, &status
);
2532 if ( U_FAILURE(status
) ) {
2533 log_err("FAIL: ucal_get MONTH/DATE for locale %s, julianDay %d, status %s\n", locale
, jd
, u_errorName(status
));
2534 } else if (month
> maxMonth
|| dayOfMonth
> maxDayOfMonth
) {
2535 log_err("FAIL: locale %s, julianDay %d; maxMonth %d, got month %d; maxDayOfMonth %d, got dayOfMonth %d\n",
2536 locale
, jd
, maxMonth
, month
, maxDayOfMonth
, dayOfMonth
);
2544 /* Apple-specific */
2546 const char * locale
;
2548 UADayPeriod expected
[12]; // expected results for 0..22 in 2-hour increments
2549 } DayPeriodTestItem
;
2551 static const DayPeriodTestItem dpItems
[] = {
2552 { "en", FALSE
, { UADAYPERIOD_NIGHT1
, UADAYPERIOD_NIGHT1
, UADAYPERIOD_NIGHT1
, UADAYPERIOD_MORNING1
, UADAYPERIOD_MORNING1
, UADAYPERIOD_MORNING1
,
2553 UADAYPERIOD_AFTERNOON1
, UADAYPERIOD_AFTERNOON1
, UADAYPERIOD_AFTERNOON1
, UADAYPERIOD_EVENING1
, UADAYPERIOD_EVENING1
, UADAYPERIOD_NIGHT1
} },
2554 { "en", TRUE
, { UADAYPERIOD_MIDNIGHT
, UADAYPERIOD_NIGHT1
, UADAYPERIOD_NIGHT1
, UADAYPERIOD_MORNING1
, UADAYPERIOD_MORNING1
, UADAYPERIOD_MORNING1
,
2555 UADAYPERIOD_NOON
, UADAYPERIOD_AFTERNOON1
, UADAYPERIOD_AFTERNOON1
, UADAYPERIOD_EVENING1
, UADAYPERIOD_EVENING1
, UADAYPERIOD_NIGHT1
} },
2556 { "ta", FALSE
, { UADAYPERIOD_NIGHT1
, UADAYPERIOD_NIGHT1
, UADAYPERIOD_MORNING1
, UADAYPERIOD_MORNING2
, UADAYPERIOD_MORNING2
, UADAYPERIOD_MORNING2
,
2557 UADAYPERIOD_AFTERNOON1
, UADAYPERIOD_AFTERNOON2
, UADAYPERIOD_EVENING1
, UADAYPERIOD_EVENING2
, UADAYPERIOD_EVENING2
, UADAYPERIOD_NIGHT1
} },
2558 // test fallback for languages with no data. Should be to root, but that is broken in the data, so to en for now.
2559 { "tlh", FALSE
, { UADAYPERIOD_NIGHT1
, UADAYPERIOD_NIGHT1
, UADAYPERIOD_NIGHT1
, UADAYPERIOD_MORNING1
, UADAYPERIOD_MORNING1
, UADAYPERIOD_MORNING1
,
2560 UADAYPERIOD_AFTERNOON1
, UADAYPERIOD_AFTERNOON1
, UADAYPERIOD_AFTERNOON1
, UADAYPERIOD_EVENING1
, UADAYPERIOD_EVENING1
, UADAYPERIOD_NIGHT1
} },
2561 { NULL
, FALSE
, { 0 } }
2564 void TestGetDayPeriods() {
2565 static const DayPeriodTestItem
* dpItemPtr
;
2566 for (dpItemPtr
= dpItems
; dpItemPtr
->locale
!= NULL
; dpItemPtr
++) {
2568 for (hourIndex
= 0; hourIndex
< 12; hourIndex
++) {
2569 UErrorCode status
= U_ZERO_ERROR
;
2570 UADayPeriod dp
= uacal_getDayPeriod(dpItemPtr
->locale
, hourIndex
*2, 0, dpItemPtr
->formatStyle
, &status
);
2571 if ( U_FAILURE(status
) ) {
2572 log_err("FAIL: uacal_getDayPeriod, locale %s, hour %d, formatStyle %d, status %s\n",
2573 dpItemPtr
->locale
, hourIndex
*2, dpItemPtr
->formatStyle
, u_errorName(status
));
2574 } else if (dp
!= dpItemPtr
->expected
[hourIndex
]) {
2575 log_err("FAIL: uacal_getDayPeriod, locale %s, hour %d, formatStyle %d, expected dp %d, got %d\n",
2576 dpItemPtr
->locale
, hourIndex
*2, dpItemPtr
->formatStyle
, dpItemPtr
->expected
[hourIndex
], dp
);
2582 #endif /* #if !UCONFIG_NO_FORMATTING */