1b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/*
2b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru*******************************************************************************
38393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius* Copyright (C) 2007-2013, International Business Machines Corporation and    *
4b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru* others. All Rights Reserved.                                                *
5b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru*******************************************************************************
6b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru*/
7b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#ifndef ZONEMETA_H
8b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#define ZONEMETA_H
9b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
10b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#include "unicode/utypes.h"
11b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
12b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#if !UCONFIG_NO_FORMATTING
13b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
14b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#include "unicode/unistr.h"
15b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#include "hash.h"
16b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
17b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste QueruU_NAMESPACE_BEGIN
18b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
19b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Querutypedef struct OlsonToMetaMappingEntry {
20b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    const UChar *mzid; // const because it's a reference to a resource bundle string.
21b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    UDate from;
22b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    UDate to;
23b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru} OlsonToMetaMappingEntry;
24b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
25b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queruclass UVector;
26b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2clairehoclass TimeZone;
27b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
28b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queruclass U_I18N_API ZoneMeta {
29b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Querupublic:
30b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    /**
31b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho     * Return the canonical id for this tzid defined by CLDR, which might be the id itself.
32b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho     * If the given system tzid is not known, U_ILLEGAL_ARGUMENT_ERROR is set in the status.
33b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho     *
34b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho     * Note: this internal API supports all known system IDs and "Etc/Unknown" (which is
35b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho     * NOT a system ID).
36b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru     */
37b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho    static UnicodeString& U_EXPORT2 getCanonicalCLDRID(const UnicodeString &tzid, UnicodeString &systemID, UErrorCode& status);
38b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho
39b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho    /**
40b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho     * Return the canonical id for this tzid defined by CLDR, which might be the id itself.
41b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho     * This overload method returns a persistent const UChar*, which is guranteed to persist
42b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho     * (a pointer to a resource).
43b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho     */
44b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho    static const UChar* U_EXPORT2 getCanonicalCLDRID(const UnicodeString &tzid, UErrorCode& status);
45b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho
46b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho    /*
47b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho     * Conveninent method returning CLDR canonical ID for the given time zone
48b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho     */
49b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho    static const UChar* U_EXPORT2 getCanonicalCLDRID(const TimeZone& tz);
50b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
51b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    /**
52b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru     * Return the canonical country code for this tzid.  If we have none, or if the time zone
538393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius     * is not associated with a country, return bogus string.
548393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius     * @param tzid Zone ID
558393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius     * @param country [output] Country code
568393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius     * @param isPrimary [output] TRUE if the zone is the primary zone for the country
578393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius     * @return A reference to the result country
58b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru     */
598393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius    static UnicodeString& U_EXPORT2 getCanonicalCountry(const UnicodeString &tzid, UnicodeString &country, UBool *isPrimary = NULL);
60b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
61b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    /**
62b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru     * Returns a CLDR metazone ID for the given Olson tzid and time.
63b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru     */
64c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru    static UnicodeString& U_EXPORT2 getMetazoneID(const UnicodeString &tzid, UDate date, UnicodeString &result);
65b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    /**
66b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru     * Returns an Olson ID for the ginve metazone and region
67b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru     */
68c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru    static UnicodeString& U_EXPORT2 getZoneIdByMetazone(const UnicodeString &mzid, const UnicodeString &region, UnicodeString &result);
69b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
70c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru    static const UVector* U_EXPORT2 getMetazoneMappings(const UnicodeString &tzid);
71b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
72b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho    static const UVector* U_EXPORT2 getAvailableMetazoneIDs();
73b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho
74b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho    /**
75b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho     * Returns the pointer to the persistent time zone ID string, or NULL if the given tzid is not in the
76b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho     * tz database. This method is useful when you maintain persistent zone IDs without duplication.
77b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho     */
78b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho    static const UChar* U_EXPORT2 findTimeZoneID(const UnicodeString& tzid);
79b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho
80b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho    /**
81b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho     * Returns the pointer to the persistent meta zone ID string, or NULL if the given mzid is not available.
82b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho     * This method is useful when you maintain persistent meta zone IDs without duplication.
83b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho     */
84b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho    static const UChar* U_EXPORT2 findMetaZoneID(const UnicodeString& mzid);
85b26ce3a7367e4ed2ee7ddddcdc3f3d3377a455c2claireho
86103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius    /**
87103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius     * Creates a custom zone for the offset
88103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius     * @param offset GMT offset in milliseconds
89103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius     * @return A custom TimeZone for the offset with normalized time zone id
90103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius     */
91103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius    static TimeZone* createCustomTimeZone(int32_t offset);
92103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius
938393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius    /**
948393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius     * Returns the time zone's short ID (null terminated) for the zone.
958393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius     * For example, "uslax" for zone "America/Los_Angeles".
968393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius     * @param tz the time zone
978393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius     * @return the short ID of the time zone, or null if the short ID is not available.
988393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius     */
998393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius    static const UChar* U_EXPORT2 getShortID(const TimeZone& tz);
1008393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius
1018393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius    /**
1028393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius     * Returns the time zone's short ID (null terminated) for the zone ID.
1038393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius     * For example, "uslax" for zone ID "America/Los_Angeles".
1048393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius     * @param tz the time zone ID
1058393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius     * @return the short ID of the time zone ID, or null if the short ID is not available.
1068393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius     */
1078393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius    static const UChar* U_EXPORT2 getShortID(const UnicodeString& id);
1088393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius
109b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queruprivate:
110c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru    ZoneMeta(); // Prevent construction.
11150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho    static UVector* createMetazoneMappings(const UnicodeString &tzid);
112103e9ffba2cba345d0078eb8b8db33249f81840aCraig Cornelius    static UnicodeString& formatCustomID(uint8_t hour, uint8_t min, uint8_t sec, UBool negative, UnicodeString& id);
1138393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius    static const UChar* getShortIDFromCanonical(const UChar* canonicalID);
114b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru};
115b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
116b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste QueruU_NAMESPACE_END
117b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
118b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#endif /* #if !UCONFIG_NO_FORMATTING */
119b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#endif // ZONEMETA_H
120