From 50e9b8620ce0832e518a744f53c082e9e2aa1bde Mon Sep 17 00:00:00 2001 From: Neil Fuller Date: Thu, 13 Oct 2016 09:26:21 +0100 Subject: Update time_zones_by_country.xml / delete unused files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit preferred_time_zones.xml is not referenced in any code and has been deleted here. TimeUtilsTest.java is broken / out of date and semi-duplicates code in android.util.cts.TimeUtilsTest. It has been deleted here. time_zones_by_country.xml file has not been updated since (at least) 2009. Ideally this information would be updated as needed when the timezone rule data is updated on device. This change just brings the data up to date without addressing that issue. Given the apparent, non-obvious, ordering requirements it may not be possible to use zone1970.tab data directly. --------------- Impact assessment: At the time of writing time_zones_by_country.xml is used from: Non-public methods: android.util.TimeUtils.getTimeZones(String) Public methods: android.util.TimeUtils.getTimeZone(int, boolean, long, String) android.util.TimeUtils.getTimeZonesWithUniqueOffsets(String) Therefore there is some app / user benefit from updating it. Within the framework, this affects: telephony.ServiceStateTracker - in some circumstances when receiving offset information from cell networks when better information is not available. There is some clockwork code affected that uses the calls for similar purposes. --------------- Notes on file formats / mapping the IANA source data: The updated data was sourced from the IANA tzdata 2016g file called zone1970.tab. The time_zones_by_country.xml file was manually edited in a text editor using criteria detailed below. The zone1970.tab file maps country codes (column 1) to a zone ID (column 3). A country can be mapped to multiple zones. The zone.tab file that was likely used in the past is similar in content and format. See the zone.tab file header for details of the differences. The time_zones_by_country.xml can have multiple entries for each country, starting with a comment. Comments exist for each (Country, Offset) pair. The name is free-text, the offset is a non-DST offset for a zone as of 14th Oct 2016 using the 2016g data. Countries are listed in ASCII ascending order of the country code. Within each country offsets are mostly ordered east to west. An exception appears to be Australia. The data may have a secondary order of "best match" (e.g. maybe by population). This might be important for getTimeZone(int, boolean, long, String)) since it returns the first match for a given offset, dst, country. The timezone offset, transition information itself (offset, dst) is pulled from the timezone rules data on the device, not this file. The data is encoded for each (Country, Offset) pair by a sequence of: {Olson ID} xx is the country code from column 1 in the zone1970.tab file, the element content is the zone ID from column 3. --------------- Notes on the changes made to time_zones_by_country.xml: There are various changes in this commit associated with switching from zone.tab to zone1970.tab as a data source: zone.tab uses different Olson IDs due to the different criteria used by these files. The offset in each case will be the same so will have no practical effect on offsets / zone detection, though will affect the exemplar location for the zone found. The remaining changes reflect actual zone / offset changes that have occurred. When adding new zones or rearranging existing ones they have been positioned so as not to modify the first zone for each country or the first zone per offset because of the uncertainty about the secondary ordering. This is to avoid the risk of now picking a different zone for a country or {country + dst + offset}. This has resulted in a couple of places where the ordering is non-intuitive. The zone names and the offset information contained in the comments was checked semi-manually using other 2016g data, i.e. the base offset of each zone was checked against output from a script that created a TimeZone object from each Olson ID in the file and output the raw (non-DST) offset. --------------- Change specifics: Changes made due to zone1970.tab vs zone.tab: ANTIGUA AND BARBUDA ANGUILLA ANGOLA ALAND ISLANDS ARUBA BOSNIA AND HERZEGOVINA BURKINA FASO BAHRAIN BENIN BOTSWANA CONGO CENTRAL AFRICAN REPUBLIC CONGO CAMEROON DJIBOUTI DOMINICA ERITREA ETHIOPIA GABON GRENADA GUERNSEY GAMBIA GUINEA GUADELOUPE EQUATORIAL GUINEA CROATIA ISLE OF MAN JERSEY CAMBODIA COMOROS SAINT KITTS AND NEVIS KUWAIT CAYMAN ISLANDS LAO PEOPLE'S DEMOCRATIC REPUBLIC SAINT LUCIA LIECHTENSTEIN LESOTHO MONTENEGRO MADAGASCAR MACEDONIA MALI NORTHERN MARIANA ISLANDS MAURITANIA MONTSERRAT MALAWI NIGER OMAN RWANDA SAINT HELENA SLOVENIA SVALBARD AND JAN MAYEN SLOVAKIA SIERRA LEONE SAN MARINO SENEGAL SOMALIA SAO TOME AND PRINCIPE SWAZILAND TOGO TANZANIA UGANDA UNITED STATES MINOR OUTLYING ISLANDS HOLY SEE SAINT VINCENT AND THE GRENADINES VIRGIN ISLANDS YEMEN MAYOTTE ZAMBIA ZIMBABWE --------- Changes due to new data: ANTARCTICA ARGENTINA AUSTRALIA BRAZIL CANADA CHINA MICRONESIA INDIA MYANMAR MEXICO PAPUA NEW GUINEA PALESTINE RUSSIAN FEDERATION UNITED STATES UKRAINE --------- Removal of NETHERLANDS ANTILLES (country code "an"): "an" no longer present in the IANA data. The country code is no longer in use. https://en.wikipedia.org/wiki/ISO_3166-2:AN New country entries for: Saint Barthélemy Caribbean Netherlands Curaçao Collectivity of Saint Martin Sint Maarten --------- Changes due to new data *and* with differences between zone1970.tab and zone.tab: GERMANY South Sudan (entirely new) VIET NAM FRENCH SOUTHERN TERRITORIES --------- Changes to comments or arrangement of existing entries due to non-DST offset changes since the last update: Antarctica/Mawson Europe/Minsk America/Resolute Atlantic/Stanley Asia/Pyongyang America/Cancun America/Grand_Turk Pacific/Fakaofo Europe/Istanbul America/Caracas Pacific/Apia Bug: 25338903 Test: Build / CtsUtilTestCases Change-Id: I87e3db795f55ddd92e7402459c5e97aa70b9301e --- core/res/res/xml/preferred_time_zones.xml | 25 -- core/res/res/xml/time_zones_by_country.xml | 270 +++++++----- .../coretests/src/android/util/TimeUtilsTest.java | 457 --------------------- 3 files changed, 168 insertions(+), 584 deletions(-) delete mode 100644 core/res/res/xml/preferred_time_zones.xml delete mode 100644 core/tests/coretests/src/android/util/TimeUtilsTest.java diff --git a/core/res/res/xml/preferred_time_zones.xml b/core/res/res/xml/preferred_time_zones.xml deleted file mode 100644 index da8553fb01d1..000000000000 --- a/core/res/res/xml/preferred_time_zones.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - America/New_York - America/Chicago - America/Denver - America/Los_Angeles - diff --git a/core/res/res/xml/time_zones_by_country.xml b/core/res/res/xml/time_zones_by_country.xml index 9b2bd50401b9..a685e2b8a5e5 100644 --- a/core/res/res/xml/time_zones_by_country.xml +++ b/core/res/res/xml/time_zones_by_country.xml @@ -31,11 +31,11 @@ - America/Antigua + America/Port_of_Spain - America/Anguilla + America/Port_of_Spain @@ -45,18 +45,13 @@ Asia/Yerevan - - - America/Curacao - - Africa/Luanda + Africa/Lagos - Antarctica/McMurdo - Antarctica/South_Pole + Pacific/Auckland @@ -70,15 +65,22 @@ Antarctica/Davis - + Antarctica/Mawson + + + Antarctica/Vostok Antarctica/Syowa + + + Antarctica/Troll + Antarctica/Rothera @@ -91,12 +93,14 @@ America/Argentina/Buenos_Aires America/Argentina/Cordoba + America/Argentina/Salta America/Argentina/Jujuy America/Argentina/Tucuman America/Argentina/Catamarca America/Argentina/La_Rioja America/Argentina/San_Juan America/Argentina/Mendoza + America/Argentina/San_Luis America/Argentina/Rio_Gallegos America/Argentina/Ushuaia @@ -117,6 +121,9 @@ Australia/Currie Australia/Lindeman + + Antarctica/Macquarie + Australia/Lord_Howe @@ -137,11 +144,11 @@ - America/Aruba + America/Curacao - Europe/Mariehamn + Europe/Helsinki @@ -149,7 +156,7 @@ - Europe/Sarajevo + Europe/Belgrade @@ -165,7 +172,7 @@ - Africa/Ouagadougou + Africa/Abidjan @@ -173,15 +180,19 @@ - Asia/Bahrain + Asia/Qatar - Africa/Bujumbura + Africa/Maputo - Africa/Porto-Novo + Africa/Lagos + + + + America/Port_of_Spain @@ -195,6 +206,10 @@ America/La_Paz + + + America/Curacao + America/Noronha @@ -208,6 +223,7 @@ America/Araguaina America/Maceio America/Bahia + America/Santarem @@ -216,6 +232,9 @@ America/Cuiaba America/Porto_Velho America/Boa_Vista + + + America/Eirunepe America/Rio_Branco @@ -229,9 +248,9 @@ - Africa/Gaborone + Africa/Maputo - + Europe/Minsk @@ -254,12 +273,10 @@ America/Toronto - America/Montreal America/Nipigon America/Thunder_Bay America/Iqaluit America/Pangnirtung - America/Resolute America/Atikokan @@ -269,6 +286,7 @@ America/Rankin_Inlet America/Rainy_River America/Swift_Current + America/Resolute @@ -277,6 +295,8 @@ America/Yellowknife America/Inuvik America/Dawson_Creek + America/Creston + America/Fort_Nelson @@ -290,19 +310,19 @@ - Africa/Lubumbashi + Africa/Maputo - Africa/Kinshasa + Africa/Lagos - Africa/Bangui + Africa/Lagos - Africa/Brazzaville + Africa/Lagos @@ -326,15 +346,15 @@ - Africa/Douala + Africa/Lagos Asia/Shanghai - Asia/Harbin - Asia/Chongqing + + + Asia/Urumqi - Asia/Kashgar @@ -352,6 +372,10 @@ Atlantic/Cape_Verde + + + America/Curacao + Indian/Christmas @@ -367,10 +391,11 @@ Europe/Berlin + Europe/Zurich - Africa/Djibouti + Africa/Nairobi @@ -378,7 +403,7 @@ - America/Dominica + America/Port_of_Spain @@ -410,7 +435,7 @@ - Africa/Asmara + Africa/Nairobi @@ -423,7 +448,7 @@ - Africa/Addis_Ababa + Africa/Nairobi @@ -433,7 +458,7 @@ Pacific/Fiji - + Atlantic/Stanley @@ -444,7 +469,7 @@ - Pacific/Truk + Pacific/Chuuk @@ -456,7 +481,7 @@ - Africa/Libreville + Africa/Lagos @@ -464,7 +489,7 @@ - America/Grenada + America/Port_of_Spain @@ -476,7 +501,7 @@ - Europe/Guernsey + Europe/London @@ -504,19 +529,19 @@ - Africa/Banjul + Africa/Abidjan - Africa/Conakry + Africa/Abidjan - America/Guadeloupe + America/Port_of_Spain - Africa/Malabo + Africa/Lagos @@ -552,7 +577,7 @@ - Europe/Zagreb + Europe/Belgrade @@ -585,11 +610,11 @@ - Europe/Isle_of_Man + Europe/London - Asia/Calcutta + Asia/Kolkata @@ -613,7 +638,7 @@ - Europe/Jersey + Europe/London @@ -637,7 +662,7 @@ - Asia/Phnom_Penh + Asia/Bangkok @@ -653,13 +678,13 @@ - Indian/Comoro + Africa/Nairobi - America/St_Kitts + America/Port_of_Spain - + Asia/Pyongyang @@ -669,11 +694,11 @@ - Asia/Kuwait + Asia/Riyadh - America/Cayman + America/Panama @@ -688,7 +713,7 @@ - Asia/Vientiane + Asia/Bangkok @@ -696,11 +721,11 @@ - America/St_Lucia + America/Port_of_Spain - Europe/Vaduz + Europe/Zurich @@ -712,7 +737,7 @@ - Africa/Maseru + Africa/Johannesburg @@ -744,11 +769,15 @@ - Europe/Podgorica + Europe/Belgrade + + + + America/Port_of_Spain - Indian/Antananarivo + Africa/Nairobi @@ -757,15 +786,15 @@ - Europe/Skopje + Europe/Belgrade - Africa/Bamako + Africa/Abidjan - Asia/Rangoon + Asia/Yangon @@ -782,7 +811,7 @@ - Pacific/Saipan + Pacific/Guam @@ -790,11 +819,11 @@ - Africa/Nouakchott + Africa/Abidjan - America/Montserrat + America/Port_of_Spain @@ -810,20 +839,26 @@ - Africa/Blantyre + Africa/Maputo America/Mexico_City - America/Cancun America/Merida America/Monterrey + America/Matamoros + America/Bahia_Banderas + + + + America/Cancun America/Chihuahua America/Hermosillo America/Mazatlan + America/Ojinaga @@ -848,7 +883,7 @@ - Africa/Niamey + Africa/Lagos @@ -892,7 +927,7 @@ - Asia/Muscat + Asia/Dubai @@ -918,6 +953,10 @@ Pacific/Port_Moresby + + + Pacific/Bougainville + Asia/Manila @@ -945,6 +984,7 @@ Asia/Gaza + Asia/Hebron @@ -987,15 +1027,19 @@ Asia/Magadan + Asia/Sakhalin + Asia/Srednekolymsk Asia/Vladivostok - Asia/Sakhalin + Asia/Ust-Nera Asia/Yakutsk + Asia/Chita + Asia/Khandyga @@ -1004,10 +1048,13 @@ Asia/Krasnoyarsk + Asia/Novosibirsk + Asia/Barnaul + Asia/Novokuznetsk + Asia/Tomsk - Asia/Novosibirsk Asia/Omsk @@ -1017,11 +1064,15 @@ Europe/Samara + Europe/Astrakhan + Europe/Ulyanovsk Europe/Moscow Europe/Volgograd + Europe/Kirov + Europe/Simferopol @@ -1029,7 +1080,7 @@ - Africa/Kigali + Africa/Maputo @@ -1057,57 +1108,65 @@ - Atlantic/St_Helena + Africa/Abidjan - Europe/Ljubljana + Europe/Belgrade - Arctic/Longyearbyen + Europe/Oslo - Europe/Bratislava + Europe/Prague - Africa/Freetown + Africa/Abidjan - Europe/San_Marino + Europe/Rome - Africa/Dakar + Africa/Abidjan - Africa/Mogadishu + Africa/Nairobi America/Paramaribo + + + Africa/Khartoum + - Africa/Sao_Tome + Africa/Abidjan America/El_Salvador + + + America/Curacao + Asia/Damascus - Africa/Mbabane + Africa/Johannesburg - + America/Grand_Turk @@ -1119,9 +1178,13 @@ Indian/Kerguelen + + + Indian/Reunion + - Africa/Lome + Africa/Abidjan @@ -1131,7 +1194,7 @@ Asia/Dushanbe - + Pacific/Fakaofo @@ -1151,7 +1214,7 @@ Pacific/Tongatapu - + Europe/Istanbul @@ -1169,18 +1232,17 @@ - Africa/Dar_es_Salaam + Africa/Nairobi Europe/Kiev Europe/Uzhgorod Europe/Zaporozhye - Europe/Simferopol - Africa/Kampala + Africa/Nairobi @@ -1188,11 +1250,11 @@ - Pacific/Johnston + Pacific/Honolulu - Pacific/Midway + Pacific/Pago_Pago @@ -1214,12 +1276,13 @@ America/Menominee America/North_Dakota/Center America/North_Dakota/New_Salem + America/Indiana/Tell_City + America/North_Dakota/Beulah America/Denver America/Boise - America/Shiprock America/Phoenix @@ -1232,6 +1295,8 @@ America/Juneau America/Yakutat America/Nome + America/Metlakatla + America/Sitka @@ -1249,27 +1314,28 @@ - Europe/Vatican + Europe/Rome - America/St_Vincent + America/Port_of_Spain - + America/Caracas - America/Tortola + America/Port_of_Spain - America/St_Thomas + America/Port_of_Spain - Asia/Saigon + Asia/Ho_Chi_Minh + Asia/Bangkok @@ -1279,17 +1345,17 @@ Pacific/Wallis - + Pacific/Apia - Asia/Aden + Asia/Riyadh - Indian/Mayotte + Africa/Nairobi @@ -1297,9 +1363,9 @@ - Africa/Lusaka + Africa/Maputo - Africa/Harare + Africa/Maputo diff --git a/core/tests/coretests/src/android/util/TimeUtilsTest.java b/core/tests/coretests/src/android/util/TimeUtilsTest.java deleted file mode 100644 index 237062748f9f..000000000000 --- a/core/tests/coretests/src/android/util/TimeUtilsTest.java +++ /dev/null @@ -1,457 +0,0 @@ -/* - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package android.util; - -import junit.framework.TestCase; - -import java.util.Calendar; -import java.util.TimeZone; - -/** - * TimeUtilsTest tests the time zone guesser. - */ -public class TimeUtilsTest extends TestCase { - public void testMainstream() throws Exception { - String[] mainstream = new String[] { - "America/New_York", // Eastern - "America/Chicago", // Central - "America/Denver", // Mountain - "America/Los_Angeles", // Pacific - "America/Anchorage", // Alaska - "Pacific/Honolulu", // Hawaii, no DST - }; - - for (String name : mainstream) { - TimeZone tz = TimeZone.getTimeZone(name); - Calendar c = Calendar.getInstance(tz); - TimeZone guess; - - c.set(2008, Calendar.OCTOBER, 20, 12, 00, 00); - guess = guess(c, "us"); - assertEquals(name, guess.getID()); - - c.set(2009, Calendar.JANUARY, 20, 12, 00, 00); - guess = guess(c, "us"); - assertEquals(name, guess.getID()); - } - } - - public void testWeird() throws Exception { - String[] weird = new String[] { - "America/Phoenix", // Mountain, no DST - "America/Adak", // Same as Hawaii, but with DST - }; - - for (String name : weird) { - TimeZone tz = TimeZone.getTimeZone(name); - Calendar c = Calendar.getInstance(tz); - TimeZone guess; - - c.set(2008, Calendar.OCTOBER, 20, 12, 00, 00); - guess = guess(c, "us"); - assertEquals(name, guess.getID()); - } - } - - public void testOld() throws Exception { - String[] old = new String[] { - "America/Indiana/Indianapolis", // Eastern, formerly no DST - }; - - for (String name : old) { - TimeZone tz = TimeZone.getTimeZone(name); - Calendar c = Calendar.getInstance(tz); - TimeZone guess; - - c.set(2005, Calendar.OCTOBER, 20, 12, 00, 00); - guess = guess(c, "us"); - assertEquals(name, guess.getID()); - } - } - - public void testWorld() throws Exception { - String[] world = new String[] { - "ad", "Europe/Andorra", - "ae", "Asia/Dubai", - "af", "Asia/Kabul", - "ag", "America/Antigua", - "ai", "America/Anguilla", - "al", "Europe/Tirane", - "am", "Asia/Yerevan", - "an", "America/Curacao", - "ao", "Africa/Luanda", - "aq", "Antarctica/McMurdo", - "aq", "Antarctica/DumontDUrville", - "aq", "Antarctica/Casey", - "aq", "Antarctica/Davis", - "aq", "Antarctica/Mawson", - "aq", "Antarctica/Syowa", - "aq", "Antarctica/Rothera", - "aq", "Antarctica/Palmer", - "ar", "America/Argentina/Buenos_Aires", - "as", "Pacific/Pago_Pago", - "at", "Europe/Vienna", - "au", "Australia/Sydney", - "au", "Australia/Adelaide", - "au", "Australia/Perth", - "au", "Australia/Eucla", - "aw", "America/Aruba", - "ax", "Europe/Mariehamn", - "az", "Asia/Baku", - "ba", "Europe/Sarajevo", - "bb", "America/Barbados", - "bd", "Asia/Dhaka", - "be", "Europe/Brussels", - "bf", "Africa/Ouagadougou", - "bg", "Europe/Sofia", - "bh", "Asia/Bahrain", - "bi", "Africa/Bujumbura", - "bj", "Africa/Porto-Novo", - "bm", "Atlantic/Bermuda", - "bn", "Asia/Brunei", - "bo", "America/La_Paz", - "br", "America/Noronha", - "br", "America/Sao_Paulo", - "br", "America/Manaus", - "bs", "America/Nassau", - "bt", "Asia/Thimphu", - "bw", "Africa/Gaborone", - "by", "Europe/Minsk", - "bz", "America/Belize", - "ca", "America/St_Johns", - "ca", "America/Halifax", - "ca", "America/Toronto", - "ca", "America/Winnipeg", - "ca", "America/Edmonton", - "ca", "America/Vancouver", - "cc", "Indian/Cocos", - "cd", "Africa/Lubumbashi", - "cd", "Africa/Kinshasa", - "cf", "Africa/Bangui", - "cg", "Africa/Brazzaville", - "ch", "Europe/Zurich", - "ci", "Africa/Abidjan", - "ck", "Pacific/Rarotonga", - "cl", "America/Santiago", - "cl", "Pacific/Easter", - "cm", "Africa/Douala", - "cn", "Asia/Shanghai", - "co", "America/Bogota", - "cr", "America/Costa_Rica", - "cu", "America/Havana", - "cv", "Atlantic/Cape_Verde", - "cx", "Indian/Christmas", - "cy", "Asia/Nicosia", - "cz", "Europe/Prague", - "de", "Europe/Berlin", - "dj", "Africa/Djibouti", - "dk", "Europe/Copenhagen", - "dm", "America/Dominica", - "do", "America/Santo_Domingo", - "dz", "Africa/Algiers", - "ec", "America/Guayaquil", - "ec", "Pacific/Galapagos", - "ee", "Europe/Tallinn", - "eg", "Africa/Cairo", - "eh", "Africa/El_Aaiun", - "er", "Africa/Asmara", - "es", "Europe/Madrid", - "es", "Atlantic/Canary", - "et", "Africa/Addis_Ababa", - "fi", "Europe/Helsinki", - "fj", "Pacific/Fiji", - "fk", "Atlantic/Stanley", - "fm", "Pacific/Ponape", - "fm", "Pacific/Truk", - "fo", "Atlantic/Faroe", - "fr", "Europe/Paris", - "ga", "Africa/Libreville", - "gb", "Europe/London", - "gd", "America/Grenada", - "ge", "Asia/Tbilisi", - "gf", "America/Cayenne", - "gg", "Europe/Guernsey", - "gh", "Africa/Accra", - "gi", "Europe/Gibraltar", - "gl", "America/Danmarkshavn", - "gl", "America/Scoresbysund", - "gl", "America/Godthab", - "gl", "America/Thule", - "gm", "Africa/Banjul", - "gn", "Africa/Conakry", - "gp", "America/Guadeloupe", - "gq", "Africa/Malabo", - "gr", "Europe/Athens", - "gs", "Atlantic/South_Georgia", - "gt", "America/Guatemala", - "gu", "Pacific/Guam", - "gw", "Africa/Bissau", - "gy", "America/Guyana", - "hk", "Asia/Hong_Kong", - "hn", "America/Tegucigalpa", - "hr", "Europe/Zagreb", - "ht", "America/Port-au-Prince", - "hu", "Europe/Budapest", - "id", "Asia/Jayapura", - "id", "Asia/Makassar", - "id", "Asia/Jakarta", - "ie", "Europe/Dublin", - "il", "Asia/Jerusalem", - "im", "Europe/Isle_of_Man", - "in", "Asia/Calcutta", - "io", "Indian/Chagos", - "iq", "Asia/Baghdad", - "ir", "Asia/Tehran", - "is", "Atlantic/Reykjavik", - "it", "Europe/Rome", - "je", "Europe/Jersey", - "jm", "America/Jamaica", - "jo", "Asia/Amman", - "jp", "Asia/Tokyo", - "ke", "Africa/Nairobi", - "kg", "Asia/Bishkek", - "kh", "Asia/Phnom_Penh", - "ki", "Pacific/Kiritimati", - "ki", "Pacific/Enderbury", - "ki", "Pacific/Tarawa", - "km", "Indian/Comoro", - "kn", "America/St_Kitts", - "kp", "Asia/Pyongyang", - "kr", "Asia/Seoul", - "kw", "Asia/Kuwait", - "ky", "America/Cayman", - "kz", "Asia/Almaty", - "kz", "Asia/Aqtau", - "la", "Asia/Vientiane", - "lb", "Asia/Beirut", - "lc", "America/St_Lucia", - "li", "Europe/Vaduz", - "lk", "Asia/Colombo", - "lr", "Africa/Monrovia", - "ls", "Africa/Maseru", - "lt", "Europe/Vilnius", - "lu", "Europe/Luxembourg", - "lv", "Europe/Riga", - "ly", "Africa/Tripoli", - "ma", "Africa/Casablanca", - "mc", "Europe/Monaco", - "md", "Europe/Chisinau", - "me", "Europe/Podgorica", - "mg", "Indian/Antananarivo", - "mh", "Pacific/Majuro", - "mk", "Europe/Skopje", - "ml", "Africa/Bamako", - "mm", "Asia/Rangoon", - "mn", "Asia/Choibalsan", - "mn", "Asia/Hovd", - "mo", "Asia/Macau", - "mp", "Pacific/Saipan", - "mq", "America/Martinique", - "mr", "Africa/Nouakchott", - "ms", "America/Montserrat", - "mt", "Europe/Malta", - "mu", "Indian/Mauritius", - "mv", "Indian/Maldives", - "mw", "Africa/Blantyre", - "mx", "America/Mexico_City", - "mx", "America/Chihuahua", - "mx", "America/Tijuana", - "my", "Asia/Kuala_Lumpur", - "mz", "Africa/Maputo", - "na", "Africa/Windhoek", - "nc", "Pacific/Noumea", - "ne", "Africa/Niamey", - "nf", "Pacific/Norfolk", - "ng", "Africa/Lagos", - "ni", "America/Managua", - "nl", "Europe/Amsterdam", - "no", "Europe/Oslo", - "np", "Asia/Katmandu", - "nr", "Pacific/Nauru", - "nu", "Pacific/Niue", - "nz", "Pacific/Auckland", - "nz", "Pacific/Chatham", - "om", "Asia/Muscat", - "pa", "America/Panama", - "pe", "America/Lima", - "pf", "Pacific/Gambier", - "pf", "Pacific/Marquesas", - "pf", "Pacific/Tahiti", - "pg", "Pacific/Port_Moresby", - "ph", "Asia/Manila", - "pk", "Asia/Karachi", - "pl", "Europe/Warsaw", - "pm", "America/Miquelon", - "pn", "Pacific/Pitcairn", - "pr", "America/Puerto_Rico", - "ps", "Asia/Gaza", - "pt", "Europe/Lisbon", - "pt", "Atlantic/Azores", - "pw", "Pacific/Palau", - "py", "America/Asuncion", - "qa", "Asia/Qatar", - "re", "Indian/Reunion", - "ro", "Europe/Bucharest", - "rs", "Europe/Belgrade", - "ru", "Asia/Kamchatka", - "ru", "Asia/Magadan", - "ru", "Asia/Vladivostok", - "ru", "Asia/Yakutsk", - "ru", "Asia/Irkutsk", - "ru", "Asia/Krasnoyarsk", - "ru", "Asia/Novosibirsk", - "ru", "Asia/Yekaterinburg", - "ru", "Europe/Samara", - "ru", "Europe/Moscow", - "ru", "Europe/Kaliningrad", - "rw", "Africa/Kigali", - "sa", "Asia/Riyadh", - "sb", "Pacific/Guadalcanal", - "sc", "Indian/Mahe", - "sd", "Africa/Khartoum", - "se", "Europe/Stockholm", - "sg", "Asia/Singapore", - "sh", "Atlantic/St_Helena", - "si", "Europe/Ljubljana", - "sj", "Arctic/Longyearbyen", - "sk", "Europe/Bratislava", - "sl", "Africa/Freetown", - "sm", "Europe/San_Marino", - "sn", "Africa/Dakar", - "so", "Africa/Mogadishu", - "sr", "America/Paramaribo", - "st", "Africa/Sao_Tome", - "sv", "America/El_Salvador", - "sy", "Asia/Damascus", - "sz", "Africa/Mbabane", - "tc", "America/Grand_Turk", - "td", "Africa/Ndjamena", - "tf", "Indian/Kerguelen", - "tg", "Africa/Lome", - "th", "Asia/Bangkok", - "tj", "Asia/Dushanbe", - "tk", "Pacific/Fakaofo", - "tl", "Asia/Dili", - "tm", "Asia/Ashgabat", - "tn", "Africa/Tunis", - "to", "Pacific/Tongatapu", - "tr", "Europe/Istanbul", - "tt", "America/Port_of_Spain", - "tv", "Pacific/Funafuti", - "tw", "Asia/Taipei", - "tz", "Africa/Dar_es_Salaam", - "ua", "Europe/Kiev", - "ug", "Africa/Kampala", - "um", "Pacific/Wake", - "um", "Pacific/Johnston", - "um", "Pacific/Midway", - "us", "America/New_York", - "us", "America/Chicago", - "us", "America/Denver", - "us", "America/Los_Angeles", - "us", "America/Anchorage", - "us", "Pacific/Honolulu", - "uy", "America/Montevideo", - "uz", "Asia/Tashkent", - "va", "Europe/Vatican", - "vc", "America/St_Vincent", - "ve", "America/Caracas", - "vg", "America/Tortola", - "vi", "America/St_Thomas", - "vn", "Asia/Saigon", - "vu", "Pacific/Efate", - "wf", "Pacific/Wallis", - "ws", "Pacific/Apia", - "ye", "Asia/Aden", - "yt", "Indian/Mayotte", - "za", "Africa/Johannesburg", - "zm", "Africa/Lusaka", - "zw", "Africa/Harare", - }; - - for (int i = 0; i < world.length; i += 2) { - String country = world[i]; - String name = world[i + 1]; - - TimeZone tz = TimeZone.getTimeZone(name); - Calendar c = Calendar.getInstance(tz); - TimeZone guess; - - c.set(2009, Calendar.JULY, 20, 12, 00, 00); - guess = guess(c, country); - assertEquals(name, guess.getID()); - - c.set(2009, Calendar.JANUARY, 20, 12, 00, 00); - guess = guess(c, country); - assertEquals(name, guess.getID()); - } - } - - public void testWorldWeird() throws Exception { - String[] world = new String[] { - // Distinguisable from Sydney only when DST not in effect - "au", "Australia/Lord_Howe", - }; - - for (int i = 0; i < world.length; i += 2) { - String country = world[i]; - String name = world[i + 1]; - - TimeZone tz = TimeZone.getTimeZone(name); - Calendar c = Calendar.getInstance(tz); - TimeZone guess; - - c.set(2009, Calendar.JULY, 20, 12, 00, 00); - guess = guess(c, country); - assertEquals(name, guess.getID()); - } - } - - private static TimeZone guess(Calendar c, String country) { - return TimeUtils.getTimeZone(c.get(c.ZONE_OFFSET) + c.get(c.DST_OFFSET), - c.get(c.DST_OFFSET) != 0, - c.getTimeInMillis(), - country); - } - - public void testFormatDuration() { - assertFormatDuration("0", 0); - assertFormatDuration("-1ms", -1); - assertFormatDuration("+1ms", 1); - assertFormatDuration("+10ms", 10); - assertFormatDuration("+100ms", 100); - assertFormatDuration("+101ms", 101); - assertFormatDuration("+330ms", 330); - assertFormatDuration("+1s0ms", 1000); - assertFormatDuration("+1s330ms", 1330); - assertFormatDuration("+10s24ms", 10024); - assertFormatDuration("+1m0s30ms", 60030); - assertFormatDuration("+1h0m0s30ms", 3600030); - assertFormatDuration("+1d0h0m0s30ms", 86400030); - } - - public void testFormatHugeDuration() { - assertFormatDuration("+15542d1h11m11s555ms", 1342833071555L); - assertFormatDuration("-15542d1h11m11s555ms", -1342833071555L); - } - - private void assertFormatDuration(String expected, long duration) { - StringBuilder sb = new StringBuilder(); - TimeUtils.formatDuration(duration, sb); - assertEquals("formatDuration(" + duration + ")", expected, sb.toString()); - } -} -- cgit v1.2.3-59-g8ed1b