diff --git a/.gitattributes b/.gitattributes index 449a9051cf..f1a7b73726 100644 --- a/.gitattributes +++ b/.gitattributes @@ -215,6 +215,7 @@ icu4c/source/tools/makeconv/makeconv.vcxproj.filters -text icu4c/source/tools/pkgdata/pkgdata.vcxproj -text icu4c/source/tools/pkgdata/pkgdata.vcxproj.filters -text icu4c/source/tools/toolutil/toolutil.vcxproj -text +icu4c/source/tools/tzcode/icuregions -text icu4j/build.properties -text icu4j/demos/.settings/org.eclipse.core.resources.prefs -text icu4j/demos/manifest.stub -text diff --git a/icu4c/source/tools/tzcode/icuregions b/icu4c/source/tools/tzcode/icuregions new file mode 100644 index 0000000000..1ea894b089 --- /dev/null +++ b/icu4c/source/tools/tzcode/icuregions @@ -0,0 +1,11 @@ +###################################################################### +# Copyright (C) 2013, International Business Machines +# Corporation and others. All Rights Reserved. +###################################################################### +# This is an ICU-specific file including zone/region mapping. +# +# Each line below indicates zone and its region in the syntax below - +# +# +America/Montreal CA + diff --git a/icu4c/source/tools/tzcode/tz.alias b/icu4c/source/tools/tzcode/tz.alias deleted file mode 100644 index cf984ba098..0000000000 --- a/icu4c/source/tools/tzcode/tz.alias +++ /dev/null @@ -1,56 +0,0 @@ -# -# !!!! WARNING !!!!! -# -# This file is OBSOLLETE and no longer used by ICU tzdata build tool. -# Use the file 'icuzones' to specify backward compatibility aliases. -# -# 2007-04-03 Yoshito Umaoka -# - -###################################################################### -# Copyright (C) 1999-2007, International Business Machines -# Corporation and others. All Rights Reserved. -###################################################################### -# A simple alias list. We use this to retain backward compatibility. -# For example, ICU has always defined the zone name "PST" to indicate -# the zone America/Los_Angeles. Unless we continue to have a zone with -# this ID, legacy code may break. -# -# This list is read by tz2icu to incorporate legacy ICU zone aliases -# into the ICU system zone data. -# -# Format: alias_name unix_name # optional comment - -#### Aliases that conflict with Olson compatibility Zone definition - -ACT Australia/Darwin -AET Australia/Sydney -AGT America/Buenos_Aires -ART Africa/Cairo -AST America/Anchorage -BET America/Sao_Paulo -BST Asia/Dhaka # spelling changed in 2000h; was Asia/Dacca -CAT Africa/Harare -CNT America/St_Johns -CST America/Chicago -CTT Asia/Shanghai -EAT Africa/Addis_Ababa -ECT Europe/Paris -# EET Europe/Istanbul # EET is a standard UNIX zone -#### EST America/New_York # Defined as -05:00 -#### HST Pacific/Honolulu # Defined as -10:00 -IET America/Indianapolis -IST Asia/Calcutta -JST Asia/Tokyo -# MET Asia/Tehran # MET is a standard UNIX zone -MIT Pacific/Apia -#### MST America/Denver # Defined as -07:00 -NET Asia/Yerevan -NST Pacific/Auckland -PLT Asia/Karachi -PNT America/Phoenix -PRT America/Puerto_Rico -PST America/Los_Angeles -SST Pacific/Guadalcanal -# UTC Etc/UTC # Olson LINK -VST Asia/Saigon diff --git a/icu4c/source/tools/tzcode/tz2icu.cpp b/icu4c/source/tools/tzcode/tz2icu.cpp index 238e86560d..6af3eb4000 100644 --- a/icu4c/source/tools/tzcode/tz2icu.cpp +++ b/icu4c/source/tools/tzcode/tz2icu.cpp @@ -1,7 +1,7 @@ /* ********************************************************************** -* Copyright (c) 2003-2010, International Business Machines +* Copyright (c) 2003-2013, International Business Machines * Corporation and others. All Rights Reserved. ********************************************************************** * Author: Alan Liu @@ -1581,8 +1581,36 @@ int main(int argc, char *argv[]) { } // Create the country map + map icuRegions; // ICU's custom zone -> country override map > countryMap; // country -> set of zones map reverseCountryMap; // zone -> country + + try { + // Read icuregions file to collect ICU's own zone-region mapping data. + ifstream frg(ICU_REGIONS); + if (frg) { + string line; + while (getline(frg, line)) { + if (line[0] == '#') continue; + + string zone, country; + istringstream is(line); + is >> zone >> country; + if (zone.size() == 0) continue; + if (country.size() < 2) { + cerr << "Error: Can't parse " << line << " in " << ICU_REGIONS << endl; + return 1; + } + icuRegions[zone] = country; + } + } else { + cout << "No custom region map [icuregions]" << endl; + } + } catch (const exception& error) { + cerr << "Error: While reading " << ICU_REGIONS << ": " << error.what() << endl; + return 1; + } + try { ifstream f(zonetab.c_str()); if (!f) { @@ -1609,6 +1637,13 @@ int main(int argc, char *argv[]) { << " in " << zonetab << endl; return 1; } + if (icuRegions.find(zone) != icuRegions.end()) { + // Custom override + string customCountry = icuRegions[zone]; + cout << "Region Mapping: custom override for " << zone + << " " << country << " -> " << customCountry << endl; + country = customCountry; + } countryMap[country].insert(zone); reverseCountryMap[zone] = country; //cerr << (n+1) << ": " << country << " <=> " << zone << endl; @@ -1621,6 +1656,20 @@ int main(int argc, char *argv[]) { return 1; } + // Merge ICU's own zone-region mapping data + for (map::const_iterator i = icuRegions.begin(); + i != icuRegions.end(); ++i) { + const string& zid(i->first); + if (reverseCountryMap.find(zid) != reverseCountryMap.end()) { + continue; + } + cout << "Region Mapping: custom data zone=" << zid + << ", region=" << i->second << endl; + + reverseCountryMap[zid] = i->second; + countryMap[i->second].insert(zid); + } + // Merge ICU aliases into country map. Don't merge any alias // that already has a country map, since that doesn't make sense. // E.g. "Link Europe/Oslo Arctic/Longyearbyen" doesn't mean we diff --git a/icu4c/source/tools/tzcode/tz2icu.h b/icu4c/source/tools/tzcode/tz2icu.h index a488ea6db2..213608d3a0 100644 --- a/icu4c/source/tools/tzcode/tz2icu.h +++ b/icu4c/source/tools/tzcode/tz2icu.h @@ -1,6 +1,6 @@ /* ********************************************************************** -* Copyright (c) 2003-2010, International Business Machines +* Copyright (c) 2003-2013, International Business Machines * Corporation and others. All Rights Reserved. ********************************************************************** * Author: Alan Liu @@ -31,9 +31,6 @@ typedef unsigned char ICUZoneinfoVersion; * zic to communicate final zone data to tz2icu. */ #define ICU_ZONE_FILE "icu_zone.txt" -/* File containing legacy aliases. Read by tz2icu. */ -#define ICU_TZ_ALIAS "tz.alias" - /* Output resource name. This determines both the file name and the * resource name within the file. That is, the output will be to the * file ICU_TZ_RESOURCE ".txt" and the resource within it will be @@ -41,4 +38,7 @@ typedef unsigned char ICUZoneinfoVersion; #define ICU_TZ_RESOURCE_OLD "zoneinfo" #define ICU_TZ_RESOURCE "zoneinfo64" +/* File containinng custom zone-region mapping. */ +#define ICU_REGIONS "icuregions" + #endif