1b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/*********************************************************************** 2b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * COPYRIGHT: 38393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius * Copyright (c) 1997-2013, International Business Machines Corporation 4b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * and others. All Rights Reserved. 5b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru ***********************************************************************/ 6b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 7b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#include "unicode/utypes.h" 8b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 9b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#if !UCONFIG_NO_FORMATTING 10b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 11b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#include "unicode/timezone.h" 12b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#include "unicode/simpletz.h" 13b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#include "unicode/calendar.h" 14b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#include "unicode/gregocal.h" 15b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#include "unicode/resbund.h" 16b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#include "unicode/strenum.h" 1754dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius#include "unicode/uversion.h" 18b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#include "tztest.h" 19b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#include "cmemory.h" 20b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#include "putilimp.h" 21b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#include "cstring.h" 22b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#include "olsontz.h" 23b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 24b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0])) 25b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 26b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#define CASE(id,test) case id: \ 27b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru name = #test; \ 28b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (exec) { \ 29b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru logln(#test "---"); logln(""); \ 30b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru test(); \ 31b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } \ 32b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru break 33b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 34b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru// ***************************************************************************** 35b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru// class TimeZoneTest 36b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru// ***************************************************************************** 37b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 3854dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius// Some test case data is current date/tzdata version sensitive and producing errors 3954dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius// when year/rule are changed. Although we want to keep our eyes on test failures 4054dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius// caused by tzdata changes while development, keep maintaining test data in maintenance 4154dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius// stream is a little bit hassle. ICU 49 or later versions are using minor version field 4254dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius// to indicate a development build (0) or official release build (others). For development 4354dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius// builds, a test failure triggers an error, while release builds only report them in 4454dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius// verbose mode with logln. 4554dcd9b6a06071f647dac967e9e267abb9410720Craig Corneliusstatic UBool isDevelopmentBuild = (U_ICU_VERSION_MINOR_NUM == 0); 46b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru 47b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queruvoid TimeZoneTest::runIndexedTest( int32_t index, UBool exec, const char* &name, char* /*par*/ ) 48b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru{ 49103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius if (exec) { 50103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius logln("TestSuite TestTimeZone"); 51103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius } 52103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius TESTCASE_AUTO_BEGIN; 53103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius TESTCASE_AUTO(TestPRTOffset); 54103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius TESTCASE_AUTO(TestVariousAPI518); 55103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius TESTCASE_AUTO(TestGetAvailableIDs913); 56103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius TESTCASE_AUTO(TestGenericAPI); 57103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius TESTCASE_AUTO(TestRuleAPI); 58103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius TESTCASE_AUTO(TestShortZoneIDs); 59103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius TESTCASE_AUTO(TestCustomParse); 60103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius TESTCASE_AUTO(TestDisplayName); 61103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius TESTCASE_AUTO(TestDSTSavings); 62103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius TESTCASE_AUTO(TestAlternateRules); 63103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius TESTCASE_AUTO(TestCountries); 64103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius TESTCASE_AUTO(TestHistorical); 65103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius TESTCASE_AUTO(TestEquivalentIDs); 66103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius TESTCASE_AUTO(TestAliasedNames); 67103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius TESTCASE_AUTO(TestFractionalDST); 68103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius TESTCASE_AUTO(TestFebruary); 69103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius TESTCASE_AUTO(TestCanonicalID); 70103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius TESTCASE_AUTO(TestDisplayNamesMeta); 71103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius TESTCASE_AUTO(TestGetRegion); 72103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius TESTCASE_AUTO(TestGetAvailableIDsNew); 73103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius TESTCASE_AUTO(TestGetUnknown); 74103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius TESTCASE_AUTO_END; 75b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru} 76b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 77b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queruconst int32_t TimeZoneTest::millisPerHour = 3600000; 78b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 79b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru// --------------------------------------------------------------------------------- 80b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 81b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/** 82b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * Generic API testing for API coverage. 83b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */ 84b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queruvoid 85b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste QueruTimeZoneTest::TestGenericAPI() 86b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru{ 87b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UnicodeString id("NewGMT"); 88b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t offset = 12345; 89b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 90b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru SimpleTimeZone *zone = new SimpleTimeZone(offset, id); 91b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (zone->useDaylightTime()) errln("FAIL: useDaylightTime should return FALSE"); 92b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 93b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TimeZone* zoneclone = zone->clone(); 94b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (!(*zoneclone == *zone)) errln("FAIL: clone or operator== failed"); 95b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru zoneclone->setID("abc"); 96b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (!(*zoneclone != *zone)) errln("FAIL: clone or operator!= failed"); 97b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru delete zoneclone; 98b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 99b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru zoneclone = zone->clone(); 100b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (!(*zoneclone == *zone)) errln("FAIL: clone or operator== failed"); 101b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru zoneclone->setRawOffset(45678); 102b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (!(*zoneclone != *zone)) errln("FAIL: clone or operator!= failed"); 103b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 104b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru SimpleTimeZone copy(*zone); 105b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (!(copy == *zone)) errln("FAIL: copy constructor or operator== failed"); 106b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru copy = *(SimpleTimeZone*)zoneclone; 107b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (!(copy == *zoneclone)) errln("FAIL: assignment operator or operator== failed"); 108b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 109b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TimeZone* saveDefault = TimeZone::createDefault(); 110b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru logln((UnicodeString)"TimeZone::createDefault() => " + saveDefault->getID(id)); 111b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TimeZone* pstZone = TimeZone::createTimeZone("America/Los_Angeles"); 112b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 113b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru logln("call uprv_timezone() which uses the host"); 114b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru logln("to get the difference in seconds between coordinated universal"); 115b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru logln("time and local time. E.g., -28,800 for PST (GMT-8hrs)"); 116b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 117b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t tzoffset = uprv_timezone(); 118b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru logln(UnicodeString("Value returned from uprv_timezone = ") + tzoffset); 119b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru // Invert sign because UNIX semantics are backwards 120b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (tzoffset < 0) 121b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru tzoffset = -tzoffset; 122b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if ((*saveDefault == *pstZone) && (tzoffset != 28800)) { 123b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru errln("FAIL: t_timezone may be incorrect. It is not 28800"); 124b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 125b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 126b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if ((tzoffset % 900) != 0) { 12750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho /* 12827f654740f2a26ad62a5c155af9199af9e69b889claireho * Ticket#6364 and #7648 12927f654740f2a26ad62a5c155af9199af9e69b889claireho * A few time zones are using GMT offests not a multiple of 15 minutes. 13027f654740f2a26ad62a5c155af9199af9e69b889claireho * Therefore, we should not interpret such case as an error. 13127f654740f2a26ad62a5c155af9199af9e69b889claireho * We downgrade this from errln to infoln. When we see this message, 13227f654740f2a26ad62a5c155af9199af9e69b889claireho * we should examine if it is ignorable or not. 13350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho */ 13427f654740f2a26ad62a5c155af9199af9e69b889claireho infoln("WARNING: t_timezone may be incorrect. It is not a multiple of 15min.", tzoffset); 135b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 136b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 137b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TimeZone::adoptDefault(zone); 138b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TimeZone* defaultzone = TimeZone::createDefault(); 139b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (defaultzone == zone || 140b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru !(*defaultzone == *zone)) 141b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru errln("FAIL: createDefault failed"); 142b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TimeZone::adoptDefault(saveDefault); 143b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru delete defaultzone; 144b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru delete zoneclone; 145b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru delete pstZone; 146b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 147b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UErrorCode status = U_ZERO_ERROR; 148b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru const char* tzver = TimeZone::getTZDataVersion(status); 149b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (U_FAILURE(status)) { 1506d5deb12725f146643d443090dfa11b206df528aJean-Baptiste Queru errcheckln(status, "FAIL: getTZDataVersion failed - %s", u_errorName(status)); 151b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } else if (uprv_strlen(tzver) != 5 /* 4 digits + 1 letter */) { 152b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru errln((UnicodeString)"FAIL: getTZDataVersion returned " + tzver); 153b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } else { 154b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru logln((UnicodeString)"tzdata version: " + tzver); 155b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 156b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru} 157b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 158b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru// --------------------------------------------------------------------------------- 159b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 160b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/** 161b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * Test the setStartRule/setEndRule API calls. 162b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */ 163b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queruvoid 164b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste QueruTimeZoneTest::TestRuleAPI() 165b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru{ 166b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UErrorCode status = U_ZERO_ERROR; 167b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 168b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UDate offset = 60*60*1000*1.75; // Pick a weird offset 169b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru SimpleTimeZone *zone = new SimpleTimeZone((int32_t)offset, "TestZone"); 170b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (zone->useDaylightTime()) errln("FAIL: useDaylightTime should return FALSE"); 171b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 172b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru // Establish our expected transition times. Do this with a non-DST 173b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru // calendar with the (above) declared local offset. 174b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru GregorianCalendar *gc = new GregorianCalendar(*zone, status); 17550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if (failure(status, "new GregorianCalendar", TRUE)) return; 176b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru gc->clear(); 177b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru gc->set(1990, UCAL_MARCH, 1); 178b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UDate marchOneStd = gc->getTime(status); // Local Std time midnight 179b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru gc->clear(); 180b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru gc->set(1990, UCAL_JULY, 1); 181b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UDate julyOneStd = gc->getTime(status); // Local Std time midnight 182b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (failure(status, "GregorianCalendar::getTime")) return; 183b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 184b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru // Starting and ending hours, WALL TIME 185b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t startHour = (int32_t)(2.25 * 3600000); 186b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t endHour = (int32_t)(3.5 * 3600000); 187b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 188b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru zone->setStartRule(UCAL_MARCH, 1, 0, startHour, status); 189b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru zone->setEndRule (UCAL_JULY, 1, 0, endHour, status); 190b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 191b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru delete gc; 192b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru gc = new GregorianCalendar(*zone, status); 193b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (failure(status, "new GregorianCalendar")) return; 194b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 195b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UDate marchOne = marchOneStd + startHour; 196b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UDate julyOne = julyOneStd + endHour - 3600000; // Adjust from wall to Std time 197b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 198b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UDate expMarchOne = 636251400000.0; 199b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (marchOne != expMarchOne) 200b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru { 201b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru errln((UnicodeString)"FAIL: Expected start computed as " + marchOne + 202b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru " = " + dateToString(marchOne)); 203b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru logln((UnicodeString)" Should be " + expMarchOne + 204b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru " = " + dateToString(expMarchOne)); 205b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 206b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 207b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UDate expJulyOne = 646793100000.0; 208b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (julyOne != expJulyOne) 209b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru { 210b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru errln((UnicodeString)"FAIL: Expected start computed as " + julyOne + 211b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru " = " + dateToString(julyOne)); 212b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru logln((UnicodeString)" Should be " + expJulyOne + 213b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru " = " + dateToString(expJulyOne)); 214b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 215b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 216b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru testUsingBinarySearch(*zone, date(90, UCAL_JANUARY, 1), date(90, UCAL_JUNE, 15), marchOne); 217b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru testUsingBinarySearch(*zone, date(90, UCAL_JUNE, 1), date(90, UCAL_DECEMBER, 31), julyOne); 218b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 219b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (zone->inDaylightTime(marchOne - 1000, status) || 220b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru !zone->inDaylightTime(marchOne, status)) 221b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru errln("FAIL: Start rule broken"); 222b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (!zone->inDaylightTime(julyOne - 1000, status) || 223b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru zone->inDaylightTime(julyOne, status)) 224b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru errln("FAIL: End rule broken"); 225b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 226b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru zone->setStartYear(1991); 227b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (zone->inDaylightTime(marchOne, status) || 228b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru zone->inDaylightTime(julyOne - 1000, status)) 229b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru errln("FAIL: Start year broken"); 230b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 231b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru failure(status, "TestRuleAPI"); 232b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru delete gc; 233b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru delete zone; 234b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru} 235b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 236b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queruvoid 237b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste QueruTimeZoneTest::findTransition(const TimeZone& tz, 238b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UDate min, UDate max) { 239b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UErrorCode ec = U_ZERO_ERROR; 240b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UnicodeString id,s; 241b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UBool startsInDST = tz.inDaylightTime(min, ec); 242b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (failure(ec, "TimeZone::inDaylightTime")) return; 243b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (tz.inDaylightTime(max, ec) == startsInDST) { 244b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru logln("Error: " + tz.getID(id) + ".inDaylightTime(" + dateToString(min) + ") = " + (startsInDST?"TRUE":"FALSE") + 245b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru ", inDaylightTime(" + dateToString(max) + ") = " + (startsInDST?"TRUE":"FALSE")); 246b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru return; 247b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 248b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (failure(ec, "TimeZone::inDaylightTime")) return; 249b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru while ((max - min) > INTERVAL) { 250b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UDate mid = (min + max) / 2; 251b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (tz.inDaylightTime(mid, ec) == startsInDST) { 252b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru min = mid; 253b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } else { 254b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru max = mid; 255b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 256b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (failure(ec, "TimeZone::inDaylightTime")) return; 257b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 258b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru min = 1000.0 * uprv_floor(min/1000.0); 259b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru max = 1000.0 * uprv_floor(max/1000.0); 260b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru logln(tz.getID(id) + " Before: " + min/1000 + " = " + 261b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru dateToString(min,s,tz)); 262b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru logln(tz.getID(id) + " After: " + max/1000 + " = " + 263b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru dateToString(max,s,tz)); 264b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru} 265b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 266b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queruvoid 267b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste QueruTimeZoneTest::testUsingBinarySearch(const TimeZone& tz, 268b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UDate min, UDate max, 269b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UDate expectedBoundary) 270b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru{ 271b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UErrorCode status = U_ZERO_ERROR; 272b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UBool startsInDST = tz.inDaylightTime(min, status); 273b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (failure(status, "TimeZone::inDaylightTime")) return; 274b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (tz.inDaylightTime(max, status) == startsInDST) { 275b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru logln("Error: inDaylightTime(" + dateToString(max) + ") != " + ((!startsInDST)?"TRUE":"FALSE")); 276b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru return; 277b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 278b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (failure(status, "TimeZone::inDaylightTime")) return; 279b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru while ((max - min) > INTERVAL) { 280b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UDate mid = (min + max) / 2; 281b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (tz.inDaylightTime(mid, status) == startsInDST) { 282b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru min = mid; 283b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } else { 284b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru max = mid; 285b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 286b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (failure(status, "TimeZone::inDaylightTime")) return; 287b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 288b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru logln(UnicodeString("Binary Search Before: ") + uprv_floor(0.5 + min) + " = " + dateToString(min)); 289b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru logln(UnicodeString("Binary Search After: ") + uprv_floor(0.5 + max) + " = " + dateToString(max)); 290b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UDate mindelta = expectedBoundary - min; 291b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UDate maxdelta = max - expectedBoundary; 292b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (mindelta >= 0 && 293b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru mindelta <= INTERVAL && 294b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru maxdelta >= 0 && 295b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru maxdelta <= INTERVAL) 296b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru logln(UnicodeString("PASS: Expected bdry: ") + expectedBoundary + " = " + dateToString(expectedBoundary)); 297b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru else 298b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru errln(UnicodeString("FAIL: Expected bdry: ") + expectedBoundary + " = " + dateToString(expectedBoundary)); 299b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru} 300b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 301b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queruconst UDate TimeZoneTest::INTERVAL = 100; 302b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 303b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru// --------------------------------------------------------------------------------- 304b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 305b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru// ------------------------------------- 306b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 307b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/** 308b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * Test the offset of the PRT timezone. 309b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */ 310b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queruvoid 311b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste QueruTimeZoneTest::TestPRTOffset() 312b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru{ 313b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TimeZone* tz = TimeZone::createTimeZone("PRT"); 314b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (tz == 0) { 315b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru errln("FAIL: TimeZone(PRT) is null"); 316b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 317b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru else { 318b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t expectedHour = -4; 319b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru double expectedOffset = (((double)expectedHour) * millisPerHour); 320b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru double foundOffset = tz->getRawOffset(); 321b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t foundHour = (int32_t)foundOffset / millisPerHour; 322b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (expectedOffset != foundOffset) { 3236d5deb12725f146643d443090dfa11b206df528aJean-Baptiste Queru dataerrln("FAIL: Offset for PRT should be %d, found %d", expectedHour, foundHour); 324b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } else { 325b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru logln("PASS: Offset for PRT should be %d, found %d", expectedHour, foundHour); 326b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 327b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 328b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru delete tz; 329b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru} 330b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 331b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru// ------------------------------------- 332b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 333b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/** 334b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * Regress a specific bug with a sequence of API calls. 335b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */ 336b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queruvoid 337b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste QueruTimeZoneTest::TestVariousAPI518() 338b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru{ 339b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UErrorCode status = U_ZERO_ERROR; 340b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TimeZone* time_zone = TimeZone::createTimeZone("PST"); 341b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UDate d = date(97, UCAL_APRIL, 30); 342b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UnicodeString str; 343b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru logln("The timezone is " + time_zone->getID(str)); 3446d5deb12725f146643d443090dfa11b206df528aJean-Baptiste Queru if (!time_zone->inDaylightTime(d, status)) dataerrln("FAIL: inDaylightTime returned FALSE"); 34550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if (failure(status, "TimeZone::inDaylightTime", TRUE)) return; 3466d5deb12725f146643d443090dfa11b206df528aJean-Baptiste Queru if (!time_zone->useDaylightTime()) dataerrln("FAIL: useDaylightTime returned FALSE"); 3476d5deb12725f146643d443090dfa11b206df528aJean-Baptiste Queru if (time_zone->getRawOffset() != - 8 * millisPerHour) dataerrln("FAIL: getRawOffset returned wrong value"); 348b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru GregorianCalendar *gc = new GregorianCalendar(status); 349b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (U_FAILURE(status)) { errln("FAIL: Couldn't create GregorianCalendar"); return; } 350b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru gc->setTime(d, status); 351b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (U_FAILURE(status)) { errln("FAIL: GregorianCalendar::setTime failed"); return; } 352b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (time_zone->getOffset(gc->AD, gc->get(UCAL_YEAR, status), gc->get(UCAL_MONTH, status), 353b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru gc->get(UCAL_DATE, status), (uint8_t)gc->get(UCAL_DAY_OF_WEEK, status), 0, status) != - 7 * millisPerHour) 3546d5deb12725f146643d443090dfa11b206df528aJean-Baptiste Queru dataerrln("FAIL: getOffset returned wrong value"); 355b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (U_FAILURE(status)) { errln("FAIL: GregorianCalendar::set failed"); return; } 356b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru delete gc; 357b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru delete time_zone; 358b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru} 359b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 360b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru// ------------------------------------- 361b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 362b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/** 363b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * Test the call which retrieves the available IDs. 364b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */ 365b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queruvoid 366b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste QueruTimeZoneTest::TestGetAvailableIDs913() 367b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru{ 368b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UErrorCode ec = U_ZERO_ERROR; 369b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t i; 370b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 371b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#ifdef U_USE_TIMEZONE_OBSOLETE_2_8 372b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru // Test legacy API -- remove these tests when the corresponding API goes away (duh) 373b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t numIDs = -1; 374b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru const UnicodeString** ids = TimeZone::createAvailableIDs(numIDs); 375b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (ids == 0 || numIDs < 1) { 376b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru errln("FAIL: createAvailableIDs()"); 377b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } else { 378b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UnicodeString buf("TimeZone::createAvailableIDs() = { "); 379b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru for(i=0; i<numIDs; ++i) { 380b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (i) buf.append(", "); 381b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru buf.append(*ids[i]); 382b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 383b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru buf.append(" } "); 384b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru logln(buf + numIDs); 385b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru // we own the array; the caller owns the contained strings (yuck) 386b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uprv_free(ids); 387b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 388b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 389b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru numIDs = -1; 390b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru ids = TimeZone::createAvailableIDs(-8*U_MILLIS_PER_HOUR, numIDs); 391b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (ids == 0 || numIDs < 1) { 392b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru errln("FAIL: createAvailableIDs(-8:00)"); 393b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } else { 394b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UnicodeString buf("TimeZone::createAvailableIDs(-8:00) = { "); 395b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru for(i=0; i<numIDs; ++i) { 396b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (i) buf.append(", "); 397b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru buf.append(*ids[i]); 398b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 399b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru buf.append(" } "); 400b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru logln(buf + numIDs); 401b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru // we own the array; the caller owns the contained strings (yuck) 402b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uprv_free(ids); 403b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 404b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru numIDs = -1; 405b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru ids = TimeZone::createAvailableIDs("US", numIDs); 406b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (ids == 0 || numIDs < 1) { 407b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru errln("FAIL: createAvailableIDs(US) ids=%d, numIDs=%d", ids, numIDs); 408b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } else { 409b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UnicodeString buf("TimeZone::createAvailableIDs(US) = { "); 410b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru for(i=0; i<numIDs; ++i) { 411b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (i) buf.append(", "); 412b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru buf.append(*ids[i]); 413b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 414b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru buf.append(" } "); 415b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru logln(buf + numIDs); 416b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru // we own the array; the caller owns the contained strings (yuck) 417b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru uprv_free(ids); 418b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 419b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#endif 420b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 421b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UnicodeString str; 422b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UnicodeString *buf = new UnicodeString("TimeZone::createEnumeration() = { "); 423b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t s_length; 424b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru StringEnumeration* s = TimeZone::createEnumeration(); 425b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho if (s == NULL) { 426b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho dataerrln("Unable to create TimeZone enumeration"); 427b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho return; 428b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho } 429b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru s_length = s->count(ec); 430b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru for (i = 0; i < s_length;++i) { 431b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (i > 0) *buf += ", "; 432b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if ((i & 1) == 0) { 433b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru *buf += *s->snext(ec); 434b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } else { 435b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru *buf += UnicodeString(s->next(NULL, ec), ""); 436b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 437b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 438b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if((i % 5) == 4) { 439b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru // replace s with a clone of itself 440b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru StringEnumeration *s2 = s->clone(); 441b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(s2 == NULL || s_length != s2->count(ec)) { 442b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru errln("TimezoneEnumeration.clone() failed"); 443b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } else { 444b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru delete s; 445b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru s = s2; 446b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 447b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 448b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 449b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru *buf += " };"; 450b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru logln(*buf); 451b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 452b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* Confirm that the following zones can be retrieved: The first 453b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * zone, the last zone, and one in-between. This tests the binary 454b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * search through the system zone data. 455b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */ 456b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru s->reset(ec); 457b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t middle = s_length/2; 458b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru for (i=0; i<s_length; ++i) { 459b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru const UnicodeString* id = s->snext(ec); 460b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (i==0 || i==middle || i==(s_length-1)) { 461b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TimeZone *z = TimeZone::createTimeZone(*id); 462b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (z == 0) { 463b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru errln(UnicodeString("FAIL: createTimeZone(") + 464b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru *id + ") -> 0"); 465b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } else if (z->getID(str) != *id) { 466b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru errln(UnicodeString("FAIL: createTimeZone(") + 467b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru *id + ") -> zone " + str); 468b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } else { 469b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru logln(UnicodeString("OK: createTimeZone(") + 470b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru *id + ") succeeded"); 471b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 472b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru delete z; 473b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 474b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 475b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru delete s; 476b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 477b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru buf->truncate(0); 478b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru *buf += "TimeZone::createEnumeration(GMT+01:00) = { "; 479b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 480b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru s = TimeZone::createEnumeration(1 * U_MILLIS_PER_HOUR); 481b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru s_length = s->count(ec); 482b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru for (i = 0; i < s_length;++i) { 483b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (i > 0) *buf += ", "; 484b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru *buf += *s->snext(ec); 485b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 486b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru delete s; 487b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru *buf += " };"; 488b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru logln(*buf); 489b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 490b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 491b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru buf->truncate(0); 492b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru *buf += "TimeZone::createEnumeration(US) = { "; 493b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 494b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru s = TimeZone::createEnumeration("US"); 495b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru s_length = s->count(ec); 496b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru for (i = 0; i < s_length;++i) { 497b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (i > 0) *buf += ", "; 498b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru *buf += *s->snext(ec); 499b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 500b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru *buf += " };"; 501b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru logln(*buf); 502b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 503b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TimeZone *tz = TimeZone::createTimeZone("PST"); 504b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (tz != 0) logln("getTimeZone(PST) = " + tz->getID(str)); 505b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru else errln("FAIL: getTimeZone(PST) = null"); 506b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru delete tz; 507b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru tz = TimeZone::createTimeZone("America/Los_Angeles"); 508b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (tz != 0) logln("getTimeZone(America/Los_Angeles) = " + tz->getID(str)); 509b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru else errln("FAIL: getTimeZone(PST) = null"); 510b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru delete tz; 511b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 512b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru // @bug 4096694 513b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru tz = TimeZone::createTimeZone("NON_EXISTENT"); 514b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UnicodeString temp; 515b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (tz == 0) 516b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru errln("FAIL: getTimeZone(NON_EXISTENT) = null"); 517b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho else if (tz->getID(temp) != UCAL_UNKNOWN_ZONE_ID) 518b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru errln("FAIL: getTimeZone(NON_EXISTENT) = " + temp); 519b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru delete tz; 520b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 521b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru delete buf; 522b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru delete s; 523b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru} 524b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 525b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2clairehovoid 526b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2clairehoTimeZoneTest::TestGetAvailableIDsNew() 527b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho{ 528b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho UErrorCode ec = U_ZERO_ERROR; 529b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho StringEnumeration *any, *canonical, *canonicalLoc; 530b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho StringEnumeration *any_US, *canonical_US, *canonicalLoc_US; 531b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho StringEnumeration *any_W5, *any_CA_W5; 532b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho StringEnumeration *any_US_E14; 533b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho int32_t rawOffset; 534b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho const UnicodeString *id1, *id2; 535b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho UnicodeString canonicalID; 536b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho UBool isSystemID; 537b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho char region[4]; 538b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho int32_t zoneCount; 539b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho 540b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho any = canonical = canonicalLoc = any_US = canonical_US = canonicalLoc_US = any_W5 = any_CA_W5 = any_US_E14 = NULL; 541b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho 542b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho any = TimeZone::createTimeZoneIDEnumeration(UCAL_ZONE_TYPE_ANY, NULL, NULL, ec); 543b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho if (U_FAILURE(ec)) { 544b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho dataerrln("Failed to create enumration for ANY"); 545b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho goto cleanup; 546b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho } 547b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho 548b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho canonical = TimeZone::createTimeZoneIDEnumeration(UCAL_ZONE_TYPE_CANONICAL, NULL, NULL, ec); 549b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho if (U_FAILURE(ec)) { 550b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho errln("Failed to create enumration for CANONICAL"); 551b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho goto cleanup; 552b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho } 553b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho 554b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho canonicalLoc = TimeZone::createTimeZoneIDEnumeration(UCAL_ZONE_TYPE_CANONICAL_LOCATION, NULL, NULL, ec); 555b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho if (U_FAILURE(ec)) { 556b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho errln("Failed to create enumration for CANONICALLOC"); 557b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho goto cleanup; 558b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho } 559b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho 560b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho any_US = TimeZone::createTimeZoneIDEnumeration(UCAL_ZONE_TYPE_ANY, "US", NULL, ec); 561b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho if (U_FAILURE(ec)) { 562b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho errln("Failed to create enumration for ANY_US"); 563b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho goto cleanup; 564b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho } 565b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho 566b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho canonical_US = TimeZone::createTimeZoneIDEnumeration(UCAL_ZONE_TYPE_CANONICAL, "US", NULL, ec); 567b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho if (U_FAILURE(ec)) { 568b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho errln("Failed to create enumration for CANONICAL_US"); 569b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho goto cleanup; 570b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho } 571b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho 572b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho canonicalLoc_US = TimeZone::createTimeZoneIDEnumeration(UCAL_ZONE_TYPE_CANONICAL_LOCATION, "US", NULL, ec); 573b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho if (U_FAILURE(ec)) { 574b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho errln("Failed to create enumration for CANONICALLOC_US"); 575b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho goto cleanup; 576b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho } 577b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho 578b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho rawOffset = (-5)*60*60*1000; 579b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho any_W5 = TimeZone::createTimeZoneIDEnumeration(UCAL_ZONE_TYPE_ANY, NULL, &rawOffset, ec); 580b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho if (U_FAILURE(ec)) { 581b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho errln("Failed to create enumration for ANY_W5"); 582b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho goto cleanup; 583b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho } 584b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho 585b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho any_CA_W5 = TimeZone::createTimeZoneIDEnumeration(UCAL_ZONE_TYPE_ANY, "CA", &rawOffset, ec); 586b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho if (U_FAILURE(ec)) { 587b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho errln("Failed to create enumration for ANY_CA_W5"); 588b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho goto cleanup; 589b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho } 590b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho 591b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho rawOffset = 14*60*60*1000; 592b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho any_US_E14 = TimeZone::createTimeZoneIDEnumeration(UCAL_ZONE_TYPE_ANY, "US", &rawOffset, ec); 593b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho if (U_FAILURE(ec)) { 594b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho errln("Failed to create enumration for ANY_US_E14"); 595b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho goto cleanup; 596b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho } 597b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho 598b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho checkContainsAll(any, "ANY", canonical, "CANONICAL"); 599b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho checkContainsAll(canonical, "CANONICAL", canonicalLoc, "CANONICALLOC"); 600b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho 601b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho checkContainsAll(any, "ANY", any_US, "ANY_US"); 602b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho checkContainsAll(canonical, "CANONICAL", canonical_US, "CANONICAL_US"); 603b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho checkContainsAll(canonicalLoc, "CANONICALLOC", canonicalLoc_US, "CANONICALLOC_US"); 604b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho 605b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho checkContainsAll(any_US, "ANY_US", canonical_US, "CANONICAL_US"); 606b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho checkContainsAll(canonical_US, "CANONICAL_US", canonicalLoc_US, "CANONICALLOC_US"); 607b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho 608b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho checkContainsAll(any, "ANY", any_W5, "ANY_W5"); 609b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho checkContainsAll(any_W5, "ANY_W5", any_CA_W5, "ANY_CA_W5"); 610b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho 611b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho // And ID in any set, but not in canonical set must not be a canonical ID 612b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho any->reset(ec); 613b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho while ((id1 = any->snext(ec)) != NULL) { 614b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho UBool found = FALSE; 615b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho canonical->reset(ec); 616b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho while ((id2 = canonical->snext(ec)) != NULL) { 617b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho if (*id1 == *id2) { 618b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho found = TRUE; 619b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho break; 620b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho } 621b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho } 622b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho if (U_FAILURE(ec)) { 623b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho break; 624b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho } 625b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho if (!found) { 626b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho TimeZone::getCanonicalID(*id1, canonicalID, isSystemID, ec); 627b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho if (U_FAILURE(ec)) { 628b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho break; 629b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho } 630b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho if (*id1 == canonicalID) { 631b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho errln((UnicodeString)"FAIL: canonicalID [" + *id1 + "] is not in CANONICAL"); 632b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho } 633b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho if (!isSystemID) { 634b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho errln((UnicodeString)"FAIL: ANY contains non-system ID: " + *id1); 635b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho } 636b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho } 637b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho } 638b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho if (U_FAILURE(ec)) { 639b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho errln("Error checking IDs in ANY, but not in CANONICAL"); 640b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho ec = U_ZERO_ERROR; 641b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho } 642b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho 643b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho // canonical set must contains only canonical IDs 644b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho canonical->reset(ec); 645b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho while ((id1 = canonical->snext(ec)) != NULL) { 646b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho TimeZone::getCanonicalID(*id1, canonicalID, isSystemID, ec); 647b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho if (U_FAILURE(ec)) { 648b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho break; 649b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho } 650b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho if (*id1 != canonicalID) { 651b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho errln((UnicodeString)"FAIL: CANONICAL contains non-canonical ID: " + *id1); 652b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho } 653b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho if (!isSystemID) { 654b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho errln((UnicodeString)"FAILE: CANONICAL contains non-system ID: " + *id1); 655b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho } 656b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho } 657b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho if (U_FAILURE(ec)) { 658b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho errln("Error checking IDs in CANONICAL"); 659b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho ec = U_ZERO_ERROR; 660b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho } 661b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho 662b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho // canonicalLoc set must contain only canonical location IDs 663b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho canonicalLoc->reset(ec); 664b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho while ((id1 = canonicalLoc->snext(ec)) != NULL) { 665b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho TimeZone::getRegion(*id1, region, sizeof(region), ec); 666b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho if (U_FAILURE(ec)) { 667b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho break; 668b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho } 669b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho if (uprv_strcmp(region, "001") == 0) { 670b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho errln((UnicodeString)"FAIL: CANONICALLOC contains non location zone: " + *id1); 671b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho } 672b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho } 673b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho if (U_FAILURE(ec)) { 674b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho errln("Error checking IDs in CANONICALLOC"); 675b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho ec = U_ZERO_ERROR; 676b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho } 677b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho 678b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho // any_US must contain only US zones 679b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho any_US->reset(ec); 680b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho while ((id1 = any_US->snext(ec)) != NULL) { 681b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho TimeZone::getRegion(*id1, region, sizeof(region), ec); 682b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho if (U_FAILURE(ec)) { 683b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho break; 684b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho } 685b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho if (uprv_strcmp(region, "US") != 0) { 686b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho errln((UnicodeString)"FAIL: ANY_US contains non-US zone ID: " + *id1); 687b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho } 688b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho } 689b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho if (U_FAILURE(ec)) { 690b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho errln("Error checking IDs in ANY_US"); 691b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho ec = U_ZERO_ERROR; 692b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho } 693b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho 694b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho // any_W5 must contain only GMT-05:00 zones 695b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho any_W5->reset(ec); 696b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho while ((id1 = any_W5->snext(ec)) != NULL) { 697b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho TimeZone *tz = TimeZone::createTimeZone(*id1); 698b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho if (tz->getRawOffset() != (-5)*60*60*1000) { 699b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho errln((UnicodeString)"FAIL: ANY_W5 contains a zone whose offset is not -05:00: " + *id1); 700b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho } 701b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho delete tz; 702b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho } 703b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho if (U_FAILURE(ec)) { 704b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho errln("Error checking IDs in ANY_W5"); 705b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho ec = U_ZERO_ERROR; 706b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho } 707b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho 708b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho // No US zone swith GMT+14:00 709b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho zoneCount = any_US_E14->count(ec); 710b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho if (U_FAILURE(ec)) { 711b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho errln("Error checking IDs in ANY_US_E14"); 712b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho ec = U_ZERO_ERROR; 713b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho } else if (zoneCount != 0) { 714b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho errln("FAIL: ANY_US_E14 must be empty"); 715b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho } 716b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho 717b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2clairehocleanup: 718b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho delete any; 719b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho delete canonical; 720b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho delete canonicalLoc; 721b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho delete any_US; 722b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho delete canonical_US; 723b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho delete canonicalLoc_US; 724b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho delete any_W5; 725b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho delete any_CA_W5; 726b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho delete any_US_E14; 727b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho} 728b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho 729b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2clairehovoid 730b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2clairehoTimeZoneTest::checkContainsAll(StringEnumeration *s1, const char *name1, 731b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho StringEnumeration *s2, const char *name2) 732b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho{ 733b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho UErrorCode ec = U_ZERO_ERROR; 734b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho const UnicodeString *id1, *id2; 735b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho 736b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho s2->reset(ec); 737b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho 738b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho while ((id2 = s2->snext(ec)) != NULL) { 739b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho UBool found = FALSE; 740b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho s1->reset(ec); 741b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho while ((id1 = s1->snext(ec)) != NULL) { 742b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho if (*id1 == *id2) { 743b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho found = TRUE; 744b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho break; 745b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho } 746b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho } 747b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho if (!found) { 748b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho errln((UnicodeString)"FAIL: " + name1 + "does not contain " 749b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho + *id2 + " in " + name2); 750b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho } 751b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho } 752b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho 753b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho if (U_FAILURE(ec)) { 754b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho errln((UnicodeString)"Error checkContainsAll for " + name1 + " - " + name2); 755b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho } 756b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho} 757b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 758b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/** 759b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * NOTE: As of ICU 2.8, this test confirms that the "tz.alias" 760b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * file, used to build ICU alias zones, is working. It also 761b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * looks at some genuine Olson compatibility IDs. [aliu] 762b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * 763b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * This test is problematic. It should really just confirm that 764b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * the list of compatibility zone IDs exist and are somewhat 765b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * meaningful (that is, they aren't all aliases of GMT). It goes a 766b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * bit further -- it hard-codes expectations about zone behavior, 767b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * when in fact zones are redefined quite frequently. ICU's build 768b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * process means that it is easy to update ICU to contain the 769b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * latest Olson zone data, but if a zone tested here changes, then 770b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * this test will fail. I have updated the test for 1999j data, 771b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * but further updates will probably be required. Note that some 772b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * of the concerts listed below no longer apply -- in particular, 773b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * we do NOT overwrite real UNIX zones with 3-letter IDs. There 774b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * are two points of overlap as of 1999j: MET and EET. These are 775b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * both real UNIX zones, so we just use the official 776b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * definition. This test has been updated to reflect this. 777b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * 12/3/99 aliu 778b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * 779b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * Added tests for additional zones and aliases from the icuzones file. 780b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * Markus Scherer 2006-nov-06 781b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * 782b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * [srl - from java - 7/5/1998] 783b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * @bug 4130885 784b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * Certain short zone IDs, used since 1.1.x, are incorrect. 785b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * 786b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * The worst of these is: 787b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * 788b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * "CAT" (Central African Time) should be GMT+2:00, but instead returns a 789b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * zone at GMT-1:00. The zone at GMT-1:00 should be called EGT, CVT, EGST, 790b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * or AZOST, depending on which zone is meant, but in no case is it CAT. 791b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * 792b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * Other wrong zone IDs: 793b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * 794b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * ECT (European Central Time) GMT+1:00: ECT is Ecuador Time, 795b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * GMT-5:00. European Central time is abbreviated CEST. 796b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * 797b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * SST (Solomon Island Time) GMT+11:00. SST is actually Samoa Standard Time, 798b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * GMT-11:00. Solomon Island time is SBT. 799b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * 800b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * NST (New Zealand Time) GMT+12:00. NST is the abbreviation for 801b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * Newfoundland Standard Time, GMT-3:30. New Zealanders use NZST. 802b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * 803b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * AST (Alaska Standard Time) GMT-9:00. [This has already been noted in 804b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * another bug.] It should be "AKST". AST is Atlantic Standard Time, 805b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * GMT-4:00. 806b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * 807b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * PNT (Phoenix Time) GMT-7:00. PNT usually means Pitcairn Time, 808b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * GMT-8:30. There is no standard abbreviation for Phoenix time, as distinct 809b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * from MST with daylight savings. 810b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * 811b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * In addition to these problems, a number of zones are FAKE. That is, they 812b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * don't match what people use in the real world. 813b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * 814b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * FAKE zones: 815b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * 816b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * EET (should be EEST) 817b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * ART (should be EEST) 818b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * MET (should be IRST) 819b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * NET (should be AMST) 820b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * PLT (should be PKT) 821b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * BST (should be BDT) 822b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * VST (should be ICT) 823b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * CTT (should be CST) + 824b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * ACT (should be CST) + 825b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * AET (should be EST) + 826b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * MIT (should be WST) + 827b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * IET (should be EST) + 828b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * PRT (should be AST) + 829b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * CNT (should be NST) 830b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * AGT (should be ARST) 831b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * BET (should be EST) + 832b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * 833b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * + A zone with the correct name already exists and means something 834b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * else. E.g., EST usually indicates the US Eastern zone, so it cannot be 835b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * used for Brazil (BET). 836b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */ 837b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queruvoid TimeZoneTest::TestShortZoneIDs() 838b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru{ 839b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t i; 840b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru // Create a small struct to hold the array 841b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru struct 842b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru { 843b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru const char *id; 844b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t offset; 845b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UBool daylight; 846b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 847b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru kReferenceList [] = 848b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru { 84954dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius {"HST", -600, FALSE}, // Olson northamerica -10:00 85054dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius {"AST", -540, TRUE}, // ICU Link - America/Anchorage 85154dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius {"PST", -480, TRUE}, // ICU Link - America/Los_Angeles 85254dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius {"PNT", -420, FALSE}, // ICU Link - America/Phoenix 853b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"MST", -420, FALSE}, // updated Aug 2003 aliu 85454dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius {"CST", -360, TRUE}, // Olson northamerica -7:00 85554dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius {"IET", -300, TRUE}, // ICU Link - America/Indiana/Indianapolis 85654dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius {"EST", -300, FALSE}, // Olson northamerica -5:00 85754dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius {"PRT", -240, FALSE}, // ICU Link - America/Puerto_Rico 85854dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius {"CNT", -210, TRUE}, // ICU Link - America/St_Johns 85954dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius {"AGT", -180, FALSE}, // ICU Link - America/Argentina/Buenos_Aires 86054dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius {"BET", -180, TRUE}, // ICU Link - America/Sao_Paulo 86154dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius {"GMT", 0, FALSE}, // Olson etcetera Link - Etc/GMT 86254dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius {"UTC", 0, FALSE}, // Olson etcetera 0 86354dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius {"ECT", 60, TRUE}, // ICU Link - Europe/Paris 86454dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius {"MET", 60, TRUE}, // Olson europe 1:00 C-Eur 86554dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius {"CAT", 120, FALSE}, // ICU Link - Africa/Harare 86654dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius {"ART", 120, FALSE}, // ICU Link - Africa/Cairo 86754dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius {"EET", 120, TRUE}, // Olson europe 2:00 EU 86854dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius {"EAT", 180, FALSE}, // ICU Link - Africa/Addis_Ababa 86954dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius {"NET", 240, FALSE}, // ICU Link - Asia/Yerevan 87054dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius {"PLT", 300, FALSE}, // ICU Link - Asia/Karachi 87154dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius {"IST", 330, FALSE}, // ICU Link - Asia/Kolkata 87254dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius {"BST", 360, FALSE}, // ICU Link - Asia/Dhaka 87354dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius {"VST", 420, FALSE}, // ICU Link - Asia/Ho_Chi_Minh 87454dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius {"CTT", 480, FALSE}, // ICU Link - Asia/Shanghai 87554dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius {"JST", 540, FALSE}, // ICU Link - Asia/Tokyo 87654dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius {"ACT", 570, FALSE}, // ICU Link - Australia/Darwin 87754dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius {"AET", 600, TRUE}, // ICU Link - Australia/Sydney 87854dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius {"SST", 660, FALSE}, // ICU Link - Pacific/Guadalcanal 87954dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius {"NST", 720, TRUE}, // ICU Link - Pacific/Auckland 88054dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius {"MIT", 780, TRUE}, // ICU Link - Pacific/Apia 88154dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius 88254dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius {"Etc/Unknown", 0, FALSE}, // CLDR 883b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 884b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"SystemV/AST4ADT", -240, TRUE}, 885b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"SystemV/EST5EDT", -300, TRUE}, 886b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"SystemV/CST6CDT", -360, TRUE}, 887b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"SystemV/MST7MDT", -420, TRUE}, 888b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"SystemV/PST8PDT", -480, TRUE}, 889b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"SystemV/YST9YDT", -540, TRUE}, 890b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"SystemV/AST4", -240, FALSE}, 891b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"SystemV/EST5", -300, FALSE}, 892b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"SystemV/CST6", -360, FALSE}, 893b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"SystemV/MST7", -420, FALSE}, 894b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"SystemV/PST8", -480, FALSE}, 895b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"SystemV/YST9", -540, FALSE}, 896b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"SystemV/HST10", -600, FALSE}, 897b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 898b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"",0,FALSE} 899b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru }; 900b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 901b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru for(i=0;kReferenceList[i].id[0];i++) { 902b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UnicodeString itsID(kReferenceList[i].id); 903b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UBool ok = TRUE; 904b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru // Check existence. 905b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TimeZone *tz = TimeZone::createTimeZone(itsID); 906b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (!tz || (kReferenceList[i].offset != 0 && *tz == *TimeZone::getGMT())) { 907b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru errln("FAIL: Time Zone " + itsID + " does not exist!"); 908b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru continue; 909b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 910b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 911b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru // Check daylight usage. 912b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UBool usesDaylight = tz->useDaylightTime(); 913b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (usesDaylight != kReferenceList[i].daylight) { 91454dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius if (!isDevelopmentBuild) { 915b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru logln("Warning: Time Zone " + itsID + " use daylight is " + 916b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru (usesDaylight?"TRUE":"FALSE") + 917b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru " but it should be " + 918b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru ((kReferenceList[i].daylight)?"TRUE":"FALSE")); 919b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } else { 92054dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius dataerrln("FAIL: Time Zone " + itsID + " use daylight is " + 921b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru (usesDaylight?"TRUE":"FALSE") + 922b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru " but it should be " + 923b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru ((kReferenceList[i].daylight)?"TRUE":"FALSE")); 924b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 925b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru ok = FALSE; 926b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 927b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 928b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru // Check offset 929b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t offsetInMinutes = tz->getRawOffset()/60000; 930b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (offsetInMinutes != kReferenceList[i].offset) { 93154dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius if (!isDevelopmentBuild) { 932b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru logln("FAIL: Time Zone " + itsID + " raw offset is " + 933b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru offsetInMinutes + 934b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru " but it should be " + kReferenceList[i].offset); 935b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } else { 93654dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius dataerrln("FAIL: Time Zone " + itsID + " raw offset is " + 937b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru offsetInMinutes + 938b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru " but it should be " + kReferenceList[i].offset); 939b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 940b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru ok = FALSE; 941b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 942b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 943b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (ok) { 944b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru logln("OK: " + itsID + 945b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru " useDaylightTime() & getRawOffset() as expected"); 946b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 947b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru delete tz; 948b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 949b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 950b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 951b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru // OK now test compat 952b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru logln("Testing for compatibility zones"); 953b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 954b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru const char* compatibilityMap[] = { 955b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru // This list is copied from tz.alias. If tz.alias 956b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru // changes, this list must be updated. Current as of Mar 2007 957b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru "ACT", "Australia/Darwin", 958b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru "AET", "Australia/Sydney", 959b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru "AGT", "America/Buenos_Aires", 960b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru "ART", "Africa/Cairo", 961b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru "AST", "America/Anchorage", 962b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru "BET", "America/Sao_Paulo", 963b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru "BST", "Asia/Dhaka", // # spelling changed in 2000h; was Asia/Dacca 964b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru "CAT", "Africa/Harare", 965b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru "CNT", "America/St_Johns", 966b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru "CST", "America/Chicago", 967b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru "CTT", "Asia/Shanghai", 968b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru "EAT", "Africa/Addis_Ababa", 969b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru "ECT", "Europe/Paris", 970b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru // EET Europe/Istanbul # EET is a standard UNIX zone 971b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru // "EST", "America/New_York", # Defined as -05:00 972b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru // "HST", "Pacific/Honolulu", # Defined as -10:00 973b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru "IET", "America/Indianapolis", 974b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru "IST", "Asia/Calcutta", 975b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru "JST", "Asia/Tokyo", 976b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru // MET Asia/Tehran # MET is a standard UNIX zone 977b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru "MIT", "Pacific/Apia", 978b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru // "MST", "America/Denver", # Defined as -07:00 979b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru "NET", "Asia/Yerevan", 980b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru "NST", "Pacific/Auckland", 981b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru "PLT", "Asia/Karachi", 982b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru "PNT", "America/Phoenix", 983b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru "PRT", "America/Puerto_Rico", 984b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru "PST", "America/Los_Angeles", 985b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru "SST", "Pacific/Guadalcanal", 986b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru "UTC", "Etc/GMT", 987b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru "VST", "Asia/Saigon", 988b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru "","","" 989b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru }; 990b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 991b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru for (i=0;*compatibilityMap[i];i+=2) { 992b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UnicodeString itsID; 993b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 994b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru const char *zone1 = compatibilityMap[i]; 995b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru const char *zone2 = compatibilityMap[i+1]; 996b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 997b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TimeZone *tz1 = TimeZone::createTimeZone(zone1); 998b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TimeZone *tz2 = TimeZone::createTimeZone(zone2); 999b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1000b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (!tz1) { 1001b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru errln(UnicodeString("FAIL: Could not find short ID zone ") + zone1); 1002b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1003b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (!tz2) { 1004b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru errln(UnicodeString("FAIL: Could not find long ID zone ") + zone2); 1005b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1006b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1007b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (tz1 && tz2) { 1008b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru // make NAME same so comparison will only look at the rest 1009b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru tz2->setID(tz1->getID(itsID)); 1010b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1011b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (*tz1 != *tz2) { 1012b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru errln("FAIL: " + UnicodeString(zone1) + 1013b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru " != " + UnicodeString(zone2)); 1014b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } else { 1015b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru logln("OK: " + UnicodeString(zone1) + 1016b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru " == " + UnicodeString(zone2)); 1017b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1018b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1019b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1020b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru delete tz1; 1021b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru delete tz2; 1022b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1023b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru} 1024b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1025b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1026b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/** 1027b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * Utility function for TestCustomParse 1028b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */ 1029b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste QueruUnicodeString& TimeZoneTest::formatOffset(int32_t offset, UnicodeString &rv) { 1030b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru rv.remove(); 1031b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UChar sign = 0x002B; 1032b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (offset < 0) { 1033b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru sign = 0x002D; 1034b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru offset = -offset; 1035b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1036b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1037b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t s = offset % 60; 1038b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru offset /= 60; 1039b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t m = offset % 60; 1040b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t h = offset / 60; 1041b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1042b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru rv += (UChar)(sign); 1043b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (h >= 10) { 1044b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru rv += (UChar)(0x0030 + (h/10)); 1045b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } else { 1046b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru rv += (UChar)0x0030; 1047b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1048b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru rv += (UChar)(0x0030 + (h%10)); 1049b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1050b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru rv += (UChar)0x003A; /* ':' */ 1051b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (m >= 10) { 1052b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru rv += (UChar)(0x0030 + (m/10)); 1053b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } else { 1054b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru rv += (UChar)0x0030; 1055b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1056b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru rv += (UChar)(0x0030 + (m%10)); 1057b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1058b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (s) { 1059b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru rv += (UChar)0x003A; /* ':' */ 1060b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (s >= 10) { 1061b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru rv += (UChar)(0x0030 + (s/10)); 1062b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } else { 1063b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru rv += (UChar)0x0030; 1064b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1065b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru rv += (UChar)(0x0030 + (s%10)); 1066b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1067b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru return rv; 1068b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru} 1069b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1070b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/** 1071b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * Utility function for TestCustomParse, generating time zone ID 1072b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * string for the give offset. 1073b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */ 1074b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste QueruUnicodeString& TimeZoneTest::formatTZID(int32_t offset, UnicodeString &rv) { 1075b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru rv.remove(); 1076b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UChar sign = 0x002B; 1077b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (offset < 0) { 1078b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru sign = 0x002D; 1079b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru offset = -offset; 1080b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1081b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1082b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t s = offset % 60; 1083b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru offset /= 60; 1084b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t m = offset % 60; 1085b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t h = offset / 60; 1086b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1087b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru rv += "GMT"; 1088b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru rv += (UChar)(sign); 1089b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (h >= 10) { 1090b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru rv += (UChar)(0x0030 + (h/10)); 1091b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } else { 1092b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru rv += (UChar)0x0030; 1093b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1094b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru rv += (UChar)(0x0030 + (h%10)); 1095b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru rv += (UChar)0x003A; 1096b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (m >= 10) { 1097b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru rv += (UChar)(0x0030 + (m/10)); 1098b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } else { 1099b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru rv += (UChar)0x0030; 1100b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1101b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru rv += (UChar)(0x0030 + (m%10)); 1102b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1103b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (s) { 1104b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru rv += (UChar)0x003A; 1105b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (s >= 10) { 1106b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru rv += (UChar)(0x0030 + (s/10)); 1107b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } else { 1108b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru rv += (UChar)0x0030; 1109b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1110b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru rv += (UChar)(0x0030 + (s%10)); 1111b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1112b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru return rv; 1113b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru} 1114b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1115b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/** 1116b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * As part of the VM fix (see CCC approved RFE 4028006, bug 1117b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * 4044013), TimeZone.getTimeZone() has been modified to recognize 1118b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * generic IDs of the form GMT[+-]hh:mm, GMT[+-]hhmm, and 1119b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * GMT[+-]hh. Test this behavior here. 1120b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * 1121b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * @bug 4044013 1122b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */ 1123b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queruvoid TimeZoneTest::TestCustomParse() 1124b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru{ 1125b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t i; 1126b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru const int32_t kUnparseable = 604800; // the number of seconds in a week. More than any offset should be. 1127b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1128b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru struct 1129b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru { 1130b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru const char *customId; 1131b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t expectedOffset; 1132b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1133b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru kData[] = 1134b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru { 1135b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru // ID Expected offset in seconds 1136b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"GMT", kUnparseable}, //Isn't custom. [returns normal GMT] 1137b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"GMT-YOUR.AD.HERE", kUnparseable}, 1138b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"GMT0", kUnparseable}, 1139b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"GMT+0", (0)}, 1140b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"GMT+1", (1*60*60)}, 1141b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"GMT-0030", (-30*60)}, 1142b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"GMT+15:99", kUnparseable}, 1143b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"GMT+", kUnparseable}, 1144b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"GMT-", kUnparseable}, 1145b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"GMT+0:", kUnparseable}, 1146b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"GMT-:", kUnparseable}, 1147b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"GMT-YOUR.AD.HERE", kUnparseable}, 1148b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"GMT+0010", (10*60)}, // Interpret this as 00:10 1149b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"GMT-10", (-10*60*60)}, 1150b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"GMT+30", kUnparseable}, 1151b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"GMT-3:30", (-(3*60+30)*60)}, 1152b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"GMT-230", (-(2*60+30)*60)}, 1153b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"GMT+05:13:05", ((5*60+13)*60+5)}, 1154b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"GMT-71023", (-((7*60+10)*60+23))}, 1155b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"GMT+01:23:45:67", kUnparseable}, 1156b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"GMT+01:234", kUnparseable}, 1157b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"GMT-2:31:123", kUnparseable}, 1158b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"GMT+3:75", kUnparseable}, 1159b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"GMT-01010101", kUnparseable}, 1160b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {0, 0} 1161b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru }; 1162b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1163b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru for (i=0; kData[i].customId != 0; i++) { 1164b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UnicodeString id(kData[i].customId); 1165b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t exp = kData[i].expectedOffset; 1166b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TimeZone *zone = TimeZone::createTimeZone(id); 1167b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UnicodeString itsID, temp; 1168b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 116927f654740f2a26ad62a5c155af9199af9e69b889claireho if (dynamic_cast<OlsonTimeZone *>(zone) != NULL) { 1170b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru logln(id + " -> Olson time zone"); 1171b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } else { 1172b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru zone->getID(itsID); 1173b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t ioffset = zone->getRawOffset()/1000; 1174b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UnicodeString offset, expectedID; 1175b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru formatOffset(ioffset, offset); 1176b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru formatTZID(ioffset, expectedID); 1177b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru logln(id + " -> " + itsID + " " + offset); 1178b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho if (exp == kUnparseable && itsID != UCAL_UNKNOWN_ZONE_ID) { 1179b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru errln("Expected parse failure for " + id + 1180b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru ", got offset of " + offset + 1181b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru ", id " + itsID); 1182b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1183b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru // JDK 1.3 creates custom zones with the ID "Custom" 1184b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru // JDK 1.4 creates custom zones with IDs of the form "GMT+02:00" 1185b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru // ICU creates custom zones with IDs of the form "GMT+02:00" 1186b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru else if (exp != kUnparseable && (ioffset != exp || itsID != expectedID)) { 11876d5deb12725f146643d443090dfa11b206df528aJean-Baptiste Queru dataerrln("Expected offset of " + formatOffset(exp, temp) + 1188b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru ", id " + expectedID + 1189b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru ", for " + id + 1190b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru ", got offset of " + offset + 1191b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru ", id " + itsID); 1192b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1193b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1194b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru delete zone; 1195b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1196b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru} 1197b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1198b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queruvoid 1199b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste QueruTimeZoneTest::TestAliasedNames() 1200b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru{ 1201b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru struct { 1202b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru const char *from; 1203b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru const char *to; 1204b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } kData[] = { 1205b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* Generated by org.unicode.cldr.tool.CountItems */ 1206b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1207b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* zoneID, canonical zoneID */ 1208b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"Africa/Timbuktu", "Africa/Bamako"}, 1209b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"America/Argentina/Buenos_Aires", "America/Buenos_Aires"}, 1210b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"America/Argentina/Catamarca", "America/Catamarca"}, 1211b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"America/Argentina/ComodRivadavia", "America/Catamarca"}, 1212b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"America/Argentina/Cordoba", "America/Cordoba"}, 1213b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"America/Argentina/Jujuy", "America/Jujuy"}, 1214b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"America/Argentina/Mendoza", "America/Mendoza"}, 1215b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"America/Atka", "America/Adak"}, 1216b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"America/Ensenada", "America/Tijuana"}, 1217b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"America/Fort_Wayne", "America/Indiana/Indianapolis"}, 1218b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"America/Indianapolis", "America/Indiana/Indianapolis"}, 1219b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"America/Knox_IN", "America/Indiana/Knox"}, 1220b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"America/Louisville", "America/Kentucky/Louisville"}, 1221b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"America/Porto_Acre", "America/Rio_Branco"}, 1222b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"America/Rosario", "America/Cordoba"}, 1223b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"America/Virgin", "America/St_Thomas"}, 1224b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"Asia/Ashkhabad", "Asia/Ashgabat"}, 1225b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"Asia/Chungking", "Asia/Chongqing"}, 1226b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"Asia/Dacca", "Asia/Dhaka"}, 1227b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"Asia/Istanbul", "Europe/Istanbul"}, 1228b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"Asia/Macao", "Asia/Macau"}, 1229b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"Asia/Tel_Aviv", "Asia/Jerusalem"}, 1230b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"Asia/Thimbu", "Asia/Thimphu"}, 1231b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"Asia/Ujung_Pandang", "Asia/Makassar"}, 1232b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"Asia/Ulan_Bator", "Asia/Ulaanbaatar"}, 1233b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"Australia/ACT", "Australia/Sydney"}, 1234b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"Australia/Canberra", "Australia/Sydney"}, 1235b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"Australia/LHI", "Australia/Lord_Howe"}, 1236b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"Australia/NSW", "Australia/Sydney"}, 1237b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"Australia/North", "Australia/Darwin"}, 1238b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"Australia/Queensland", "Australia/Brisbane"}, 1239b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"Australia/South", "Australia/Adelaide"}, 1240b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"Australia/Tasmania", "Australia/Hobart"}, 1241b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"Australia/Victoria", "Australia/Melbourne"}, 1242b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"Australia/West", "Australia/Perth"}, 1243b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"Australia/Yancowinna", "Australia/Broken_Hill"}, 1244b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"Brazil/Acre", "America/Rio_Branco"}, 1245b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"Brazil/DeNoronha", "America/Noronha"}, 1246b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"Brazil/East", "America/Sao_Paulo"}, 1247b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"Brazil/West", "America/Manaus"}, 1248b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"Canada/Atlantic", "America/Halifax"}, 1249b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"Canada/Central", "America/Winnipeg"}, 1250b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"Canada/East-Saskatchewan", "America/Regina"}, 1251b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"Canada/Eastern", "America/Toronto"}, 1252b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"Canada/Mountain", "America/Edmonton"}, 1253b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"Canada/Newfoundland", "America/St_Johns"}, 1254b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"Canada/Pacific", "America/Vancouver"}, 1255b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"Canada/Saskatchewan", "America/Regina"}, 1256b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"Canada/Yukon", "America/Whitehorse"}, 1257b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"Chile/Continental", "America/Santiago"}, 1258b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"Chile/EasterIsland", "Pacific/Easter"}, 1259b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"Cuba", "America/Havana"}, 1260b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"Egypt", "Africa/Cairo"}, 1261b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"Eire", "Europe/Dublin"}, 1262b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"Etc/GMT+0", "Etc/GMT"}, 1263b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"Etc/GMT-0", "Etc/GMT"}, 1264b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"Etc/GMT0", "Etc/GMT"}, 1265b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"Etc/Greenwich", "Etc/GMT"}, 1266b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"Etc/UCT", "Etc/GMT"}, 1267b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"Etc/UTC", "Etc/GMT"}, 1268b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"Etc/Universal", "Etc/GMT"}, 1269b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"Etc/Zulu", "Etc/GMT"}, 1270b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"Europe/Belfast", "Europe/London"}, 1271b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"Europe/Nicosia", "Asia/Nicosia"}, 1272b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"Europe/Tiraspol", "Europe/Chisinau"}, 1273b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"GB", "Europe/London"}, 1274b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"GB-Eire", "Europe/London"}, 1275b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"GMT", "Etc/GMT"}, 1276b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"GMT+0", "Etc/GMT"}, 1277b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"GMT-0", "Etc/GMT"}, 1278b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"GMT0", "Etc/GMT"}, 1279b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"Greenwich", "Etc/GMT"}, 1280b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"Hongkong", "Asia/Hong_Kong"}, 1281b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"Iceland", "Atlantic/Reykjavik"}, 1282b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"Iran", "Asia/Tehran"}, 1283b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"Israel", "Asia/Jerusalem"}, 1284b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"Jamaica", "America/Jamaica"}, 1285b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"Japan", "Asia/Tokyo"}, 1286b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"Kwajalein", "Pacific/Kwajalein"}, 1287b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"Libya", "Africa/Tripoli"}, 1288b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"Mexico/BajaNorte", "America/Tijuana"}, 1289b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"Mexico/BajaSur", "America/Mazatlan"}, 1290b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"Mexico/General", "America/Mexico_City"}, 1291b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"NZ", "Pacific/Auckland"}, 1292b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"NZ-CHAT", "Pacific/Chatham"}, 1293b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"Navajo", "America/Shiprock"}, 1294b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"PRC", "Asia/Shanghai"}, 1295b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"Pacific/Samoa", "Pacific/Pago_Pago"}, 1296b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"Pacific/Yap", "Pacific/Truk"}, 1297b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"Poland", "Europe/Warsaw"}, 1298b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"Portugal", "Europe/Lisbon"}, 1299b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"ROC", "Asia/Taipei"}, 1300b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"ROK", "Asia/Seoul"}, 1301b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"Singapore", "Asia/Singapore"}, 1302b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"Turkey", "Europe/Istanbul"}, 1303b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"UCT", "Etc/GMT"}, 1304b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"US/Alaska", "America/Anchorage"}, 1305b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"US/Aleutian", "America/Adak"}, 1306b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"US/Arizona", "America/Phoenix"}, 1307b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"US/Central", "America/Chicago"}, 1308b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"US/East-Indiana", "America/Indiana/Indianapolis"}, 1309b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"US/Eastern", "America/New_York"}, 1310b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"US/Hawaii", "Pacific/Honolulu"}, 1311b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"US/Indiana-Starke", "America/Indiana/Knox"}, 1312b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"US/Michigan", "America/Detroit"}, 1313b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"US/Mountain", "America/Denver"}, 1314b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"US/Pacific", "America/Los_Angeles"}, 1315b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"US/Pacific-New", "America/Los_Angeles"}, 1316b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"US/Samoa", "Pacific/Pago_Pago"}, 1317b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"UTC", "Etc/GMT"}, 1318b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"Universal", "Etc/GMT"}, 1319b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"W-SU", "Europe/Moscow"}, 1320b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"Zulu", "Etc/GMT"}, 1321b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru /* Total: 113 */ 1322b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1323b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru }; 1324b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1325b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TimeZone::EDisplayType styles[] = { TimeZone::SHORT, TimeZone::LONG }; 1326b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UBool useDst[] = { FALSE, TRUE }; 1327b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t noLoc = uloc_countAvailable(); 1328b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1329b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t i, j, k, loc; 1330b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UnicodeString fromName, toName; 1331b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TimeZone *from = NULL, *to = NULL; 1332b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru for(i = 0; i < (int32_t)(sizeof(kData)/sizeof(kData[0])); i++) { 1333b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru from = TimeZone::createTimeZone(kData[i].from); 1334b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru to = TimeZone::createTimeZone(kData[i].to); 1335b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(!from->hasSameRules(*to)) { 1336b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru errln("different at %i\n", i); 1337b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1338b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(!quick) { 1339b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru for(loc = 0; loc < noLoc; loc++) { 1340b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru const char* locale = uloc_getAvailable(loc); 1341b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru for(j = 0; j < (int32_t)(sizeof(styles)/sizeof(styles[0])); j++) { 1342b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru for(k = 0; k < (int32_t)(sizeof(useDst)/sizeof(useDst[0])); k++) { 1343b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru fromName.remove(); 1344b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru toName.remove(); 1345b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru from->getDisplayName(useDst[k], styles[j],locale, fromName); 1346b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru to->getDisplayName(useDst[k], styles[j], locale, toName); 1347b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(fromName.compare(toName) != 0) { 1348b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru errln("Fail: Expected "+toName+" but got " + prettify(fromName) 1349b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru + " for locale: " + locale + " index: "+ loc 1350b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru + " to id "+ kData[i].to 1351b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru + " from id " + kData[i].from); 1352b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1353b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1354b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1355b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1356b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } else { 1357b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru fromName.remove(); 1358b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru toName.remove(); 1359b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru from->getDisplayName(fromName); 1360b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru to->getDisplayName(toName); 1361b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(fromName.compare(toName) != 0) { 1362b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru errln("Fail: Expected "+toName+" but got " + fromName); 1363b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1364b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1365b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru delete from; 1366b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru delete to; 1367b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1368b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru} 1369b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1370b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/** 1371b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * Test the basic functionality of the getDisplayName() API. 1372b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * 1373b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * @bug 4112869 1374b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * @bug 4028006 1375b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * 1376b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * See also API change request A41. 1377b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * 1378b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * 4/21/98 - make smarter, so the test works if the ext resources 1379b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * are present or not. 1380b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */ 1381b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queruvoid 1382b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste QueruTimeZoneTest::TestDisplayName() 1383b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru{ 1384b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UErrorCode status = U_ZERO_ERROR; 1385b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t i; 1386b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TimeZone *zone = TimeZone::createTimeZone("PST"); 1387b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UnicodeString name; 1388b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru zone->getDisplayName(Locale::getEnglish(), name); 1389b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru logln("PST->" + name); 1390b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (name.compare("Pacific Standard Time") != 0) 13916d5deb12725f146643d443090dfa11b206df528aJean-Baptiste Queru dataerrln("Fail: Expected \"Pacific Standard Time\" but got " + name); 1392b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1393b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru //***************************************************************** 1394b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru // THE FOLLOWING LINES MUST BE UPDATED IF THE LOCALE DATA CHANGES 1395b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru // THE FOLLOWING LINES MUST BE UPDATED IF THE LOCALE DATA CHANGES 1396b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru // THE FOLLOWING LINES MUST BE UPDATED IF THE LOCALE DATA CHANGES 1397b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru //***************************************************************** 1398b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru struct 1399b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru { 1400b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UBool useDst; 1401b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TimeZone::EDisplayType style; 1402b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru const char *expect; 1403b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } kData[] = { 1404b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {FALSE, TimeZone::SHORT, "PST"}, 1405b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {TRUE, TimeZone::SHORT, "PDT"}, 1406b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {FALSE, TimeZone::LONG, "Pacific Standard Time"}, 1407b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {TRUE, TimeZone::LONG, "Pacific Daylight Time"}, 1408b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 140950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho {FALSE, TimeZone::SHORT_GENERIC, "PT"}, 141050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho {TRUE, TimeZone::SHORT_GENERIC, "PT"}, 141150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho {FALSE, TimeZone::LONG_GENERIC, "Pacific Time"}, 141250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho {TRUE, TimeZone::LONG_GENERIC, "Pacific Time"}, 141350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 141450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho {FALSE, TimeZone::SHORT_GMT, "-0800"}, 141550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho {TRUE, TimeZone::SHORT_GMT, "-0700"}, 141650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho {FALSE, TimeZone::LONG_GMT, "GMT-08:00"}, 141750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho {TRUE, TimeZone::LONG_GMT, "GMT-07:00"}, 141850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 141950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho {FALSE, TimeZone::SHORT_COMMONLY_USED, "PST"}, 142050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho {TRUE, TimeZone::SHORT_COMMONLY_USED, "PDT"}, 142154dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius {FALSE, TimeZone::GENERIC_LOCATION, "Los Angeles Time"}, 142254dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius {TRUE, TimeZone::GENERIC_LOCATION, "Los Angeles Time"}, 142350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 1424b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {FALSE, TimeZone::LONG, ""} 1425b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru }; 1426b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1427b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru for (i=0; kData[i].expect[0] != '\0'; i++) 1428b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru { 1429b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru name.remove(); 1430b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru name = zone->getDisplayName(kData[i].useDst, 1431b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru kData[i].style, 1432b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru Locale::getEnglish(), name); 1433b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (name.compare(kData[i].expect) != 0) 14346d5deb12725f146643d443090dfa11b206df528aJean-Baptiste Queru dataerrln("Fail: Expected " + UnicodeString(kData[i].expect) + "; got " + name); 1435b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru logln("PST [with options]->" + name); 1436b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1437b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru for (i=0; kData[i].expect[0] != '\0'; i++) 1438b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru { 1439b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru name.remove(); 1440b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru name = zone->getDisplayName(kData[i].useDst, 1441b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru kData[i].style, name); 1442b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (name.compare(kData[i].expect) != 0) 14436d5deb12725f146643d443090dfa11b206df528aJean-Baptiste Queru dataerrln("Fail: Expected " + UnicodeString(kData[i].expect) + "; got " + name); 1444b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru logln("PST [with options]->" + name); 1445b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1446b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1447b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1448b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru // Make sure that we don't display the DST name by constructing a fake 1449b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru // PST zone that has DST all year long. 1450b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru SimpleTimeZone *zone2 = new SimpleTimeZone(0, "PST"); 1451b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1452b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru zone2->setStartRule(UCAL_JANUARY, 1, 0, 0, status); 1453b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru zone2->setEndRule(UCAL_DECEMBER, 31, 0, 0, status); 1454b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1455b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UnicodeString inDaylight; 1456b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (zone2->inDaylightTime(UDate(0), status)) { 1457b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru inDaylight = UnicodeString("TRUE"); 1458b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } else { 1459b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru inDaylight = UnicodeString("FALSE"); 1460b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1461b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru logln(UnicodeString("Modified PST inDaylightTime->") + inDaylight ); 1462b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(U_FAILURE(status)) 1463b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru { 146450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho dataerrln("Some sort of error..." + UnicodeString(u_errorName(status))); // REVISIT 1465b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1466b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru name.remove(); 1467b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru name = zone2->getDisplayName(Locale::getEnglish(),name); 1468b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru logln("Modified PST->" + name); 1469b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (name.compare("Pacific Standard Time") != 0) 14706d5deb12725f146643d443090dfa11b206df528aJean-Baptiste Queru dataerrln("Fail: Expected \"Pacific Standard Time\""); 1471b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1472b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru // Make sure we get the default display format for Locales 1473b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru // with no display name data. 1474b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru Locale mt_MT("mt_MT"); 1475b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru name.remove(); 1476b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru name = zone->getDisplayName(mt_MT,name); 1477b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru //***************************************************************** 1478b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru // THE FOLLOWING LINE MUST BE UPDATED IF THE LOCALE DATA CHANGES 1479b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru // THE FOLLOWING LINE MUST BE UPDATED IF THE LOCALE DATA CHANGES 1480b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru // THE FOLLOWING LINE MUST BE UPDATED IF THE LOCALE DATA CHANGES 1481b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru //***************************************************************** 1482b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru logln("PST(mt_MT)->" + name); 1483b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1484b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru // *** REVISIT SRL how in the world do I check this? looks java specific. 1485b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru // Now be smart -- check to see if zh resource is even present. 1486b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru // If not, we expect the en fallback behavior. 1487b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru ResourceBundle enRB(NULL, 1488b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru Locale::getEnglish(), status); 1489b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(U_FAILURE(status)) 149050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho dataerrln("Couldn't get ResourceBundle for en - %s", u_errorName(status)); 1491b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1492b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru ResourceBundle mtRB(NULL, 1493b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru mt_MT, status); 1494b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru //if(U_FAILURE(status)) 1495b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru // errln("Couldn't get ResourceBundle for mt_MT"); 1496b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1497b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UBool noZH = U_FAILURE(status); 1498b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1499b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (noZH) { 1500b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru logln("Warning: Not testing the mt_MT behavior because resource is absent"); 1501b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (name != "Pacific Standard Time") 15026d5deb12725f146643d443090dfa11b206df528aJean-Baptiste Queru dataerrln("Fail: Expected Pacific Standard Time"); 1503b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1504b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1505b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1506b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (name.compare("GMT-08:00") && 1507b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru name.compare("GMT-8:00") && 1508b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru name.compare("GMT-0800") && 1509b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru name.compare("GMT-800")) { 15106d5deb12725f146643d443090dfa11b206df528aJean-Baptiste Queru dataerrln(UnicodeString("Fail: Expected GMT-08:00 or something similar for PST in mt_MT but got ") + name ); 15116d5deb12725f146643d443090dfa11b206df528aJean-Baptiste Queru dataerrln("************************************************************"); 15126d5deb12725f146643d443090dfa11b206df528aJean-Baptiste Queru dataerrln("THE ABOVE FAILURE MAY JUST MEAN THE LOCALE DATA HAS CHANGED"); 15136d5deb12725f146643d443090dfa11b206df528aJean-Baptiste Queru dataerrln("************************************************************"); 1514b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1515b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1516b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru // Now try a non-existent zone 1517b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru delete zone2; 1518b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru zone2 = new SimpleTimeZone(90*60*1000, "xyzzy"); 1519b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru name.remove(); 1520b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru name = zone2->getDisplayName(Locale::getEnglish(),name); 1521b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru logln("GMT+90min->" + name); 1522b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (name.compare("GMT+01:30") && 1523b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru name.compare("GMT+1:30") && 1524b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru name.compare("GMT+0130") && 1525b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru name.compare("GMT+130")) 15266d5deb12725f146643d443090dfa11b206df528aJean-Baptiste Queru dataerrln("Fail: Expected GMT+01:30 or something similar"); 1527b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru name.truncate(0); 1528b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru zone2->getDisplayName(name); 1529b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru logln("GMT+90min->" + name); 1530b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (name.compare("GMT+01:30") && 1531b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru name.compare("GMT+1:30") && 1532b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru name.compare("GMT+0130") && 1533b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru name.compare("GMT+130")) 15346d5deb12725f146643d443090dfa11b206df528aJean-Baptiste Queru dataerrln("Fail: Expected GMT+01:30 or something similar"); 1535b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru // clean up 1536b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru delete zone; 1537b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru delete zone2; 1538b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru} 1539b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1540b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/** 1541b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * @bug 4107276 1542b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */ 1543b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queruvoid 1544b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste QueruTimeZoneTest::TestDSTSavings() 1545b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru{ 1546b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UErrorCode status = U_ZERO_ERROR; 1547b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru // It might be better to find a way to integrate this test into the main TimeZone 1548b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru // tests above, but I don't have time to figure out how to do this (or if it's 1549b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru // even really a good idea). Let's consider that a future. --rtg 1/27/98 1550b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru SimpleTimeZone *tz = new SimpleTimeZone(-5 * U_MILLIS_PER_HOUR, "dstSavingsTest", 1551b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UCAL_MARCH, 1, 0, 0, UCAL_SEPTEMBER, 1, 0, 0, 1552b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru (int32_t)(0.5 * U_MILLIS_PER_HOUR), status); 1553b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(U_FAILURE(status)) 1554b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru errln("couldn't create TimeZone"); 1555b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1556b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (tz->getRawOffset() != -5 * U_MILLIS_PER_HOUR) 1557b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru errln(UnicodeString("Got back a raw offset of ") + (tz->getRawOffset() / U_MILLIS_PER_HOUR) + 1558b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru " hours instead of -5 hours."); 1559b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (!tz->useDaylightTime()) 1560b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru errln("Test time zone should use DST but claims it doesn't."); 1561b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (tz->getDSTSavings() != 0.5 * U_MILLIS_PER_HOUR) 1562b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru errln(UnicodeString("Set DST offset to 0.5 hour, but got back ") + (tz->getDSTSavings() / 1563b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru U_MILLIS_PER_HOUR) + " hours instead."); 1564b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1565b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t offset = tz->getOffset(GregorianCalendar::AD, 1998, UCAL_JANUARY, 1, 1566b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UCAL_THURSDAY, 10 * U_MILLIS_PER_HOUR,status); 1567b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (offset != -5 * U_MILLIS_PER_HOUR) 1568b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru errln(UnicodeString("The offset for 10 AM, 1/1/98 should have been -5 hours, but we got ") 1569b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru + (offset / U_MILLIS_PER_HOUR) + " hours."); 1570b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1571b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru offset = tz->getOffset(GregorianCalendar::AD, 1998, UCAL_JUNE, 1, UCAL_MONDAY, 1572b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 10 * U_MILLIS_PER_HOUR,status); 1573b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (offset != -4.5 * U_MILLIS_PER_HOUR) 1574b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru errln(UnicodeString("The offset for 10 AM, 6/1/98 should have been -4.5 hours, but we got ") 1575b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru + (offset / U_MILLIS_PER_HOUR) + " hours."); 1576b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1577b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru tz->setDSTSavings(U_MILLIS_PER_HOUR, status); 1578b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru offset = tz->getOffset(GregorianCalendar::AD, 1998, UCAL_JANUARY, 1, 1579b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UCAL_THURSDAY, 10 * U_MILLIS_PER_HOUR,status); 1580b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (offset != -5 * U_MILLIS_PER_HOUR) 1581b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru errln(UnicodeString("The offset for 10 AM, 1/1/98 should have been -5 hours, but we got ") 1582b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru + (offset / U_MILLIS_PER_HOUR) + " hours."); 1583b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1584b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru offset = tz->getOffset(GregorianCalendar::AD, 1998, UCAL_JUNE, 1, UCAL_MONDAY, 1585b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 10 * U_MILLIS_PER_HOUR,status); 1586b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (offset != -4 * U_MILLIS_PER_HOUR) 1587b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru errln(UnicodeString("The offset for 10 AM, 6/1/98 (with a 1-hour DST offset) should have been -4 hours, but we got ") 1588b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru + (offset / U_MILLIS_PER_HOUR) + " hours."); 1589b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1590b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru delete tz; 1591b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru} 1592b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1593b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/** 1594b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * @bug 4107570 1595b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */ 1596b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queruvoid 1597b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste QueruTimeZoneTest::TestAlternateRules() 1598b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru{ 1599b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru // Like TestDSTSavings, this test should probably be integrated somehow with the main 1600b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru // test at the top of this class, but I didn't have time to figure out how to do that. 1601b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru // --rtg 1/28/98 1602b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1603b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru SimpleTimeZone tz(-5 * U_MILLIS_PER_HOUR, "alternateRuleTest"); 1604b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1605b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru // test the day-of-month API 1606b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UErrorCode status = U_ZERO_ERROR; 1607b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru tz.setStartRule(UCAL_MARCH, 10, 12 * U_MILLIS_PER_HOUR, status); 1608b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(U_FAILURE(status)) 1609b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru errln("tz.setStartRule failed"); 1610b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru tz.setEndRule(UCAL_OCTOBER, 20, 12 * U_MILLIS_PER_HOUR, status); 1611b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(U_FAILURE(status)) 1612b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru errln("tz.setStartRule failed"); 1613b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1614b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t offset = tz.getOffset(GregorianCalendar::AD, 1998, UCAL_MARCH, 5, 1615b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UCAL_THURSDAY, 10 * U_MILLIS_PER_HOUR,status); 1616b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (offset != -5 * U_MILLIS_PER_HOUR) 1617b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru errln(UnicodeString("The offset for 10AM, 3/5/98 should have been -5 hours, but we got ") 1618b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru + (offset / U_MILLIS_PER_HOUR) + " hours."); 1619b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1620b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru offset = tz.getOffset(GregorianCalendar::AD, 1998, UCAL_MARCH, 15, 1621b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UCAL_SUNDAY, 10 * millisPerHour,status); 1622b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (offset != -4 * U_MILLIS_PER_HOUR) 1623b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru errln(UnicodeString("The offset for 10AM, 3/15/98 should have been -4 hours, but we got ") 1624b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru + (offset / U_MILLIS_PER_HOUR) + " hours."); 1625b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1626b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru offset = tz.getOffset(GregorianCalendar::AD, 1998, UCAL_OCTOBER, 15, 1627b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UCAL_THURSDAY, 10 * millisPerHour,status); 1628b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (offset != -4 * U_MILLIS_PER_HOUR) 1629b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru errln(UnicodeString("The offset for 10AM, 10/15/98 should have been -4 hours, but we got ") + (offset / U_MILLIS_PER_HOUR) + " hours."); 1630b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1631b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru offset = tz.getOffset(GregorianCalendar::AD, 1998, UCAL_OCTOBER, 25, 1632b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UCAL_SUNDAY, 10 * millisPerHour,status); 1633b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (offset != -5 * U_MILLIS_PER_HOUR) 1634b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru errln(UnicodeString("The offset for 10AM, 10/25/98 should have been -5 hours, but we got ") 1635b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru + (offset / U_MILLIS_PER_HOUR) + " hours."); 1636b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1637b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru // test the day-of-week-after-day-in-month API 1638b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru tz.setStartRule(UCAL_MARCH, 10, UCAL_FRIDAY, 12 * millisPerHour, TRUE, status); 1639b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(U_FAILURE(status)) 1640b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru errln("tz.setStartRule failed"); 1641b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru tz.setEndRule(UCAL_OCTOBER, 20, UCAL_FRIDAY, 12 * millisPerHour, FALSE, status); 1642b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(U_FAILURE(status)) 1643b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru errln("tz.setStartRule failed"); 1644b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1645b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru offset = tz.getOffset(GregorianCalendar::AD, 1998, UCAL_MARCH, 11, 1646b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UCAL_WEDNESDAY, 10 * millisPerHour,status); 1647b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (offset != -5 * U_MILLIS_PER_HOUR) 1648b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru errln(UnicodeString("The offset for 10AM, 3/11/98 should have been -5 hours, but we got ") 1649b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru + (offset / U_MILLIS_PER_HOUR) + " hours."); 1650b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1651b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru offset = tz.getOffset(GregorianCalendar::AD, 1998, UCAL_MARCH, 14, 1652b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UCAL_SATURDAY, 10 * millisPerHour,status); 1653b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (offset != -4 * U_MILLIS_PER_HOUR) 1654b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru errln(UnicodeString("The offset for 10AM, 3/14/98 should have been -4 hours, but we got ") 1655b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru + (offset / U_MILLIS_PER_HOUR) + " hours."); 1656b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1657b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru offset = tz.getOffset(GregorianCalendar::AD, 1998, UCAL_OCTOBER, 15, 1658b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UCAL_THURSDAY, 10 * millisPerHour,status); 1659b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (offset != -4 * U_MILLIS_PER_HOUR) 1660b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru errln(UnicodeString("The offset for 10AM, 10/15/98 should have been -4 hours, but we got ") 1661b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru + (offset / U_MILLIS_PER_HOUR) + " hours."); 1662b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1663b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru offset = tz.getOffset(GregorianCalendar::AD, 1998, UCAL_OCTOBER, 17, 1664b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UCAL_SATURDAY, 10 * millisPerHour,status); 1665b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (offset != -5 * U_MILLIS_PER_HOUR) 1666b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru errln(UnicodeString("The offset for 10AM, 10/17/98 should have been -5 hours, but we got ") 1667b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru + (offset / U_MILLIS_PER_HOUR) + " hours."); 1668b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru} 1669b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1670b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queruvoid TimeZoneTest::TestFractionalDST() { 1671b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru const char* tzName = "Australia/Lord_Howe"; // 30 min offset 1672b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TimeZone* tz_icu = TimeZone::createTimeZone(tzName); 1673b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int dst_icu = tz_icu->getDSTSavings(); 1674b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UnicodeString id; 1675b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t expected = 1800000; 1676b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (expected != dst_icu) { 16776d5deb12725f146643d443090dfa11b206df528aJean-Baptiste Queru dataerrln(UnicodeString("java reports dst savings of ") + expected + 1678b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru " but icu reports " + dst_icu + 1679b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru " for tz " + tz_icu->getID(id)); 1680b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } else { 1681b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru logln(UnicodeString("both java and icu report dst savings of ") + expected + " for tz " + tz_icu->getID(id)); 1682b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1683b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru delete tz_icu; 1684b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru} 1685b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1686b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/** 1687b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * Test country code support. Jitterbug 776. 1688b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */ 1689b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queruvoid TimeZoneTest::TestCountries() { 1690b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru // Make sure America/Los_Angeles is in the "US" group, and 1691b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru // Asia/Tokyo isn't. Vice versa for the "JP" group. 1692b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UErrorCode ec = U_ZERO_ERROR; 1693b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t n; 1694b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru StringEnumeration* s = TimeZone::createEnumeration("US"); 1695b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho if (s == NULL) { 1696b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho dataerrln("Unable to create TimeZone enumeration for US"); 1697b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho return; 1698b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho } 1699b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru n = s->count(ec); 1700b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UBool la = FALSE, tokyo = FALSE; 1701b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UnicodeString laZone("America/Los_Angeles", ""); 1702b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UnicodeString tokyoZone("Asia/Tokyo", ""); 1703b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t i; 1704b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1705b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (s == NULL || n <= 0) { 17066d5deb12725f146643d443090dfa11b206df528aJean-Baptiste Queru dataerrln("FAIL: TimeZone::createEnumeration() returned nothing"); 1707b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru return; 1708b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1709b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru for (i=0; i<n; ++i) { 1710b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru const UnicodeString* id = s->snext(ec); 1711b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (*id == (laZone)) { 1712b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru la = TRUE; 1713b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1714b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (*id == (tokyoZone)) { 1715b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru tokyo = TRUE; 1716b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1717b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1718b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (!la || tokyo) { 1719b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru errln("FAIL: " + laZone + " in US = " + la); 1720b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru errln("FAIL: " + tokyoZone + " in US = " + tokyo); 1721b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1722b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru delete s; 1723b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1724b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru s = TimeZone::createEnumeration("JP"); 1725b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru n = s->count(ec); 1726b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru la = FALSE; tokyo = FALSE; 1727b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1728b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru for (i=0; i<n; ++i) { 1729b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru const UnicodeString* id = s->snext(ec); 1730b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (*id == (laZone)) { 1731b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru la = TRUE; 1732b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1733b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (*id == (tokyoZone)) { 1734b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru tokyo = TRUE; 1735b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1736b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1737b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (la || !tokyo) { 1738b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru errln("FAIL: " + laZone + " in JP = " + la); 1739b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru errln("FAIL: " + tokyoZone + " in JP = " + tokyo); 1740b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1741b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru StringEnumeration* s1 = TimeZone::createEnumeration("US"); 1742b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru StringEnumeration* s2 = TimeZone::createEnumeration("US"); 1743b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru for(i=0;i<n;++i){ 1744b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru const UnicodeString* id1 = s1->snext(ec); 1745b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(id1==NULL || U_FAILURE(ec)){ 1746b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru errln("Failed to fetch next from TimeZone enumeration. Length returned : %i Current Index: %i", n,i); 1747b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1748b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TimeZone* tz1 = TimeZone::createTimeZone(*id1); 1749b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru for(int j=0; j<n;++j){ 1750b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru const UnicodeString* id2 = s2->snext(ec); 1751b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(id2==NULL || U_FAILURE(ec)){ 1752b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru errln("Failed to fetch next from TimeZone enumeration. Length returned : %i Current Index: %i", n,i); 1753b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1754b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TimeZone* tz2 = TimeZone::createTimeZone(*id2); 1755b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if(tz1->hasSameRules(*tz2)){ 1756b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru logln("ID1 : " + *id1+" == ID2 : " +*id2); 1757b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1758b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru delete tz2; 1759b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1760b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru delete tz1; 1761b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1762b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru delete s1; 1763b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru delete s2; 1764b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru delete s; 1765b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru} 1766b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1767b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queruvoid TimeZoneTest::TestHistorical() { 1768b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru const int32_t H = U_MILLIS_PER_HOUR; 1769b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru struct { 1770b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru const char* id; 1771b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t time; // epoch seconds 1772b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t offset; // total offset (millis) 1773b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } DATA[] = { 1774b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru // Add transition points (before/after) as desired to test historical 1775b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru // behavior. 1776b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"America/Los_Angeles", 638963999, -8*H}, // Sun Apr 01 01:59:59 GMT-08:00 1990 1777b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"America/Los_Angeles", 638964000, -7*H}, // Sun Apr 01 03:00:00 GMT-07:00 1990 1778b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"America/Los_Angeles", 657104399, -7*H}, // Sun Oct 28 01:59:59 GMT-07:00 1990 1779b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"America/Los_Angeles", 657104400, -8*H}, // Sun Oct 28 01:00:00 GMT-08:00 1990 1780b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"America/Goose_Bay", -116445601, -4*H}, // Sun Apr 24 01:59:59 GMT-04:00 1966 1781b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"America/Goose_Bay", -116445600, -3*H}, // Sun Apr 24 03:00:00 GMT-03:00 1966 1782b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"America/Goose_Bay", -100119601, -3*H}, // Sun Oct 30 01:59:59 GMT-03:00 1966 1783b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"America/Goose_Bay", -100119600, -4*H}, // Sun Oct 30 01:00:00 GMT-04:00 1966 1784b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"America/Goose_Bay", -84391201, -4*H}, // Sun Apr 30 01:59:59 GMT-04:00 1967 1785b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"America/Goose_Bay", -84391200, -3*H}, // Sun Apr 30 03:00:00 GMT-03:00 1967 1786b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"America/Goose_Bay", -68670001, -3*H}, // Sun Oct 29 01:59:59 GMT-03:00 1967 1787b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {"America/Goose_Bay", -68670000, -4*H}, // Sun Oct 29 01:00:00 GMT-04:00 1967 1788b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru {0, 0, 0} 1789b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru }; 1790b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1791b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru for (int32_t i=0; DATA[i].id!=0; ++i) { 1792b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru const char* id = DATA[i].id; 1793b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TimeZone *tz = TimeZone::createTimeZone(id); 1794b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UnicodeString s; 1795b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (tz == 0) { 1796b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru errln("FAIL: Cannot create %s", id); 1797b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } else if (tz->getID(s) != UnicodeString(id)) { 17986d5deb12725f146643d443090dfa11b206df528aJean-Baptiste Queru dataerrln((UnicodeString)"FAIL: createTimeZone(" + id + ") => " + s); 1799b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } else { 1800b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UErrorCode ec = U_ZERO_ERROR; 1801b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t raw, dst; 1802b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UDate when = (double) DATA[i].time * U_MILLIS_PER_SECOND; 1803b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru tz->getOffset(when, FALSE, raw, dst, ec); 1804b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (U_FAILURE(ec)) { 1805b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru errln("FAIL: getOffset"); 1806b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } else if ((raw+dst) != DATA[i].offset) { 1807b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru errln((UnicodeString)"FAIL: " + DATA[i].id + ".getOffset(" + 1808b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru //when + " = " + 1809b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru dateToString(when) + ") => " + 1810b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru raw + ", " + dst); 1811b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } else { 1812b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru logln((UnicodeString)"Ok: " + DATA[i].id + ".getOffset(" + 1813b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru //when + " = " + 1814b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru dateToString(when) + ") => " + 1815b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru raw + ", " + dst); 1816b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1817b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1818b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru delete tz; 1819b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1820b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru} 1821b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1822b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queruvoid TimeZoneTest::TestEquivalentIDs() { 1823b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t n = TimeZone::countEquivalentIDs("PST"); 1824b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (n < 2) { 18256d5deb12725f146643d443090dfa11b206df528aJean-Baptiste Queru dataerrln((UnicodeString)"FAIL: countEquivalentIDs(PST) = " + n); 1826b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } else { 1827b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UBool sawLA = FALSE; 1828b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru for (int32_t i=0; i<n; ++i) { 1829b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UnicodeString id = TimeZone::getEquivalentID("PST", i); 1830b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru logln((UnicodeString)"" + i + " : " + id); 1831b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (id == UnicodeString("America/Los_Angeles")) { 1832b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru sawLA = TRUE; 1833b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1834b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1835b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (!sawLA) { 1836b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru errln("FAIL: America/Los_Angeles should be in the list"); 1837b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1838b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1839b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru} 1840b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1841b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru// Test that a transition at the end of February is handled correctly. 1842b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queruvoid TimeZoneTest::TestFebruary() { 1843b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UErrorCode status = U_ZERO_ERROR; 1844b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1845b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru // Time zone with daylight savings time from the first Sunday in November 1846b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru // to the last Sunday in February. 1847b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru // Similar to the new rule for Brazil (Sao Paulo) in tzdata2006n. 1848b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru // 1849b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru // Note: In tzdata2007h, the rule had changed, so no actual zones uses 1850b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru // lastSun in Feb anymore. 1851b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru SimpleTimeZone tz1(-3 * U_MILLIS_PER_HOUR, // raw offset: 3h before (west of) GMT 1852b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UNICODE_STRING("nov-feb", 7), 1853b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UCAL_NOVEMBER, 1, UCAL_SUNDAY, // start: November, first, Sunday 1854b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0, // midnight wall time 1855b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UCAL_FEBRUARY, -1, UCAL_SUNDAY, // end: February, last, Sunday 1856b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0, // midnight wall time 1857b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru status); 1858b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (U_FAILURE(status)) { 1859b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru errln("Unable to create the SimpleTimeZone(nov-feb): %s", u_errorName(status)); 1860b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru return; 1861b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1862b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1863b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru // Now hardcode the same rules as for Brazil in tzdata 2006n, so that 1864b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru // we cover the intended code even when in the future zoneinfo hardcodes 1865b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru // these transition dates. 1866b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru SimpleTimeZone tz2(-3 * U_MILLIS_PER_HOUR, // raw offset: 3h before (west of) GMT 1867b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UNICODE_STRING("nov-feb2", 8), 1868b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UCAL_NOVEMBER, 1, -UCAL_SUNDAY, // start: November, 1 or after, Sunday 1869b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0, // midnight wall time 1870b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UCAL_FEBRUARY, -29, -UCAL_SUNDAY,// end: February, 29 or before, Sunday 1871b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 0, // midnight wall time 1872b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru status); 1873b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (U_FAILURE(status)) { 1874b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru errln("Unable to create the SimpleTimeZone(nov-feb2): %s", u_errorName(status)); 1875b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru return; 1876b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1877b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1878b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru // Gregorian calendar with the UTC time zone for getting sample test date/times. 1879b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru GregorianCalendar gc(*TimeZone::getGMT(), status); 1880b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (U_FAILURE(status)) { 188150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho dataerrln("Unable to create the UTC calendar: %s", u_errorName(status)); 1882b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru return; 1883b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1884b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1885b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru struct { 1886b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru // UTC time. 1887b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t year, month, day, hour, minute, second; 1888b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru // Expected time zone offset in hours after GMT (negative=before GMT). 1889b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t offsetHours; 1890b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } data[] = { 1891b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru { 2006, UCAL_NOVEMBER, 5, 02, 59, 59, -3 }, 1892b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru { 2006, UCAL_NOVEMBER, 5, 03, 00, 00, -2 }, 1893b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru { 2007, UCAL_FEBRUARY, 25, 01, 59, 59, -2 }, 1894b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru { 2007, UCAL_FEBRUARY, 25, 02, 00, 00, -3 }, 1895b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1896b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru { 2007, UCAL_NOVEMBER, 4, 02, 59, 59, -3 }, 1897b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru { 2007, UCAL_NOVEMBER, 4, 03, 00, 00, -2 }, 1898b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru { 2008, UCAL_FEBRUARY, 24, 01, 59, 59, -2 }, 1899b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru { 2008, UCAL_FEBRUARY, 24, 02, 00, 00, -3 }, 1900b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1901b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru { 2008, UCAL_NOVEMBER, 2, 02, 59, 59, -3 }, 1902b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru { 2008, UCAL_NOVEMBER, 2, 03, 00, 00, -2 }, 1903b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru { 2009, UCAL_FEBRUARY, 22, 01, 59, 59, -2 }, 1904b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru { 2009, UCAL_FEBRUARY, 22, 02, 00, 00, -3 }, 1905b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1906b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru { 2009, UCAL_NOVEMBER, 1, 02, 59, 59, -3 }, 1907b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru { 2009, UCAL_NOVEMBER, 1, 03, 00, 00, -2 }, 1908b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru { 2010, UCAL_FEBRUARY, 28, 01, 59, 59, -2 }, 1909b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru { 2010, UCAL_FEBRUARY, 28, 02, 00, 00, -3 } 1910b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru }; 1911b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1912b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TimeZone *timezones[] = { &tz1, &tz2 }; 1913b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 1914b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru TimeZone *tz; 1915b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru UDate dt; 1916b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru int32_t t, i, raw, dst; 1917b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru for (t = 0; t < LENGTHOF(timezones); ++t) { 1918b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru tz = timezones[t]; 1919b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru for (i = 0; i < LENGTHOF(data); ++i) { 1920b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru gc.set(data[i].year, data[i].month, data[i].day, 1921b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru data[i].hour, data[i].minute, data[i].second); 1922b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru dt = gc.getTime(status); 1923b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (U_FAILURE(status)) { 1924b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru errln("test case %d.%d: bad date/time %04d-%02d-%02d %02d:%02d:%02d", 1925b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru t, i, 1926b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru data[i].year, data[i].month + 1, data[i].day, 1927b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru data[i].hour, data[i].minute, data[i].second); 1928b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru status = U_ZERO_ERROR; 1929b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru continue; 1930b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1931b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru tz->getOffset(dt, FALSE, raw, dst, status); 1932b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru if (U_FAILURE(status)) { 1933b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru errln("test case %d.%d: tz.getOffset(%04d-%02d-%02d %02d:%02d:%02d) fails: %s", 1934b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru t, i, 1935b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru data[i].year, data[i].month + 1, data[i].day, 1936b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru data[i].hour, data[i].minute, data[i].second, 1937b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru u_errorName(status)); 1938b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru status = U_ZERO_ERROR; 1939b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } else if ((raw + dst) != data[i].offsetHours * U_MILLIS_PER_HOUR) { 1940b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru errln("test case %d.%d: tz.getOffset(%04d-%02d-%02d %02d:%02d:%02d) returns %d+%d != %d", 1941b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru t, i, 1942b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru data[i].year, data[i].month + 1, data[i].day, 1943b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru data[i].hour, data[i].minute, data[i].second, 1944b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru raw, dst, data[i].offsetHours * U_MILLIS_PER_HOUR); 1945b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1946b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1947b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru } 1948b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru} 1949c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queruvoid TimeZoneTest::TestCanonicalID() { 1950c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru 1951c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru // Some canonical IDs in CLDR are defined as "Link" 1952c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru // in Olson tzdata. 1953c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru static const struct { 1954c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru const char *alias; 1955c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru const char *zone; 1956c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru } excluded1[] = { 1957c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru {"America/Shiprock", "America/Denver"}, // America/Shiprock is defined as a Link to America/Denver in tzdata 1958c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru {"America/Marigot", "America/Guadeloupe"}, 1959c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru {"America/St_Barthelemy", "America/Guadeloupe"}, 1960103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius {"America/Lower_Princes", "America/Curacao"}, 1961103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius {"America/Kralendijk", "America/Curacao"}, 1962c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru {"Antarctica/South_Pole", "Antarctica/McMurdo"}, 1963c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru {"Atlantic/Jan_Mayen", "Europe/Oslo"}, 1964c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru {"Arctic/Longyearbyen", "Europe/Oslo"}, 19658393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius {"Europe/Busingen", "Europe/Zurich"}, 1966c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru {"Europe/Guernsey", "Europe/London"}, 1967c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru {"Europe/Isle_of_Man", "Europe/London"}, 1968c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru {"Europe/Jersey", "Europe/London"}, 1969c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru {"Europe/Ljubljana", "Europe/Belgrade"}, 1970c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru {"Europe/Podgorica", "Europe/Belgrade"}, 1971c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru {"Europe/Sarajevo", "Europe/Belgrade"}, 1972c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru {"Europe/Skopje", "Europe/Belgrade"}, 1973c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru {"Europe/Zagreb", "Europe/Belgrade"}, 1974c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru {"Europe/Bratislava", "Europe/Prague"}, 1975c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru {"Europe/Mariehamn", "Europe/Helsinki"}, 1976c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru {"Europe/San_Marino", "Europe/Rome"}, 1977c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru {"Europe/Vatican", "Europe/Rome"}, 1978c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru {0, 0} 1979c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru }; 1980c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru 1981c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru // Following IDs are aliases of Etc/GMT in CLDR, 1982c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru // but Olson tzdata has 3 independent definitions 1983c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru // for Etc/GMT, Etc/UTC, Etc/UCT. 1984c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru // Until we merge them into one equivalent group 1985c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru // in zoneinfo.res, we exclude them in the test 1986c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru // below. 1987c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru static const char* excluded2[] = { 1988c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru "Etc/UCT", "UCT", 1989c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru "Etc/UTC", "UTC", 1990c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru "Etc/Universal", "Universal", 1991c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru "Etc/Zulu", "Zulu", 0 1992c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru }; 1993c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru 1994c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru // Walk through equivalency groups 1995c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru UErrorCode ec = U_ZERO_ERROR; 1996c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru int32_t s_length, i, j, k; 1997c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru StringEnumeration* s = TimeZone::createEnumeration(); 1998b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho if (s == NULL) { 1999b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho dataerrln("Unable to create TimeZone enumeration"); 2000b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho return; 2001b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho } 2002c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru UnicodeString canonicalID, tmpCanonical; 2003c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru s_length = s->count(ec); 2004c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru for (i = 0; i < s_length;++i) { 2005c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru const UnicodeString *tzid = s->snext(ec); 2006c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru int32_t nEquiv = TimeZone::countEquivalentIDs(*tzid); 2007c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru if (nEquiv == 0) { 2008c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru continue; 2009c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru } 2010c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru UBool bFoundCanonical = FALSE; 2011c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru // Make sure getCanonicalID returns the exact same result 2012c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru // for all entries within a same equivalency group with some 2013c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru // exceptions listed in exluded1. 2014c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru // Also, one of them must be canonical id. 2015c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru for (j = 0; j < nEquiv; j++) { 2016c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru UnicodeString tmp = TimeZone::getEquivalentID(*tzid, j); 2017c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TimeZone::getCanonicalID(tmp, tmpCanonical, ec); 2018c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru if (U_FAILURE(ec)) { 2019c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru errln((UnicodeString)"FAIL: getCanonicalID(" + tmp + ") failed."); 2020c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru ec = U_ZERO_ERROR; 2021c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru continue; 2022c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru } 2023c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru // Some exceptional cases 2024c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru for (k = 0; excluded1[k].alias != 0; k++) { 2025c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru if (tmpCanonical == excluded1[k].alias) { 2026c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru tmpCanonical = excluded1[k].zone; 2027c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru break; 2028c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru } 2029c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru } 2030c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru if (j == 0) { 2031c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru canonicalID = tmpCanonical; 2032c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru } else if (canonicalID != tmpCanonical) { 2033c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru errln("FAIL: getCanonicalID(" + tmp + ") returned " + tmpCanonical + " expected:" + canonicalID); 2034c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru } 2035c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru 2036c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru if (canonicalID == tmp) { 2037c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru bFoundCanonical = TRUE; 2038c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru } 2039c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru } 2040c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru // At least one ID in an equvalency group must match the 2041c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru // canonicalID 2042c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru if (bFoundCanonical == FALSE) { 2043c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru // test exclusion because of differences between Olson tzdata and CLDR 2044c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru UBool isExcluded = FALSE; 2045c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru for (k = 0; excluded2[k] != 0; k++) { 2046c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru if (*tzid == UnicodeString(excluded2[k])) { 2047c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru isExcluded = TRUE; 2048c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru break; 2049c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru } 2050c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru } 2051c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru if (isExcluded) { 2052c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru continue; 2053c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru } 2054c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru errln((UnicodeString)"FAIL: No timezone ids match the canonical ID " + canonicalID); 2055c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru } 2056c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru } 2057c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru delete s; 2058c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru 2059c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru // Testing some special cases 2060c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru static const struct { 2061c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru const char *id; 2062c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru const char *expected; 2063c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru UBool isSystem; 2064c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru } data[] = { 2065b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru {"GMT-03", "GMT-03:00", FALSE}, 2066b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru {"GMT+4", "GMT+04:00", FALSE}, 2067b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru {"GMT-055", "GMT-00:55", FALSE}, 2068b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru {"GMT+430", "GMT+04:30", FALSE}, 2069b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru {"GMT-12:15", "GMT-12:15", FALSE}, 2070b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru {"GMT-091015", "GMT-09:10:15", FALSE}, 2071c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru {"GMT+1:90", 0, FALSE}, 2072c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru {"America/Argentina/Buenos_Aires", "America/Buenos_Aires", TRUE}, 2073b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho {"Etc/Unknown", "Etc/Unknown", FALSE}, 2074c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru {"bogus", 0, FALSE}, 2075c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru {"", 0, FALSE}, 2076103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius {"America/Marigot", "America/Marigot", TRUE}, // Olson link, but CLDR canonical (#8953) 2077103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius {"Europe/Bratislava", "Europe/Bratislava", TRUE}, // Same as above 2078c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru {0, 0, FALSE} 2079c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru }; 2080c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru 2081c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru UBool isSystemID; 2082c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru for (i = 0; data[i].id != 0; i++) { 2083c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TimeZone::getCanonicalID(UnicodeString(data[i].id), canonicalID, isSystemID, ec); 2084c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru if (U_FAILURE(ec)) { 2085c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru if (ec != U_ILLEGAL_ARGUMENT_ERROR || data[i].expected != 0) { 2086c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru errln((UnicodeString)"FAIL: getCanonicalID(\"" + data[i].id 2087c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru + "\") returned status U_ILLEGAL_ARGUMENT_ERROR"); 2088c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru } 2089c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru ec = U_ZERO_ERROR; 2090c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru continue; 2091c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru } 2092c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru if (canonicalID != data[i].expected) { 20936d5deb12725f146643d443090dfa11b206df528aJean-Baptiste Queru dataerrln((UnicodeString)"FAIL: getCanonicalID(\"" + data[i].id 2094c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru + "\") returned " + canonicalID + " - expected: " + data[i].expected); 2095c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru } 2096c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru if (isSystemID != data[i].isSystem) { 20976d5deb12725f146643d443090dfa11b206df528aJean-Baptiste Queru dataerrln((UnicodeString)"FAIL: getCanonicalID(\"" + data[i].id 2098c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru + "\") set " + isSystemID + " to isSystemID"); 2099c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru } 2100c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru } 2101c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru} 2102c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru 2103c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru// 2104c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru// Test Display Names, choosing zones and lcoales where there are multiple 2105c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru// meta-zones defined. 2106c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru// 2107c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Querustatic struct { 2108c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru const char *zoneName; 2109c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru const char *localeName; 2110c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru UBool summerTime; 2111c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TimeZone::EDisplayType style; 2112c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru const char *expectedDisplayName; } 2113c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru zoneDisplayTestData [] = { 2114c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru // zone id locale summer format expected display name 2115c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru {"Europe/London", "en", FALSE, TimeZone::SHORT, "GMT"}, 2116c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru {"Europe/London", "en", FALSE, TimeZone::LONG, "Greenwich Mean Time"}, 21178393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius {"Europe/London", "en", TRUE, TimeZone::SHORT, "GMT+1" /*"BST"*/}, 2118c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru {"Europe/London", "en", TRUE, TimeZone::LONG, "British Summer Time"}, 2119c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru 2120c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru {"America/Anchorage", "en", FALSE, TimeZone::SHORT, "AKST"}, 2121c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru {"America/Anchorage", "en", FALSE, TimeZone::LONG, "Alaska Standard Time"}, 2122c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru {"America/Anchorage", "en", TRUE, TimeZone::SHORT, "AKDT"}, 2123c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru {"America/Anchorage", "en", TRUE, TimeZone::LONG, "Alaska Daylight Time"}, 2124c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru 2125c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru // Southern Hemisphere, all data from meta:Australia_Western 21268393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius {"Australia/Perth", "en", FALSE, TimeZone::SHORT, "GMT+8"/*"AWST"*/}, 2127c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru {"Australia/Perth", "en", FALSE, TimeZone::LONG, "Australian Western Standard Time"}, 212854dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius // Note: Perth does not observe DST currently. When display name is missing, 212954dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius // the localized GMT format with the current offset is used even daylight name was 213054dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius // requested. See #9350. 21318393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius {"Australia/Perth", "en", TRUE, TimeZone::SHORT, "GMT+8"/*"AWDT"*/}, 2132c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru {"Australia/Perth", "en", TRUE, TimeZone::LONG, "Australian Western Daylight Time"}, 2133c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru 21348393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius {"America/Sao_Paulo", "en", FALSE, TimeZone::SHORT, "GMT-3"/*"BRT"*/}, 213554dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius {"America/Sao_Paulo", "en", FALSE, TimeZone::LONG, "Brasilia Standard Time"}, 21368393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius {"America/Sao_Paulo", "en", TRUE, TimeZone::SHORT, "GMT-2"/*"BRST"*/}, 2137c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru {"America/Sao_Paulo", "en", TRUE, TimeZone::LONG, "Brasilia Summer Time"}, 2138c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru 2139c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru // No Summer Time, but had it before 1983. 2140c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru {"Pacific/Honolulu", "en", FALSE, TimeZone::SHORT, "HST"}, 2141c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru {"Pacific/Honolulu", "en", FALSE, TimeZone::LONG, "Hawaii-Aleutian Standard Time"}, 214254dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius {"Pacific/Honolulu", "en", TRUE, TimeZone::SHORT, "HDT"}, 214354dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius {"Pacific/Honolulu", "en", TRUE, TimeZone::LONG, "Hawaii-Aleutian Daylight Time"}, 2144c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru 2145c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru // Northern, has Summer, not commonly used. 21468393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius {"Europe/Helsinki", "en", FALSE, TimeZone::SHORT, "GMT+2"/*"EET"*/}, 214754dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius {"Europe/Helsinki", "en", FALSE, TimeZone::LONG, "Eastern European Standard Time"}, 21488393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius {"Europe/Helsinki", "en", TRUE, TimeZone::SHORT, "GMT+3"/*"EEST"*/}, 214954dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius {"Europe/Helsinki", "en", TRUE, TimeZone::LONG, "Eastern European Summer Time"}, 215054dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius 215154dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius // Repeating the test data for DST. The test data below trigger the problem reported 215254dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius // by Ticket#6644 21538393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius {"Europe/London", "en", TRUE, TimeZone::SHORT, "GMT+1" /*"BST"*/}, 215454dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius {"Europe/London", "en", TRUE, TimeZone::LONG, "British Summer Time"}, 215554dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius 2156c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru {NULL, NULL, FALSE, TimeZone::SHORT, NULL} // NULL values terminate list 2157c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru }; 2158c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru 2159c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queruvoid TimeZoneTest::TestDisplayNamesMeta() { 2160b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru UErrorCode status = U_ZERO_ERROR; 2161b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru GregorianCalendar cal(*TimeZone::getGMT(), status); 216250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho if (failure(status, "GregorianCalendar", TRUE)) return; 2163b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru 2164c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru UBool sawAnError = FALSE; 2165c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru for (int testNum = 0; zoneDisplayTestData[testNum].zoneName != NULL; testNum++) { 2166c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru Locale locale = Locale::createFromName(zoneDisplayTestData[testNum].localeName); 2167c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru TimeZone *zone = TimeZone::createTimeZone(zoneDisplayTestData[testNum].zoneName); 2168c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru UnicodeString displayName; 2169c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru zone->getDisplayName(zoneDisplayTestData[testNum].summerTime, 2170c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru zoneDisplayTestData[testNum].style, 2171c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru locale, 2172c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru displayName); 2173c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru if (displayName != zoneDisplayTestData[testNum].expectedDisplayName) { 2174c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru char name[100]; 2175c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru UErrorCode status = U_ZERO_ERROR; 2176c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru displayName.extract(name, 100, NULL, status); 217754dcd9b6a06071f647dac967e9e267abb9410720Craig Cornelius if (isDevelopmentBuild) { 2178b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru sawAnError = TRUE; 21796d5deb12725f146643d443090dfa11b206df528aJean-Baptiste Queru dataerrln("Incorrect time zone display name. zone = \"%s\",\n" 2180b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru " locale = \"%s\", style = %s, Summertime = %d\n" 2181b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru " Expected \"%s\", " 21826d5deb12725f146643d443090dfa11b206df528aJean-Baptiste Queru " Got \"%s\"\n Error: %s", zoneDisplayTestData[testNum].zoneName, 2183b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru zoneDisplayTestData[testNum].localeName, 2184b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru zoneDisplayTestData[testNum].style==TimeZone::SHORT ? 2185b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru "SHORT" : "LONG", 2186b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru zoneDisplayTestData[testNum].summerTime, 2187b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru zoneDisplayTestData[testNum].expectedDisplayName, 21886d5deb12725f146643d443090dfa11b206df528aJean-Baptiste Queru name, 21896d5deb12725f146643d443090dfa11b206df528aJean-Baptiste Queru u_errorName(status)); 2190b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } else { 2191b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru logln("Incorrect time zone display name. zone = \"%s\",\n" 2192b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru " locale = \"%s\", style = %s, Summertime = %d\n" 2193b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru " Expected \"%s\", " 2194b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru " Got \"%s\"\n", zoneDisplayTestData[testNum].zoneName, 2195b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru zoneDisplayTestData[testNum].localeName, 2196b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru zoneDisplayTestData[testNum].style==TimeZone::SHORT ? 2197b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru "SHORT" : "LONG", 2198b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru zoneDisplayTestData[testNum].summerTime, 2199b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru zoneDisplayTestData[testNum].expectedDisplayName, 2200b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru name); 2201b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru } 2202c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru } 2203c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru delete zone; 2204c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru } 2205c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru if (sawAnError) { 22066d5deb12725f146643d443090dfa11b206df528aJean-Baptiste Queru dataerrln("***Note: Errors could be the result of changes to zoneStrings locale data"); 2207c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru } 2208c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru} 2209b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 2210b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2clairehovoid TimeZoneTest::TestGetRegion() 2211b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho{ 2212b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho static const struct { 2213b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho const char *id; 2214b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho const char *region; 2215b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho } data[] = { 2216b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho {"America/Los_Angeles", "US"}, 2217b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho {"America/Indianapolis", "US"}, // CLDR canonical, Olson backward 2218b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho {"America/Indiana/Indianapolis", "US"}, // CLDR alias 2219b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho {"Mexico/General", "MX"}, // Link America/Mexico_City, Olson backward 2220b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho {"Etc/UTC", "001"}, 2221b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho {"EST5EDT", "001"}, 2222b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho {"PST", "US"}, // Link America/Los_Angeles 2223b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho {"Europe/Helsinki", "FI"}, 2224b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho {"Europe/Mariehamn", "AX"}, // Link Europe/Helsinki, but in zone.tab 2225b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho {"Asia/Riyadh", "SA"}, 2226b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho {"Asia/Riyadh87", "001"}, // this should be "SA" actually, but not in zone.tab 2227b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho {"Etc/Unknown", 0}, // CLDR canonical, but not a sysmte zone ID 2228b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho {"bogus", 0}, // bogus 2229b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho {"GMT+08:00", 0}, // a custom ID, not a system zone ID 2230b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho {0, 0} 2231b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho }; 2232b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho 2233b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho int32_t i; 2234b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho char region[4]; 2235b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho UErrorCode sts; 2236b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho for (i = 0; data[i].id; i++) { 2237b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho sts = U_ZERO_ERROR; 2238b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho TimeZone::getRegion(data[i].id, region, sizeof(region), sts); 2239b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho if (U_SUCCESS(sts)) { 2240b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho if (data[i].region == 0) { 2241b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho errln((UnicodeString)"Fail: getRegion(\"" + data[i].id + "\") returns " 2242b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho + region + " [expected: U_ILLEGAL_ARGUMENT_ERROR]"); 2243b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho } else if (uprv_strcmp(region, data[i].region) != 0) { 2244b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho errln((UnicodeString)"Fail: getRegion(\"" + data[i].id + "\") returns " 2245b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho + region + " [expected: " + data[i].region + "]"); 2246b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho } 2247b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho } else if (sts == U_ILLEGAL_ARGUMENT_ERROR) { 2248b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho if (data[i].region != 0) { 2249b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho dataerrln((UnicodeString)"Fail: getRegion(\"" + data[i].id 2250b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho + "\") returns error status U_ILLEGAL_ARGUMENT_ERROR [expected: " 2251b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho + data[i].region + "]"); 2252b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho } 2253b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho } else { 2254b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho errln((UnicodeString)"Fail: getRegion(\"" + data[i].id 2255b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho + "\") returns an unexpected error status"); 2256b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho } 2257b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho } 2258b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho 2259b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho // Extra test cases for short buffer 2260b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho int32_t len; 2261b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho char region2[2]; 2262b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho sts = U_ZERO_ERROR; 2263b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho 2264b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho len = TimeZone::getRegion("America/New_York", region2, sizeof(region2), sts); 2265b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho if (sts == U_ILLEGAL_ARGUMENT_ERROR) { 2266b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho dataerrln("Error calling TimeZone::getRegion"); 2267b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho } else { 2268b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho if (sts != U_STRING_NOT_TERMINATED_WARNING) { 2269b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho errln("Expected U_STRING_NOT_TERMINATED_WARNING"); 2270b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho } 2271b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho if (len != 2) { // length of "US" 2272b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho errln("Incorrect result length"); 2273b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho } 2274b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho if (uprv_strncmp(region2, "US", 2) != 0) { 2275b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho errln("Incorrect result"); 2276b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho } 2277b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho } 2278b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho 2279b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho char region1[1]; 2280b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho sts = U_ZERO_ERROR; 2281b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho 2282b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho len = TimeZone::getRegion("America/Chicago", region1, sizeof(region1), sts); 2283b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho if (sts == U_ILLEGAL_ARGUMENT_ERROR) { 2284b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho dataerrln("Error calling TimeZone::getRegion"); 2285b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho } else { 2286b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho if (sts != U_BUFFER_OVERFLOW_ERROR) { 2287b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho errln("Expected U_BUFFER_OVERFLOW_ERROR"); 2288b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho } 2289b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho if (len != 2) { // length of "US" 2290b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho errln("Incorrect result length"); 2291b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho } 2292b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho } 2293b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho} 2294103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius 2295103e9ffba2cba345d0078eb8b8db33249f81840aCraig Corneliusvoid TimeZoneTest::TestGetUnknown() { 2296103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius const TimeZone &unknown = TimeZone::getUnknown(); 2297103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius UnicodeString expectedID = UNICODE_STRING_SIMPLE("Etc/Unknown"); 2298103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius UnicodeString id; 2299103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius assertEquals("getUnknown() wrong ID", expectedID, unknown.getID(id)); 2300103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius assertTrue("getUnknown() wrong offset", 0 == unknown.getRawOffset()); 2301103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius assertFalse("getUnknown() uses DST", unknown.useDaylightTime()); 2302103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius} 2303103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius 2304b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#endif /* #if !UCONFIG_NO_FORMATTING */ 2305