1*0e209d39SAndroid Build Coastguard Worker // © 2016 and later: Unicode, Inc. and others. 2*0e209d39SAndroid Build Coastguard Worker // License & terms of use: http://www.unicode.org/copyright.html 3*0e209d39SAndroid Build Coastguard Worker /* 4*0e209d39SAndroid Build Coastguard Worker ******************************************************************************* 5*0e209d39SAndroid Build Coastguard Worker * Copyright (C) 2007-2013, International Business Machines Corporation and * 6*0e209d39SAndroid Build Coastguard Worker * others. All Rights Reserved. * 7*0e209d39SAndroid Build Coastguard Worker ******************************************************************************* 8*0e209d39SAndroid Build Coastguard Worker */ 9*0e209d39SAndroid Build Coastguard Worker #ifndef ZONEMETA_H 10*0e209d39SAndroid Build Coastguard Worker #define ZONEMETA_H 11*0e209d39SAndroid Build Coastguard Worker 12*0e209d39SAndroid Build Coastguard Worker #include "unicode/utypes.h" 13*0e209d39SAndroid Build Coastguard Worker 14*0e209d39SAndroid Build Coastguard Worker #if !UCONFIG_NO_FORMATTING 15*0e209d39SAndroid Build Coastguard Worker 16*0e209d39SAndroid Build Coastguard Worker #include "unicode/unistr.h" 17*0e209d39SAndroid Build Coastguard Worker #include "hash.h" 18*0e209d39SAndroid Build Coastguard Worker 19*0e209d39SAndroid Build Coastguard Worker U_NAMESPACE_BEGIN 20*0e209d39SAndroid Build Coastguard Worker 21*0e209d39SAndroid Build Coastguard Worker struct OlsonToMetaMappingEntry : public UMemory { 22*0e209d39SAndroid Build Coastguard Worker const char16_t *mzid; // const because it's a reference to a resource bundle string. 23*0e209d39SAndroid Build Coastguard Worker UDate from; 24*0e209d39SAndroid Build Coastguard Worker UDate to; 25*0e209d39SAndroid Build Coastguard Worker }; 26*0e209d39SAndroid Build Coastguard Worker 27*0e209d39SAndroid Build Coastguard Worker class UVector; 28*0e209d39SAndroid Build Coastguard Worker class TimeZone; 29*0e209d39SAndroid Build Coastguard Worker 30*0e209d39SAndroid Build Coastguard Worker class U_I18N_API ZoneMeta { 31*0e209d39SAndroid Build Coastguard Worker public: 32*0e209d39SAndroid Build Coastguard Worker /** 33*0e209d39SAndroid Build Coastguard Worker * Return the canonical id for this tzid defined by CLDR, which might be the id itself. 34*0e209d39SAndroid Build Coastguard Worker * If the given system tzid is not known, U_ILLEGAL_ARGUMENT_ERROR is set in the status. 35*0e209d39SAndroid Build Coastguard Worker * 36*0e209d39SAndroid Build Coastguard Worker * Note: this internal API supports all known system IDs and "Etc/Unknown" (which is 37*0e209d39SAndroid Build Coastguard Worker * NOT a system ID). 38*0e209d39SAndroid Build Coastguard Worker */ 39*0e209d39SAndroid Build Coastguard Worker static UnicodeString& U_EXPORT2 getCanonicalCLDRID(const UnicodeString &tzid, UnicodeString &systemID, UErrorCode& status); 40*0e209d39SAndroid Build Coastguard Worker 41*0e209d39SAndroid Build Coastguard Worker /** 42*0e209d39SAndroid Build Coastguard Worker * Return the canonical id for this tzid defined by CLDR, which might be the id itself. 43*0e209d39SAndroid Build Coastguard Worker * This overload method returns a persistent const char16_t*, which is guaranteed to persist 44*0e209d39SAndroid Build Coastguard Worker * (a pointer to a resource). If the given system tzid is not known, U_ILLEGAL_ARGUMENT_ERROR 45*0e209d39SAndroid Build Coastguard Worker * is set in the status. 46*0e209d39SAndroid Build Coastguard Worker * @param tzid Zone ID 47*0e209d39SAndroid Build Coastguard Worker * @param status Receives the status 48*0e209d39SAndroid Build Coastguard Worker * @return The canonical ID for the input time zone ID 49*0e209d39SAndroid Build Coastguard Worker */ 50*0e209d39SAndroid Build Coastguard Worker static const char16_t* U_EXPORT2 getCanonicalCLDRID(const UnicodeString &tzid, UErrorCode& status); 51*0e209d39SAndroid Build Coastguard Worker 52*0e209d39SAndroid Build Coastguard Worker /* 53*0e209d39SAndroid Build Coastguard Worker * Convenient method returning CLDR canonical ID for the given time zone 54*0e209d39SAndroid Build Coastguard Worker */ 55*0e209d39SAndroid Build Coastguard Worker static const char16_t* U_EXPORT2 getCanonicalCLDRID(const TimeZone& tz); 56*0e209d39SAndroid Build Coastguard Worker 57*0e209d39SAndroid Build Coastguard Worker /** 58*0e209d39SAndroid Build Coastguard Worker * Returns primary IANA zone ID for the input zone ID, which might be the id itself. 59*0e209d39SAndroid Build Coastguard Worker * If the given system tzid is not known, U_ILLEGAL_ARGUMENT_ERROR is set in the status. 60*0e209d39SAndroid Build Coastguard Worker * 61*0e209d39SAndroid Build Coastguard Worker * @param tzid Zone ID 62*0e209d39SAndroid Build Coastguard Worker * @param ianaID Output IANA ID 63*0e209d39SAndroid Build Coastguard Worker * @param status Receives the status 64*0e209d39SAndroid Build Coastguard Worker * @return A primary IANA zone ID equivalent to the input zone ID. 65*0e209d39SAndroid Build Coastguard Worker */ 66*0e209d39SAndroid Build Coastguard Worker static UnicodeString& U_EXPORT2 getIanaID(const UnicodeString& tzid, UnicodeString& ianaID, UErrorCode& status); 67*0e209d39SAndroid Build Coastguard Worker 68*0e209d39SAndroid Build Coastguard Worker /** 69*0e209d39SAndroid Build Coastguard Worker * Return the canonical country code for this tzid. If we have none, or if the time zone 70*0e209d39SAndroid Build Coastguard Worker * is not associated with a country, return bogus string. 71*0e209d39SAndroid Build Coastguard Worker * @param tzid Zone ID 72*0e209d39SAndroid Build Coastguard Worker * @param country [output] Country code 73*0e209d39SAndroid Build Coastguard Worker * @param isPrimary [output] true if the zone is the primary zone for the country 74*0e209d39SAndroid Build Coastguard Worker * @return A reference to the result country 75*0e209d39SAndroid Build Coastguard Worker */ 76*0e209d39SAndroid Build Coastguard Worker static UnicodeString& U_EXPORT2 getCanonicalCountry(const UnicodeString &tzid, UnicodeString &country, UBool *isPrimary = nullptr); 77*0e209d39SAndroid Build Coastguard Worker 78*0e209d39SAndroid Build Coastguard Worker /** 79*0e209d39SAndroid Build Coastguard Worker * Returns a CLDR metazone ID for the given Olson tzid and time. 80*0e209d39SAndroid Build Coastguard Worker */ 81*0e209d39SAndroid Build Coastguard Worker static UnicodeString& U_EXPORT2 getMetazoneID(const UnicodeString &tzid, UDate date, UnicodeString &result); 82*0e209d39SAndroid Build Coastguard Worker /** 83*0e209d39SAndroid Build Coastguard Worker * Returns an Olson ID for the ginve metazone and region 84*0e209d39SAndroid Build Coastguard Worker */ 85*0e209d39SAndroid Build Coastguard Worker static UnicodeString& U_EXPORT2 getZoneIdByMetazone(const UnicodeString &mzid, const UnicodeString ®ion, UnicodeString &result); 86*0e209d39SAndroid Build Coastguard Worker 87*0e209d39SAndroid Build Coastguard Worker static const UVector* U_EXPORT2 getMetazoneMappings(const UnicodeString &tzid); 88*0e209d39SAndroid Build Coastguard Worker 89*0e209d39SAndroid Build Coastguard Worker static const UVector* U_EXPORT2 getAvailableMetazoneIDs(); 90*0e209d39SAndroid Build Coastguard Worker 91*0e209d39SAndroid Build Coastguard Worker /** 92*0e209d39SAndroid Build Coastguard Worker * Returns the pointer to the persistent time zone ID string, or nullptr if the given tzid is not in the 93*0e209d39SAndroid Build Coastguard Worker * tz database. This method is useful when you maintain persistent zone IDs without duplication. 94*0e209d39SAndroid Build Coastguard Worker */ 95*0e209d39SAndroid Build Coastguard Worker static const char16_t* U_EXPORT2 findTimeZoneID(const UnicodeString& tzid); 96*0e209d39SAndroid Build Coastguard Worker 97*0e209d39SAndroid Build Coastguard Worker /** 98*0e209d39SAndroid Build Coastguard Worker * Returns the pointer to the persistent meta zone ID string, or nullptr if the given mzid is not available. 99*0e209d39SAndroid Build Coastguard Worker * This method is useful when you maintain persistent meta zone IDs without duplication. 100*0e209d39SAndroid Build Coastguard Worker */ 101*0e209d39SAndroid Build Coastguard Worker static const char16_t* U_EXPORT2 findMetaZoneID(const UnicodeString& mzid); 102*0e209d39SAndroid Build Coastguard Worker 103*0e209d39SAndroid Build Coastguard Worker /** 104*0e209d39SAndroid Build Coastguard Worker * Creates a custom zone for the offset 105*0e209d39SAndroid Build Coastguard Worker * @param offset GMT offset in milliseconds 106*0e209d39SAndroid Build Coastguard Worker * @return A custom TimeZone for the offset with normalized time zone id 107*0e209d39SAndroid Build Coastguard Worker */ 108*0e209d39SAndroid Build Coastguard Worker static TimeZone* createCustomTimeZone(int32_t offset); 109*0e209d39SAndroid Build Coastguard Worker 110*0e209d39SAndroid Build Coastguard Worker /** 111*0e209d39SAndroid Build Coastguard Worker * Returns the time zone's short ID (null terminated) for the zone. 112*0e209d39SAndroid Build Coastguard Worker * For example, "uslax" for zone "America/Los_Angeles". 113*0e209d39SAndroid Build Coastguard Worker * @param tz the time zone 114*0e209d39SAndroid Build Coastguard Worker * @return the short ID of the time zone, or null if the short ID is not available. 115*0e209d39SAndroid Build Coastguard Worker */ 116*0e209d39SAndroid Build Coastguard Worker static const char16_t* U_EXPORT2 getShortID(const TimeZone& tz); 117*0e209d39SAndroid Build Coastguard Worker 118*0e209d39SAndroid Build Coastguard Worker /** 119*0e209d39SAndroid Build Coastguard Worker * Returns the time zone's short ID (null terminated) for the zone ID. 120*0e209d39SAndroid Build Coastguard Worker * For example, "uslax" for zone ID "America/Los_Angeles". 121*0e209d39SAndroid Build Coastguard Worker * @param tz the time zone ID 122*0e209d39SAndroid Build Coastguard Worker * @return the short ID of the time zone ID, or null if the short ID is not available. 123*0e209d39SAndroid Build Coastguard Worker */ 124*0e209d39SAndroid Build Coastguard Worker static const char16_t* U_EXPORT2 getShortID(const UnicodeString& id); 125*0e209d39SAndroid Build Coastguard Worker 126*0e209d39SAndroid Build Coastguard Worker private: 127*0e209d39SAndroid Build Coastguard Worker ZoneMeta() = delete; // Prevent construction. 128*0e209d39SAndroid Build Coastguard Worker static UVector* createMetazoneMappings(const UnicodeString &tzid); 129*0e209d39SAndroid Build Coastguard Worker static UnicodeString& formatCustomID(uint8_t hour, uint8_t min, uint8_t sec, UBool negative, UnicodeString& id); 130*0e209d39SAndroid Build Coastguard Worker static const char16_t* getShortIDFromCanonical(const char16_t* canonicalID); 131*0e209d39SAndroid Build Coastguard Worker }; 132*0e209d39SAndroid Build Coastguard Worker 133*0e209d39SAndroid Build Coastguard Worker U_NAMESPACE_END 134*0e209d39SAndroid Build Coastguard Worker 135*0e209d39SAndroid Build Coastguard Worker #endif /* #if !UCONFIG_NO_FORMATTING */ 136*0e209d39SAndroid Build Coastguard Worker #endif // ZONEMETA_H 137