diff options
author | Andras Becsi <andras.becsi@digia.com> | 2014-03-18 13:16:26 +0100 |
---|---|---|
committer | Frederik Gladhorn <frederik.gladhorn@digia.com> | 2014-03-20 15:55:39 +0100 |
commit | 3f0f86b0caed75241fa71c95a5d73bc0164348c5 (patch) | |
tree | 92b9fb00f2e9e90b0be2262093876d4f43b6cd13 /chromium/base/i18n | |
parent | e90d7c4b152c56919d963987e2503f9909a666d2 (diff) | |
download | qtwebengine-chromium-3f0f86b0caed75241fa71c95a5d73bc0164348c5.tar.gz |
Update to new stable branch 1750
This also includes an updated ninja and chromium dependencies
needed on Windows.
Change-Id: Icd597d80ed3fa4425933c9f1334c3c2e31291c42
Reviewed-by: Zoltan Arvai <zarvai@inf.u-szeged.hu>
Reviewed-by: Zeno Albisser <zeno.albisser@digia.com>
Diffstat (limited to 'chromium/base/i18n')
-rw-r--r-- | chromium/base/i18n/break_iterator.h | 6 | ||||
-rw-r--r-- | chromium/base/i18n/case_conversion_unittest.cc | 2 | ||||
-rw-r--r-- | chromium/base/i18n/file_util_icu.cc | 2 | ||||
-rw-r--r-- | chromium/base/i18n/file_util_icu.h | 2 | ||||
-rw-r--r-- | chromium/base/i18n/icu_util.cc | 41 | ||||
-rw-r--r-- | chromium/base/i18n/time_formatting.cc | 5 | ||||
-rw-r--r-- | chromium/base/i18n/timezone.cc | 608 | ||||
-rw-r--r-- | chromium/base/i18n/timezone.h | 21 | ||||
-rw-r--r-- | chromium/base/i18n/timezone_unittest.cc | 21 |
9 files changed, 671 insertions, 37 deletions
diff --git a/chromium/base/i18n/break_iterator.h b/chromium/base/i18n/break_iterator.h index 96bdeaa9b34..618a320924e 100644 --- a/chromium/base/i18n/break_iterator.h +++ b/chromium/base/i18n/break_iterator.h @@ -36,7 +36,7 @@ // name (BREAK_SPACE) implied. // // Under BREAK_NEWLINE mode, all characters are included in the returned -// string, breking only when a newline-equivalent character is encountered +// string, breaking only when a newline-equivalent character is encountered // (eg. in the UTF-16 equivalent of the string "foo\nbar!\n\n", the line // breaks are at the periods in ".foo\n.bar\n.\n."). // @@ -85,11 +85,11 @@ class BASE_I18N_EXPORT BreakIterator { // Under BREAK_WORD mode, returns true if the break we just hit is the // end of a word. (Otherwise, the break iterator just skipped over e.g. // whitespace or punctuation.) Under BREAK_LINE and BREAK_NEWLINE modes, - // this distinction doesn't apply and it always retuns false. + // this distinction doesn't apply and it always returns false. bool IsWord() const; // Under BREAK_WORD mode, returns true if |position| is at the end of word or - // at the start of word. It always retuns false under BREAK_LINE and + // at the start of word. It always returns false under BREAK_LINE and // BREAK_NEWLINE modes. bool IsEndOfWord(size_t position) const; bool IsStartOfWord(size_t position) const; diff --git a/chromium/base/i18n/case_conversion_unittest.cc b/chromium/base/i18n/case_conversion_unittest.cc index 2139bbe7b38..38e2c687822 100644 --- a/chromium/base/i18n/case_conversion_unittest.cc +++ b/chromium/base/i18n/case_conversion_unittest.cc @@ -6,6 +6,7 @@ #include "base/strings/utf_string_conversions.h" #include "testing/gtest/include/gtest/gtest.h" +namespace base { namespace { // Test upper and lower case string conversion. @@ -24,3 +25,4 @@ TEST(CaseConversionTest, UpperLower) { // TODO(jshin): More tests are needed, especially with non-ASCII characters. } // namespace +} // namespace base diff --git a/chromium/base/i18n/file_util_icu.cc b/chromium/base/i18n/file_util_icu.cc index 4b2ca3ac0b2..9b0525086d0 100644 --- a/chromium/base/i18n/file_util_icu.cc +++ b/chromium/base/i18n/file_util_icu.cc @@ -19,6 +19,8 @@ #include "third_party/icu/source/common/unicode/uniset.h" #include "third_party/icu/source/i18n/unicode/coll.h" +using base::string16; + namespace { class IllegalCharacters { diff --git a/chromium/base/i18n/file_util_icu.h b/chromium/base/i18n/file_util_icu.h index 7f246c7f1c7..15526c3a645 100644 --- a/chromium/base/i18n/file_util_icu.h +++ b/chromium/base/i18n/file_util_icu.h @@ -15,7 +15,7 @@ namespace file_util { // Returns true if file_name does not have any illegal character. The input // param has the same restriction as that for ReplaceIllegalCharacters. -BASE_I18N_EXPORT bool IsFilenameLegal(const string16& file_name); +BASE_I18N_EXPORT bool IsFilenameLegal(const base::string16& file_name); // Replaces characters in 'file_name' that are illegal for file names with // 'replace_char'. 'file_name' must not be a full or relative path, but just the diff --git a/chromium/base/i18n/icu_util.cc b/chromium/base/i18n/icu_util.cc index 3e1353b499d..e5c698475e4 100644 --- a/chromium/base/i18n/icu_util.cc +++ b/chromium/base/i18n/icu_util.cc @@ -29,18 +29,6 @@ #define ICU_UTIL_DATA_SHARED 1 #define ICU_UTIL_DATA_STATIC 2 -#ifndef ICU_UTIL_DATA_IMPL - -#if defined(OS_WIN) -#define ICU_UTIL_DATA_IMPL ICU_UTIL_DATA_SHARED -#elif defined(OS_IOS) -#define ICU_UTIL_DATA_IMPL ICU_UTIL_DATA_FILE -#else -#define ICU_UTIL_DATA_IMPL ICU_UTIL_DATA_STATIC -#endif - -#endif // ICU_UTIL_DATA_IMPL - #if ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_FILE #define ICU_UTIL_DATA_FILE_NAME "icudt" U_ICU_VERSION_SHORT "l.dat" #elif ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_SHARED @@ -86,26 +74,12 @@ bool InitializeICU() { udata_setCommonData(reinterpret_cast<void*>(addr), &err); return err == U_ZERO_ERROR; #elif (ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_STATIC) - // Mac/Linux bundle the ICU data in. + // The ICU data is statically linked. return true; #elif (ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_FILE) -#if !defined(OS_MACOSX) - // For now, expect the data file to be alongside the executable. - // This is sufficient while we work on unit tests, but will eventually - // likely live in a data directory. - FilePath data_path; - bool path_ok = PathService::Get(base::DIR_EXE, &data_path); - DCHECK(path_ok); - u_setDataDirectory(data_path.value().c_str()); - // Only look for the packaged data file; - // the default behavior is to look for individual files. - UErrorCode err = U_ZERO_ERROR; - udata_setFileAccess(UDATA_ONLY_PACKAGES, &err); - return err == U_ZERO_ERROR; -#else // If the ICU data directory is set, ICU won't actually load the data until // it is needed. This can fail if the process is sandboxed at that time. - // Instead, Mac maps the file in and hands off the data so the sandbox won't + // Instead, we map the file in and hand off the data so the sandbox won't // cause any problems. // Chrome doesn't normally shut down ICU, so the mapped data shouldn't ever @@ -113,12 +87,22 @@ bool InitializeICU() { CR_DEFINE_STATIC_LOCAL(base::MemoryMappedFile, mapped_file, ()); if (!mapped_file.IsValid()) { // Assume it is in the framework bundle's Resources directory. +#if !defined(OS_MACOSX) + // For now, expect the data file to be alongside the executable. + // This is sufficient while we work on unit tests, but will eventually + // likely live in a data directory. + FilePath data_path; + bool path_ok = PathService::Get(base::DIR_EXE, &data_path); + DCHECK(path_ok); + data_path = data_path.AppendASCII(ICU_UTIL_DATA_FILE_NAME); +#else FilePath data_path = base::mac::PathForFrameworkBundleResource(CFSTR(ICU_UTIL_DATA_FILE_NAME)); if (data_path.empty()) { DLOG(ERROR) << ICU_UTIL_DATA_FILE_NAME << " not found in bundle"; return false; } +#endif // OS check if (!mapped_file.Initialize(data_path)) { DLOG(ERROR) << "Couldn't mmap " << data_path.value(); return false; @@ -127,7 +111,6 @@ bool InitializeICU() { UErrorCode err = U_ZERO_ERROR; udata_setCommonData(const_cast<uint8*>(mapped_file.data()), &err); return err == U_ZERO_ERROR; -#endif // OS check #endif } diff --git a/chromium/base/i18n/time_formatting.cc b/chromium/base/i18n/time_formatting.cc index 3973dd2508f..917ba43b9ec 100644 --- a/chromium/base/i18n/time_formatting.cc +++ b/chromium/base/i18n/time_formatting.cc @@ -12,8 +12,7 @@ #include "third_party/icu/source/i18n/unicode/dtptngen.h" #include "third_party/icu/source/i18n/unicode/smpdtfmt.h" -using base::Time; - +namespace base { namespace { string16 TimeFormat(const icu::DateFormat* formatter, @@ -48,8 +47,6 @@ string16 TimeFormatWithoutAmPm(const icu::DateFormat* formatter, } // namespace -namespace base { - string16 TimeFormatTimeOfDay(const Time& time) { // We can omit the locale parameter because the default should match // Chrome's application locale. diff --git a/chromium/base/i18n/timezone.cc b/chromium/base/i18n/timezone.cc new file mode 100644 index 00000000000..8c652799dbb --- /dev/null +++ b/chromium/base/i18n/timezone.cc @@ -0,0 +1,608 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "base/i18n/timezone.h" + +#include <map> + +#include "base/memory/singleton.h" +#include "base/strings/string16.h" +#include "base/strings/utf_string_conversions.h" +#include "third_party/icu/source/i18n/unicode/timezone.h" + +namespace base { + +namespace { + +class TimezoneMap { + public: + static TimezoneMap* GetInstance() { + return Singleton<TimezoneMap>::get(); + } + + std::string CountryCodeForTimezone(const std::string& olson_code) { + std::map<std::string, std::string>::iterator iter = map_.find(olson_code); + if (iter != map_.end()) + return iter->second; + + return std::string(); + } + + private: + TimezoneMap() { + // These mappings are adapted from zone.tab, which is available at + // <http://www.ietf.org/timezones/data/zone.tab> and is a part of public + // domain. + struct OlsonCodeData { + std::string country_code; + std::string olson_code; + } olson_code_data[] = { + { "AD", "Europe/Andorra" }, + { "AE", "Asia/Dubai" }, + { "AF", "Asia/Kabul" }, + { "AG", "America/Antigua" }, + { "AI", "America/Anguilla" }, + { "AL", "Europe/Tirane" }, + { "AM", "Asia/Yerevan" }, + { "AO", "Africa/Luanda" }, + { "AQ", "Antarctica/McMurdo" }, + { "AQ", "Antarctica/Rothera" }, + { "AQ", "Antarctica/Palmer" }, + { "AQ", "Antarctica/Mawson" }, + { "AQ", "Antarctica/Davis" }, + { "AQ", "Antarctica/Casey" }, + { "AQ", "Antarctica/Vostok" }, + { "AQ", "Antarctica/DumontDUrville" }, + { "AQ", "Antarctica/Syowa" }, + { "AR", "America/Argentina/Buenos_Aires" }, + { "AR", "America/Argentina/Cordoba" }, + { "AR", "America/Argentina/Salta" }, + { "AR", "America/Argentina/Jujuy" }, + { "AR", "America/Argentina/Tucuman" }, + { "AR", "America/Argentina/Catamarca" }, + { "AR", "America/Argentina/La_Rioja" }, + { "AR", "America/Argentina/San_Juan" }, + { "AR", "America/Argentina/Mendoza" }, + { "AR", "America/Argentina/San_Luis" }, + { "AR", "America/Argentina/Rio_Gallegos" }, + { "AR", "America/Argentina/Ushuaia" }, + { "AS", "Pacific/Pago_Pago" }, + { "AT", "Europe/Vienna" }, + { "AU", "Australia/Lord_Howe" }, + { "AU", "Antarctica/Macquarie" }, + { "AU", "Australia/Hobart" }, + { "AU", "Australia/Currie" }, + { "AU", "Australia/Melbourne" }, + { "AU", "Australia/Sydney" }, + { "AU", "Australia/Broken_Hill" }, + { "AU", "Australia/Brisbane" }, + { "AU", "Australia/Lindeman" }, + { "AU", "Australia/Adelaide" }, + { "AU", "Australia/Darwin" }, + { "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" }, + { "BL", "America/St_Barthelemy" }, + { "BM", "Atlantic/Bermuda" }, + { "BN", "Asia/Brunei" }, + { "BO", "America/La_Paz" }, + { "BQ", "America/Kralendijk" }, + { "BR", "America/Noronha" }, + { "BR", "America/Belem" }, + { "BR", "America/Fortaleza" }, + { "BR", "America/Recife" }, + { "BR", "America/Araguaina" }, + { "BR", "America/Maceio" }, + { "BR", "America/Bahia" }, + { "BR", "America/Sao_Paulo" }, + { "BR", "America/Campo_Grande" }, + { "BR", "America/Cuiaba" }, + { "BR", "America/Santarem" }, + { "BR", "America/Porto_Velho" }, + { "BR", "America/Boa_Vista" }, + { "BR", "America/Manaus" }, + { "BR", "America/Eirunepe" }, + { "BR", "America/Rio_Branco" }, + { "BS", "America/Nassau" }, + { "BT", "Asia/Thimphu" }, + { "BW", "Africa/Gaborone" }, + { "BY", "Europe/Minsk" }, + { "BZ", "America/Belize" }, + { "CA", "America/St_Johns" }, + { "CA", "America/Halifax" }, + { "CA", "America/Glace_Bay" }, + { "CA", "America/Moncton" }, + { "CA", "America/Goose_Bay" }, + { "CA", "America/Blanc-Sablon" }, + { "CA", "America/Toronto" }, + { "CA", "America/Nipigon" }, + { "CA", "America/Thunder_Bay" }, + { "CA", "America/Iqaluit" }, + { "CA", "America/Pangnirtung" }, + { "CA", "America/Resolute" }, + { "CA", "America/Atikokan" }, + { "CA", "America/Rankin_Inlet" }, + { "CA", "America/Winnipeg" }, + { "CA", "America/Rainy_River" }, + { "CA", "America/Regina" }, + { "CA", "America/Swift_Current" }, + { "CA", "America/Edmonton" }, + { "CA", "America/Cambridge_Bay" }, + { "CA", "America/Yellowknife" }, + { "CA", "America/Inuvik" }, + { "CA", "America/Creston" }, + { "CA", "America/Dawson_Creek" }, + { "CA", "America/Vancouver" }, + { "CA", "America/Whitehorse" }, + { "CA", "America/Dawson" }, + { "CC", "Indian/Cocos" }, + { "CD", "Africa/Kinshasa" }, + { "CD", "Africa/Lubumbashi" }, + { "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" }, + { "CN", "Asia/Harbin" }, + { "CN", "Asia/Chongqing" }, + { "CN", "Asia/Urumqi" }, + { "CN", "Asia/Kashgar" }, + { "CO", "America/Bogota" }, + { "CR", "America/Costa_Rica" }, + { "CU", "America/Havana" }, + { "CV", "Atlantic/Cape_Verde" }, + { "CW", "America/Curacao" }, + { "CX", "Indian/Christmas" }, + { "CY", "Asia/Nicosia" }, + { "CZ", "Europe/Prague" }, + { "DE", "Europe/Berlin" }, + { "DE", "Europe/Busingen" }, + { "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", "Africa/Ceuta" }, + { "ES", "Atlantic/Canary" }, + { "ET", "Africa/Addis_Ababa" }, + { "FI", "Europe/Helsinki" }, + { "FJ", "Pacific/Fiji" }, + { "FK", "Atlantic/Stanley" }, + { "FM", "Pacific/Chuuk" }, + { "FM", "Pacific/Pohnpei" }, + { "FM", "Pacific/Kosrae" }, + { "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/Godthab" }, + { "GL", "America/Danmarkshavn" }, + { "GL", "America/Scoresbysund" }, + { "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/Jakarta" }, + { "ID", "Asia/Pontianak" }, + { "ID", "Asia/Makassar" }, + { "ID", "Asia/Jayapura" }, + { "IE", "Europe/Dublin" }, + { "IL", "Asia/Jerusalem" }, + { "IM", "Europe/Isle_of_Man" }, + { "IN", "Asia/Kolkata" }, + { "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/Tarawa" }, + { "KI", "Pacific/Enderbury" }, + { "KI", "Pacific/Kiritimati" }, + { "KM", "Indian/Comoro" }, + { "KN", "America/St_Kitts" }, + { "KP", "Asia/Pyongyang" }, + { "KR", "Asia/Seoul" }, + { "KW", "Asia/Kuwait" }, + { "KY", "America/Cayman" }, + { "KZ", "Asia/Almaty" }, + { "KZ", "Asia/Qyzylorda" }, + { "KZ", "Asia/Aqtobe" }, + { "KZ", "Asia/Aqtau" }, + { "KZ", "Asia/Oral" }, + { "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" }, + { "MF", "America/Marigot" }, + { "MG", "Indian/Antananarivo" }, + { "MH", "Pacific/Majuro" }, + { "MH", "Pacific/Kwajalein" }, + { "MK", "Europe/Skopje" }, + { "ML", "Africa/Bamako" }, + { "MM", "Asia/Rangoon" }, + { "MN", "Asia/Ulaanbaatar" }, + { "MN", "Asia/Hovd" }, + { "MN", "Asia/Choibalsan" }, + { "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/Cancun" }, + { "MX", "America/Merida" }, + { "MX", "America/Monterrey" }, + { "MX", "America/Matamoros" }, + { "MX", "America/Mazatlan" }, + { "MX", "America/Chihuahua" }, + { "MX", "America/Ojinaga" }, + { "MX", "America/Hermosillo" }, + { "MX", "America/Tijuana" }, + { "MX", "America/Santa_Isabel" }, + { "MX", "America/Bahia_Banderas" }, + { "MY", "Asia/Kuala_Lumpur" }, + { "MY", "Asia/Kuching" }, + { "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/Kathmandu" }, + { "NR", "Pacific/Nauru" }, + { "NU", "Pacific/Niue" }, + { "NZ", "Pacific/Auckland" }, + { "NZ", "Pacific/Chatham" }, + { "OM", "Asia/Muscat" }, + { "PA", "America/Panama" }, + { "PE", "America/Lima" }, + { "PF", "Pacific/Tahiti" }, + { "PF", "Pacific/Marquesas" }, + { "PF", "Pacific/Gambier" }, + { "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" }, + { "PS", "Asia/Hebron" }, + { "PT", "Europe/Lisbon" }, + { "PT", "Atlantic/Madeira" }, + { "PT", "Atlantic/Azores" }, + { "PW", "Pacific/Palau" }, + { "PY", "America/Asuncion" }, + { "QA", "Asia/Qatar" }, + { "RE", "Indian/Reunion" }, + { "RO", "Europe/Bucharest" }, + { "RS", "Europe/Belgrade" }, + { "RU", "Europe/Kaliningrad" }, + { "RU", "Europe/Moscow" }, + { "RU", "Europe/Volgograd" }, + { "RU", "Europe/Samara" }, + { "RU", "Asia/Yekaterinburg" }, + { "RU", "Asia/Omsk" }, + { "RU", "Asia/Novosibirsk" }, + { "RU", "Asia/Novokuznetsk" }, + { "RU", "Asia/Krasnoyarsk" }, + { "RU", "Asia/Irkutsk" }, + { "RU", "Asia/Yakutsk" }, + { "RU", "Asia/Khandyga" }, + { "RU", "Asia/Vladivostok" }, + { "RU", "Asia/Sakhalin" }, + { "RU", "Asia/Ust-Nera" }, + { "RU", "Asia/Magadan" }, + { "RU", "Asia/Kamchatka" }, + { "RU", "Asia/Anadyr" }, + { "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" }, + { "SS", "Africa/Juba" }, + { "ST", "Africa/Sao_Tome" }, + { "SV", "America/El_Salvador" }, + { "SX", "America/Lower_Princes" }, + { "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" }, + { "UA", "Europe/Uzhgorod" }, + { "UA", "Europe/Zaporozhye" }, + { "UA", "Europe/Simferopol" }, + { "UG", "Africa/Kampala" }, + { "UM", "Pacific/Johnston" }, + { "UM", "Pacific/Midway" }, + { "UM", "Pacific/Wake" }, + { "US", "America/New_York" }, + { "US", "America/Detroit" }, + { "US", "America/Kentucky/Louisville" }, + { "US", "America/Kentucky/Monticello" }, + { "US", "America/Indiana/Indianapolis" }, + { "US", "America/Indiana/Vincennes" }, + { "US", "America/Indiana/Winamac" }, + { "US", "America/Indiana/Marengo" }, + { "US", "America/Indiana/Petersburg" }, + { "US", "America/Indiana/Vevay" }, + { "US", "America/Chicago" }, + { "US", "America/Indiana/Tell_City" }, + { "US", "America/Indiana/Knox" }, + { "US", "America/Menominee" }, + { "US", "America/North_Dakota/Center" }, + { "US", "America/North_Dakota/New_Salem" }, + { "US", "America/North_Dakota/Beulah" }, + { "US", "America/Denver" }, + { "US", "America/Boise" }, + { "US", "America/Phoenix" }, + { "US", "America/Los_Angeles" }, + { "US", "America/Anchorage" }, + { "US", "America/Juneau" }, + { "US", "America/Sitka" }, + { "US", "America/Yakutat" }, + { "US", "America/Nome" }, + { "US", "America/Adak" }, + { "US", "America/Metlakatla" }, + { "US", "Pacific/Honolulu" }, + { "UY", "America/Montevideo" }, + { "UZ", "Asia/Samarkand" }, + { "UZ", "Asia/Tashkent" }, + { "VA", "Europe/Vatican" }, + { "VC", "America/St_Vincent" }, + { "VE", "America/Caracas" }, + { "VG", "America/Tortola" }, + { "VI", "America/St_Thomas" }, + { "VN", "Asia/Ho_Chi_Minh" }, + { "VU", "Pacific/Efate" }, + { "WF", "Pacific/Wallis" }, + { "WS", "Pacific/Apia" }, + { "YE", "Asia/Aden" }, + { "YT", "Indian/Mayotte" }, + { "ZA", "Africa/Johannesburg" }, + { "ZM", "Africa/Lusaka" }, + { "ZW", "Africa/Harare" }, + // The mappings below are custom additions to zone.tab. + { "GB", "Etc/GMT" }, + { "GB", "Etc/UTC" }, + { "GB", "Etc/UCT" }, + }; + + for (size_t i = 0; i < ARRAYSIZE_UNSAFE(olson_code_data); ++i) { + map_[olson_code_data[i].olson_code] = olson_code_data[i].country_code; + } + + // These are mapping from old codenames to new codenames. They are also + // part of public domain, and available at + // <http://www.ietf.org/timezones/data/backward>. + struct LinkData { + std::string old_code; + std::string new_code; + } link_data[] = { + { "Africa/Asmera", "Africa/Asmara" }, + { "Africa/Timbuktu", "Africa/Bamako" }, + { "America/Argentina/ComodRivadavia", "America/Argentina/Catamarca" }, + { "America/Atka", "America/Adak" }, + { "America/Buenos_Aires", "America/Argentina/Buenos_Aires" }, + { "America/Catamarca", "America/Argentina/Catamarca" }, + { "America/Coral_Harbour", "America/Atikokan" }, + { "America/Cordoba", "America/Argentina/Cordoba" }, + { "America/Ensenada", "America/Tijuana" }, + { "America/Fort_Wayne", "America/Indiana/Indianapolis" }, + { "America/Indianapolis", "America/Indiana/Indianapolis" }, + { "America/Jujuy", "America/Argentina/Jujuy" }, + { "America/Knox_IN", "America/Indiana/Knox" }, + { "America/Louisville", "America/Kentucky/Louisville" }, + { "America/Mendoza", "America/Argentina/Mendoza" }, + { "America/Porto_Acre", "America/Rio_Branco" }, + { "America/Rosario", "America/Argentina/Cordoba" }, + { "America/Virgin", "America/St_Thomas" }, + { "Asia/Ashkhabad", "Asia/Ashgabat" }, + { "Asia/Chungking", "Asia/Chongqing" }, + { "Asia/Dacca", "Asia/Dhaka" }, + { "Asia/Katmandu", "Asia/Kathmandu" }, + { "Asia/Calcutta", "Asia/Kolkata" }, + { "Asia/Macao", "Asia/Macau" }, + { "Asia/Tel_Aviv", "Asia/Jerusalem" }, + { "Asia/Saigon", "Asia/Ho_Chi_Minh" }, + { "Asia/Thimbu", "Asia/Thimphu" }, + { "Asia/Ujung_Pandang", "Asia/Makassar" }, + { "Asia/Ulan_Bator", "Asia/Ulaanbaatar" }, + { "Atlantic/Faeroe", "Atlantic/Faroe" }, + { "Atlantic/Jan_Mayen", "Europe/Oslo" }, + { "Australia/ACT", "Australia/Sydney" }, + { "Australia/Canberra", "Australia/Sydney" }, + { "Australia/LHI", "Australia/Lord_Howe" }, + { "Australia/NSW", "Australia/Sydney" }, + { "Australia/North", "Australia/Darwin" }, + { "Australia/Queensland", "Australia/Brisbane" }, + { "Australia/South", "Australia/Adelaide" }, + { "Australia/Tasmania", "Australia/Hobart" }, + { "Australia/Victoria", "Australia/Melbourne" }, + { "Australia/West", "Australia/Perth" }, + { "Australia/Yancowinna", "Australia/Broken_Hill" }, + { "Brazil/Acre", "America/Rio_Branco" }, + { "Brazil/DeNoronha", "America/Noronha" }, + { "Brazil/East", "America/Sao_Paulo" }, + { "Brazil/West", "America/Manaus" }, + { "Canada/Atlantic", "America/Halifax" }, + { "Canada/Central", "America/Winnipeg" }, + { "Canada/East-Saskatchewan", "America/Regina" }, + { "Canada/Eastern", "America/Toronto" }, + { "Canada/Mountain", "America/Edmonton" }, + { "Canada/Newfoundland", "America/St_Johns" }, + { "Canada/Pacific", "America/Vancouver" }, + { "Canada/Saskatchewan", "America/Regina" }, + { "Canada/Yukon", "America/Whitehorse" }, + { "Chile/Continental", "America/Santiago" }, + { "Chile/EasterIsland", "Pacific/Easter" }, + { "Cuba", "America/Havana" }, + { "Egypt", "Africa/Cairo" }, + { "Eire", "Europe/Dublin" }, + { "Europe/Belfast", "Europe/London" }, + { "Europe/Tiraspol", "Europe/Chisinau" }, + { "GB", "Europe/London" }, + { "GB-Eire", "Europe/London" }, + { "GMT+0", "Etc/GMT" }, + { "GMT-0", "Etc/GMT" }, + { "GMT0", "Etc/GMT" }, + { "Greenwich", "Etc/GMT" }, + { "Hongkong", "Asia/Hong_Kong" }, + { "Iceland", "Atlantic/Reykjavik" }, + { "Iran", "Asia/Tehran" }, + { "Israel", "Asia/Jerusalem" }, + { "Jamaica", "America/Jamaica" }, + { "Japan", "Asia/Tokyo" }, + { "Kwajalein", "Pacific/Kwajalein" }, + { "Libya", "Africa/Tripoli" }, + { "Mexico/BajaNorte", "America/Tijuana" }, + { "Mexico/BajaSur", "America/Mazatlan" }, + { "Mexico/General", "America/Mexico_City" }, + { "NZ", "Pacific/Auckland" }, + { "NZ-CHAT", "Pacific/Chatham" }, + { "Navajo", "America/Denver" }, + { "PRC", "Asia/Shanghai" }, + { "Pacific/Samoa", "Pacific/Pago_Pago" }, + { "Pacific/Yap", "Pacific/Chuuk" }, + { "Pacific/Truk", "Pacific/Chuuk" }, + { "Pacific/Ponape", "Pacific/Pohnpei" }, + { "Poland", "Europe/Warsaw" }, + { "Portugal", "Europe/Lisbon" }, + { "ROC", "Asia/Taipei" }, + { "ROK", "Asia/Seoul" }, + { "Singapore", "Asia/Singapore" }, + { "Turkey", "Europe/Istanbul" }, + { "UCT", "Etc/UCT" }, + { "US/Alaska", "America/Anchorage" }, + { "US/Aleutian", "America/Adak" }, + { "US/Arizona", "America/Phoenix" }, + { "US/Central", "America/Chicago" }, + { "US/East-Indiana", "America/Indiana/Indianapolis" }, + { "US/Eastern", "America/New_York" }, + { "US/Hawaii", "Pacific/Honolulu" }, + { "US/Indiana-Starke", "America/Indiana/Knox" }, + { "US/Michigan", "America/Detroit" }, + { "US/Mountain", "America/Denver" }, + { "US/Pacific", "America/Los_Angeles" }, + { "US/Samoa", "Pacific/Pago_Pago" }, + { "UTC", "Etc/UTC" }, + { "Universal", "Etc/UTC" }, + { "W-SU", "Europe/Moscow" }, + { "Zulu", "Etc/UTC" }, + }; + + for (size_t i = 0; i < ARRAYSIZE_UNSAFE(link_data); ++i) { + map_[link_data[i].old_code] = map_[link_data[i].new_code]; + } + } + + friend struct DefaultSingletonTraits<TimezoneMap>; + + std::map<std::string, std::string> map_; + + DISALLOW_COPY_AND_ASSIGN(TimezoneMap); +}; + +} // namespace + +std::string CountryCodeForCurrentTimezone() { + scoped_ptr<icu::TimeZone> zone(icu::TimeZone::createDefault()); + icu::UnicodeString id; + zone->getID(id); + string16 olson_code(id.getBuffer(), id.length()); + return TimezoneMap::GetInstance()->CountryCodeForTimezone( + UTF16ToUTF8(olson_code)); +} + +} // namespace base diff --git a/chromium/base/i18n/timezone.h b/chromium/base/i18n/timezone.h new file mode 100644 index 00000000000..b7275f7b00b --- /dev/null +++ b/chromium/base/i18n/timezone.h @@ -0,0 +1,21 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef BASE_I18N_TIMEZONE_H_ +#define BASE_I18N_TIMEZONE_H_ + +#include <string> + +#include "base/i18n/base_i18n_export.h" + +namespace base { + +// Checks the system timezone and turns it into a two-character ASCII country +// code. This may fail (for example, it will always fail on Android), in which +// case it will return an empty string. +BASE_I18N_EXPORT std::string CountryCodeForCurrentTimezone(); + +} // namespace base + +#endif // BASE_TIME_TIMEZONE_H_ diff --git a/chromium/base/i18n/timezone_unittest.cc b/chromium/base/i18n/timezone_unittest.cc new file mode 100644 index 00000000000..2cdcc422985 --- /dev/null +++ b/chromium/base/i18n/timezone_unittest.cc @@ -0,0 +1,21 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "base/i18n/timezone.h" + +#include "testing/gtest/include/gtest/gtest.h" + +namespace base { +namespace { + +TEST(TimezoneTest, CountryCodeForCurrentTimezone) { + std::string country_code = CountryCodeForCurrentTimezone(); + // On some systems (such as Android or some flavors of Linux), icu may come up + // empty. + if (!country_code.empty()) + EXPECT_EQ(2U, country_code.size()); +} + +} // namespace +} // namespace base |