michael@0: /* michael@0: ******************************************************************************* michael@0: * Copyright (C) 2007-2013, International Business Machines Corporation and * michael@0: * others. All Rights Reserved. * michael@0: ******************************************************************************* michael@0: */ michael@0: #ifndef ZONEMETA_H michael@0: #define ZONEMETA_H michael@0: michael@0: #include "unicode/utypes.h" michael@0: michael@0: #if !UCONFIG_NO_FORMATTING michael@0: michael@0: #include "unicode/unistr.h" michael@0: #include "hash.h" michael@0: michael@0: U_NAMESPACE_BEGIN michael@0: michael@0: typedef struct OlsonToMetaMappingEntry { michael@0: const UChar *mzid; // const because it's a reference to a resource bundle string. michael@0: UDate from; michael@0: UDate to; michael@0: } OlsonToMetaMappingEntry; michael@0: michael@0: class UVector; michael@0: class TimeZone; michael@0: michael@0: class U_I18N_API ZoneMeta { michael@0: public: michael@0: /** michael@0: * Return the canonical id for this tzid defined by CLDR, which might be the id itself. michael@0: * If the given system tzid is not known, U_ILLEGAL_ARGUMENT_ERROR is set in the status. michael@0: * michael@0: * Note: this internal API supports all known system IDs and "Etc/Unknown" (which is michael@0: * NOT a system ID). michael@0: */ michael@0: static UnicodeString& U_EXPORT2 getCanonicalCLDRID(const UnicodeString &tzid, UnicodeString &systemID, UErrorCode& status); michael@0: michael@0: /** michael@0: * Return the canonical id for this tzid defined by CLDR, which might be the id itself. michael@0: * This overload method returns a persistent const UChar*, which is guranteed to persist michael@0: * (a pointer to a resource). michael@0: */ michael@0: static const UChar* U_EXPORT2 getCanonicalCLDRID(const UnicodeString &tzid, UErrorCode& status); michael@0: michael@0: /* michael@0: * Conveninent method returning CLDR canonical ID for the given time zone michael@0: */ michael@0: static const UChar* U_EXPORT2 getCanonicalCLDRID(const TimeZone& tz); michael@0: michael@0: /** michael@0: * Return the canonical country code for this tzid. If we have none, or if the time zone michael@0: * is not associated with a country, return bogus string. michael@0: * @param tzid Zone ID michael@0: * @param country [output] Country code michael@0: * @param isPrimary [output] TRUE if the zone is the primary zone for the country michael@0: * @return A reference to the result country michael@0: */ michael@0: static UnicodeString& U_EXPORT2 getCanonicalCountry(const UnicodeString &tzid, UnicodeString &country, UBool *isPrimary = NULL); michael@0: michael@0: /** michael@0: * Returns a CLDR metazone ID for the given Olson tzid and time. michael@0: */ michael@0: static UnicodeString& U_EXPORT2 getMetazoneID(const UnicodeString &tzid, UDate date, UnicodeString &result); michael@0: /** michael@0: * Returns an Olson ID for the ginve metazone and region michael@0: */ michael@0: static UnicodeString& U_EXPORT2 getZoneIdByMetazone(const UnicodeString &mzid, const UnicodeString ®ion, UnicodeString &result); michael@0: michael@0: static const UVector* U_EXPORT2 getMetazoneMappings(const UnicodeString &tzid); michael@0: michael@0: static const UVector* U_EXPORT2 getAvailableMetazoneIDs(); michael@0: michael@0: /** michael@0: * Returns the pointer to the persistent time zone ID string, or NULL if the given tzid is not in the michael@0: * tz database. This method is useful when you maintain persistent zone IDs without duplication. michael@0: */ michael@0: static const UChar* U_EXPORT2 findTimeZoneID(const UnicodeString& tzid); michael@0: michael@0: /** michael@0: * Returns the pointer to the persistent meta zone ID string, or NULL if the given mzid is not available. michael@0: * This method is useful when you maintain persistent meta zone IDs without duplication. michael@0: */ michael@0: static const UChar* U_EXPORT2 findMetaZoneID(const UnicodeString& mzid); michael@0: michael@0: /** michael@0: * Creates a custom zone for the offset michael@0: * @param offset GMT offset in milliseconds michael@0: * @return A custom TimeZone for the offset with normalized time zone id michael@0: */ michael@0: static TimeZone* createCustomTimeZone(int32_t offset); michael@0: michael@0: /** michael@0: * Returns the time zone's short ID (null terminated) for the zone. michael@0: * For example, "uslax" for zone "America/Los_Angeles". michael@0: * @param tz the time zone michael@0: * @return the short ID of the time zone, or null if the short ID is not available. michael@0: */ michael@0: static const UChar* U_EXPORT2 getShortID(const TimeZone& tz); michael@0: michael@0: /** michael@0: * Returns the time zone's short ID (null terminated) for the zone ID. michael@0: * For example, "uslax" for zone ID "America/Los_Angeles". michael@0: * @param tz the time zone ID michael@0: * @return the short ID of the time zone ID, or null if the short ID is not available. michael@0: */ michael@0: static const UChar* U_EXPORT2 getShortID(const UnicodeString& id); michael@0: michael@0: private: michael@0: ZoneMeta(); // Prevent construction. michael@0: static UVector* createMetazoneMappings(const UnicodeString &tzid); michael@0: static UnicodeString& formatCustomID(uint8_t hour, uint8_t min, uint8_t sec, UBool negative, UnicodeString& id); michael@0: static const UChar* getShortIDFromCanonical(const UChar* canonicalID); michael@0: }; michael@0: michael@0: U_NAMESPACE_END michael@0: michael@0: #endif /* #if !UCONFIG_NO_FORMATTING */ michael@0: #endif // ZONEMETA_H