X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/46f4442e9a5a4f3b98b7c1083586332f6a8a99a4..4f1e1a09ce4daed860e35d359ce2fceccb0764e8:/icuSources/i18n/zonemeta.h diff --git a/icuSources/i18n/zonemeta.h b/icuSources/i18n/zonemeta.h index 16943cb6..9dbcc878 100644 --- a/icuSources/i18n/zonemeta.h +++ b/icuSources/i18n/zonemeta.h @@ -1,6 +1,8 @@ +// © 2016 and later: Unicode, Inc. and others. +// License & terms of use: http://www.unicode.org/copyright.html /* ******************************************************************************* -* Copyright (C) 2007-2009, International Business Machines Corporation and * +* Copyright (C) 2007-2013, International Business Machines Corporation and * * others. All Rights Reserved. * ******************************************************************************* */ @@ -16,45 +18,51 @@ U_NAMESPACE_BEGIN -typedef struct CanonicalMapEntry { - const UChar *id; // const because it's a reference to a resource bundle string. - const UChar *country; // const because it's a reference to a resource bundle string. -} CanonicalMapEntry; - typedef struct OlsonToMetaMappingEntry { const UChar *mzid; // const because it's a reference to a resource bundle string. UDate from; UDate to; } OlsonToMetaMappingEntry; -typedef struct MetaToOlsonMappingEntry { - const UChar *id; // const because it's a reference to a resource bundle string. - UChar *territory; -} MetaToOlsonMappingEntry; - class UVector; +class TimeZone; class U_I18N_API ZoneMeta { public: /** - * Return the canonical id for this system tzid, which might be the id itself. - * If the given system tzid is not know, U_ILLEGAL_ARGUMENT_ERROR is set in the status. + * Return the canonical id for this tzid defined by CLDR, which might be the id itself. + * If the given system tzid is not known, U_ILLEGAL_ARGUMENT_ERROR is set in the status. + * + * Note: this internal API supports all known system IDs and "Etc/Unknown" (which is + * NOT a system ID). */ - static UnicodeString& U_EXPORT2 getCanonicalSystemID(const UnicodeString &tzid, UnicodeString &systemID, UErrorCode& status); + static UnicodeString& U_EXPORT2 getCanonicalCLDRID(const UnicodeString &tzid, UnicodeString &systemID, UErrorCode& status); /** - * Return the canonical country code for this tzid. If we have none, or if the time zone - * is not associated with a country, return null. + * Return the canonical id for this tzid defined by CLDR, which might be the id itself. + * This overload method returns a persistent const UChar*, which is guranteed to persist + * (a pointer to a resource). If the given system tzid is not known, U_ILLEGAL_ARGUMENT_ERROR + * is set in the status. + * @param tzid Zone ID + * @param status Receives the status + * @return The canonical ID for the input time zone ID */ - static UnicodeString& U_EXPORT2 getCanonicalCountry(const UnicodeString &tzid, UnicodeString &canonicalCountry); + static const UChar* U_EXPORT2 getCanonicalCLDRID(const UnicodeString &tzid, UErrorCode& status); + + /* + * Conveninent method returning CLDR canonical ID for the given time zone + */ + static const UChar* U_EXPORT2 getCanonicalCLDRID(const TimeZone& tz); /** - * Return the country code if this is a 'single' time zone that can fallback to just - * the country, otherwise return empty string. (Note, one must also check the locale data - * to see that there is a localization for the country in order to implement - * tr#35 appendix J step 5.) + * Return the canonical country code for this tzid. If we have none, or if the time zone + * is not associated with a country, return bogus string. + * @param tzid Zone ID + * @param country [output] Country code + * @param isPrimary [output] TRUE if the zone is the primary zone for the country + * @return A reference to the result country */ - static UnicodeString& U_EXPORT2 getSingleCountry(const UnicodeString &tzid, UnicodeString &country); + static UnicodeString& U_EXPORT2 getCanonicalCountry(const UnicodeString &tzid, UnicodeString &country, UBool *isPrimary = NULL); /** * Returns a CLDR metazone ID for the given Olson tzid and time. @@ -67,16 +75,48 @@ public: static const UVector* U_EXPORT2 getMetazoneMappings(const UnicodeString &tzid); + static const UVector* U_EXPORT2 getAvailableMetazoneIDs(); + + /** + * Returns the pointer to the persistent time zone ID string, or NULL if the given tzid is not in the + * tz database. This method is useful when you maintain persistent zone IDs without duplication. + */ + static const UChar* U_EXPORT2 findTimeZoneID(const UnicodeString& tzid); + + /** + * Returns the pointer to the persistent meta zone ID string, or NULL if the given mzid is not available. + * This method is useful when you maintain persistent meta zone IDs without duplication. + */ + static const UChar* U_EXPORT2 findMetaZoneID(const UnicodeString& mzid); + + /** + * Creates a custom zone for the offset + * @param offset GMT offset in milliseconds + * @return A custom TimeZone for the offset with normalized time zone id + */ + static TimeZone* createCustomTimeZone(int32_t offset); + + /** + * Returns the time zone's short ID (null terminated) for the zone. + * For example, "uslax" for zone "America/Los_Angeles". + * @param tz the time zone + * @return the short ID of the time zone, or null if the short ID is not available. + */ + static const UChar* U_EXPORT2 getShortID(const TimeZone& tz); + + /** + * Returns the time zone's short ID (null terminated) for the zone ID. + * For example, "uslax" for zone ID "America/Los_Angeles". + * @param tz the time zone ID + * @return the short ID of the time zone ID, or null if the short ID is not available. + */ + static const UChar* U_EXPORT2 getShortID(const UnicodeString& id); + private: ZoneMeta(); // Prevent construction. - static const CanonicalMapEntry* U_EXPORT2 getCanonicalInfo(const UnicodeString &tzid); - - static void initializeCanonicalMap(void); - static void initializeOlsonToMeta(void); - static void initializeMetaToOlson(void); - static UHashtable* createCanonicalMap(void); - static UHashtable* createOlsonToMetaMap(void); - static UHashtable* createMetaToOlsonMap(void); + static UVector* createMetazoneMappings(const UnicodeString &tzid); + static UnicodeString& formatCustomID(uint8_t hour, uint8_t min, uint8_t sec, UBool negative, UnicodeString& id); + static const UChar* getShortIDFromCanonical(const UChar* canonicalID); }; U_NAMESPACE_END