jpayne@69: // © 2016 and later: Unicode, Inc. and others.
jpayne@69: // License & terms of use: http://www.unicode.org/copyright.html
jpayne@69: /*
jpayne@69: *******************************************************************************
jpayne@69: * Copyright (C) 2011-2016, International Business Machines Corporation and
jpayne@69: * others. All Rights Reserved.
jpayne@69: *******************************************************************************
jpayne@69: */
jpayne@69: #ifndef __TZNAMES_H
jpayne@69: #define __TZNAMES_H
jpayne@69:
jpayne@69: /**
jpayne@69: * \file
jpayne@69: * \brief C++ API: TimeZoneNames
jpayne@69: */
jpayne@69: #include "unicode/utypes.h"
jpayne@69:
jpayne@69: #if U_SHOW_CPLUSPLUS_API
jpayne@69:
jpayne@69: #if !UCONFIG_NO_FORMATTING
jpayne@69:
jpayne@69: #include "unicode/uloc.h"
jpayne@69: #include "unicode/unistr.h"
jpayne@69:
jpayne@69: U_CDECL_BEGIN
jpayne@69:
jpayne@69: /**
jpayne@69: * Constants for time zone display name types.
jpayne@69: * @stable ICU 50
jpayne@69: */
jpayne@69: typedef enum UTimeZoneNameType {
jpayne@69: /**
jpayne@69: * Unknown display name type.
jpayne@69: * @stable ICU 50
jpayne@69: */
jpayne@69: UTZNM_UNKNOWN = 0x00,
jpayne@69: /**
jpayne@69: * Long display name, such as "Eastern Time".
jpayne@69: * @stable ICU 50
jpayne@69: */
jpayne@69: UTZNM_LONG_GENERIC = 0x01,
jpayne@69: /**
jpayne@69: * Long display name for standard time, such as "Eastern Standard Time".
jpayne@69: * @stable ICU 50
jpayne@69: */
jpayne@69: UTZNM_LONG_STANDARD = 0x02,
jpayne@69: /**
jpayne@69: * Long display name for daylight saving time, such as "Eastern Daylight Time".
jpayne@69: * @stable ICU 50
jpayne@69: */
jpayne@69: UTZNM_LONG_DAYLIGHT = 0x04,
jpayne@69: /**
jpayne@69: * Short display name, such as "ET".
jpayne@69: * @stable ICU 50
jpayne@69: */
jpayne@69: UTZNM_SHORT_GENERIC = 0x08,
jpayne@69: /**
jpayne@69: * Short display name for standard time, such as "EST".
jpayne@69: * @stable ICU 50
jpayne@69: */
jpayne@69: UTZNM_SHORT_STANDARD = 0x10,
jpayne@69: /**
jpayne@69: * Short display name for daylight saving time, such as "EDT".
jpayne@69: * @stable ICU 50
jpayne@69: */
jpayne@69: UTZNM_SHORT_DAYLIGHT = 0x20,
jpayne@69: /**
jpayne@69: * Exemplar location name, such as "Los Angeles".
jpayne@69: * @stable ICU 51
jpayne@69: */
jpayne@69: UTZNM_EXEMPLAR_LOCATION = 0x40
jpayne@69: } UTimeZoneNameType;
jpayne@69:
jpayne@69: U_CDECL_END
jpayne@69:
jpayne@69: U_NAMESPACE_BEGIN
jpayne@69:
jpayne@69: class UVector;
jpayne@69: struct MatchInfo;
jpayne@69:
jpayne@69: /**
jpayne@69: * TimeZoneNames
is an abstract class representing the time zone display name data model defined
jpayne@69: * by UTS#35 Unicode Locale Data Markup Language (LDML).
jpayne@69: * The model defines meta zone, which is used for storing a set of display names. A meta zone can be shared
jpayne@69: * by multiple time zones. Also a time zone may have multiple meta zone historic mappings.
jpayne@69: *
jpayne@69: * For example, people in the United States refer the zone used by the east part of North America as "Eastern Time". jpayne@69: * The tz database contains multiple time zones "America/New_York", "America/Detroit", "America/Montreal" and some jpayne@69: * others that belong to "Eastern Time". However, assigning different display names to these time zones does not make jpayne@69: * much sense for most of people. jpayne@69: *
jpayne@69: * In CLDR (which uses LDML for representing locale data), the display name jpayne@69: * "Eastern Time" is stored as long generic display name of a meta zone identified by the ID "America_Eastern". jpayne@69: * Then, there is another table maintaining the historic mapping to meta zones for each time zone. The time zones in jpayne@69: * the above example ("America/New_York", "America/Detroit"...) are mapped to the meta zone "America_Eastern". jpayne@69: *
jpayne@69: * Sometimes, a time zone is mapped to a different time zone in the past. For example, "America/Indiana/Knox" jpayne@69: * had been moving "Eastern Time" and "Central Time" back and forth. Therefore, it is necessary that time zone jpayne@69: * to meta zones mapping data are stored by date range. jpayne@69: * jpayne@69: *
Note: jpayne@69: * The methods in this class assume that time zone IDs are already canonicalized. For example, you may not get proper jpayne@69: * result returned by a method with time zone ID "America/Indiana/Indianapolis", because it's not a canonical time zone jpayne@69: * ID (the canonical time zone ID for the time zone is "America/Indianapolis". See jpayne@69: * {@link TimeZone#getCanonicalID(const UnicodeString& id, UnicodeString& canonicalID, UErrorCode& status)} about ICU jpayne@69: * canonical time zone IDs. jpayne@69: * jpayne@69: *
jpayne@69: * In CLDR, most of time zone display names except location names are provided through meta zones. But a time zone may jpayne@69: * have a specific name that is not shared with other time zones. jpayne@69: * jpayne@69: * For example, time zone "Europe/London" has English long name for standard time "Greenwich Mean Time", which is also jpayne@69: * shared with other time zones. However, the long name for daylight saving time is "British Summer Time", which is only jpayne@69: * used for "Europe/London". jpayne@69: * jpayne@69: *
jpayne@69: * {@link #getTimeZoneDisplayName} is designed for accessing a name only used by a single time zone. jpayne@69: * But is not necessarily mean that a subclass implementation use the same model with CLDR. A subclass implementation jpayne@69: * may provide time zone names only through {@link #getTimeZoneDisplayName}, or only through {@link #getMetaZoneDisplayName}, jpayne@69: * or both. jpayne@69: * jpayne@69: *
jpayne@69: * The default TimeZoneNames
implementation returned by {@link #createInstance}
jpayne@69: * uses the locale data imported from CLDR. In CLDR, set of meta zone IDs and mappings between zone IDs and meta zone
jpayne@69: * IDs are shared by all locales. Therefore, the behavior of {@link #getAvailableMetaZoneIDs},
jpayne@69: * {@link #getMetaZoneID}, and {@link #getReferenceZoneID} won't be changed no matter
jpayne@69: * what locale is used for getting an instance of TimeZoneNames
.
jpayne@69: *
jpayne@69: * @stable ICU 50
jpayne@69: */
jpayne@69: class U_I18N_API TimeZoneNames : public UObject {
jpayne@69: public:
jpayne@69: /**
jpayne@69: * Destructor.
jpayne@69: * @stable ICU 50
jpayne@69: */
jpayne@69: virtual ~TimeZoneNames();
jpayne@69:
jpayne@69: /**
jpayne@69: * Return true if the given TimeZoneNames objects are semantically equal.
jpayne@69: * @param other the object to be compared with.
jpayne@69: * @return Return TRUE if the given Format objects are semantically equal.
jpayne@69: * @stable ICU 50
jpayne@69: */
jpayne@69: virtual UBool operator==(const TimeZoneNames& other) const = 0;
jpayne@69:
jpayne@69: /**
jpayne@69: * Return true if the given TimeZoneNames objects are not semantically
jpayne@69: * equal.
jpayne@69: * @param other the object to be compared with.
jpayne@69: * @return Return TRUE if the given Format objects are not semantically equal.
jpayne@69: * @stable ICU 50
jpayne@69: */
jpayne@69: UBool operator!=(const TimeZoneNames& other) const { return !operator==(other); }
jpayne@69:
jpayne@69: /**
jpayne@69: * Clone this object polymorphically. The caller is responsible
jpayne@69: * for deleting the result when done.
jpayne@69: * @return A copy of the object
jpayne@69: * @stable ICU 50
jpayne@69: */
jpayne@69: virtual TimeZoneNames* clone() const = 0;
jpayne@69:
jpayne@69: /**
jpayne@69: * Returns an instance of TimeZoneNames
for the specified locale.
jpayne@69: *
jpayne@69: * @param locale The locale.
jpayne@69: * @param status Receives the status.
jpayne@69: * @return An instance of TimeZoneNames
jpayne@69: * @stable ICU 50
jpayne@69: */
jpayne@69: static TimeZoneNames* U_EXPORT2 createInstance(const Locale& locale, UErrorCode& status);
jpayne@69:
jpayne@69: /**
jpayne@69: * Returns an instance of TimeZoneNames
containing only short specific
jpayne@69: * zone names (SHORT_STANDARD and SHORT_DAYLIGHT),
jpayne@69: * compatible with the IANA tz database's zone abbreviations (not localized).
jpayne@69: *
jpayne@69: * Note: The input locale is used for resolving ambiguous names (e.g. "IST" is parsed
jpayne@69: * as Israel Standard Time for Israel, while it is parsed as India Standard Time for
jpayne@69: * all other regions). The zone names returned by this instance are not localized.
jpayne@69: * @stable ICU 54
jpayne@69: */
jpayne@69: static TimeZoneNames* U_EXPORT2 createTZDBInstance(const Locale& locale, UErrorCode& status);
jpayne@69:
jpayne@69: /**
jpayne@69: * Returns an enumeration of all available meta zone IDs.
jpayne@69: * @param status Receives the status.
jpayne@69: * @return an enumeration object, owned by the caller.
jpayne@69: * @stable ICU 50
jpayne@69: */
jpayne@69: virtual StringEnumeration* getAvailableMetaZoneIDs(UErrorCode& status) const = 0;
jpayne@69:
jpayne@69: /**
jpayne@69: * Returns an enumeration of all available meta zone IDs used by the given time zone.
jpayne@69: * @param tzID The canoical tiem zone ID.
jpayne@69: * @param status Receives the status.
jpayne@69: * @return an enumeration object, owned by the caller.
jpayne@69: * @stable ICU 50
jpayne@69: */
jpayne@69: virtual StringEnumeration* getAvailableMetaZoneIDs(const UnicodeString& tzID, UErrorCode& status) const = 0;
jpayne@69:
jpayne@69: /**
jpayne@69: * Returns the meta zone ID for the given canonical time zone ID at the given date.
jpayne@69: * @param tzID The canonical time zone ID.
jpayne@69: * @param date The date.
jpayne@69: * @param mzID Receives the meta zone ID for the given time zone ID at the given date. If the time zone does not have a
jpayne@69: * corresponding meta zone at the given date or the implementation does not support meta zones, "bogus" state
jpayne@69: * is set.
jpayne@69: * @return A reference to the result.
jpayne@69: * @stable ICU 50
jpayne@69: */
jpayne@69: virtual UnicodeString& getMetaZoneID(const UnicodeString& tzID, UDate date, UnicodeString& mzID) const = 0;
jpayne@69:
jpayne@69: /**
jpayne@69: * Returns the reference zone ID for the given meta zone ID for the region.
jpayne@69: *
jpayne@69: * Note: Each meta zone must have a reference zone associated with a special region "001" (world).
jpayne@69: * Some meta zones may have region specific reference zone IDs other than the special region
jpayne@69: * "001". When a meta zone does not have any region specific reference zone IDs, this method
jpayne@69: * return the reference zone ID for the special region "001" (world).
jpayne@69: *
jpayne@69: * @param mzID The meta zone ID.
jpayne@69: * @param region The region.
jpayne@69: * @param tzID Receives the reference zone ID ("golden zone" in the LDML specification) for the given time zone ID for the
jpayne@69: * region. If the meta zone is unknown or the implementation does not support meta zones, "bogus" state
jpayne@69: * is set.
jpayne@69: * @return A reference to the result.
jpayne@69: * @stable ICU 50
jpayne@69: */
jpayne@69: virtual UnicodeString& getReferenceZoneID(const UnicodeString& mzID, const char* region, UnicodeString& tzID) const = 0;
jpayne@69:
jpayne@69: /**
jpayne@69: * Returns the display name of the meta zone.
jpayne@69: * @param mzID The meta zone ID.
jpayne@69: * @param type The display name type. See {@link #UTimeZoneNameType}.
jpayne@69: * @param name Receives the display name of the meta zone. When this object does not have a localized display name for the given
jpayne@69: * meta zone with the specified type or the implementation does not provide any display names associated
jpayne@69: * with meta zones, "bogus" state is set.
jpayne@69: * @return A reference to the result.
jpayne@69: * @stable ICU 50
jpayne@69: */
jpayne@69: virtual UnicodeString& getMetaZoneDisplayName(const UnicodeString& mzID, UTimeZoneNameType type, UnicodeString& name) const = 0;
jpayne@69:
jpayne@69: /**
jpayne@69: * Returns the display name of the time zone. Unlike {@link #getDisplayName},
jpayne@69: * this method does not get a name from a meta zone used by the time zone.
jpayne@69: * @param tzID The canonical time zone ID.
jpayne@69: * @param type The display name type. See {@link #UTimeZoneNameType}.
jpayne@69: * @param name Receives the display name for the time zone. When this object does not have a localized display name for the given
jpayne@69: * time zone with the specified type, "bogus" state is set.
jpayne@69: * @return A reference to the result.
jpayne@69: * @stable ICU 50
jpayne@69: */
jpayne@69: virtual UnicodeString& getTimeZoneDisplayName(const UnicodeString& tzID, UTimeZoneNameType type, UnicodeString& name) const = 0;
jpayne@69:
jpayne@69: /**
jpayne@69: * Returns the exemplar location name for the given time zone. When this object does not have a localized location
jpayne@69: * name, the default implementation may still returns a programmatically generated name with the logic described
jpayne@69: * below.
jpayne@69: *
jpayne@69: * Note: This method calls the subclass's {@link #getTimeZoneDisplayName} first. When the
jpayne@69: * result is bogus, this method calls {@link #getMetaZoneID} to get the meta zone ID mapped from the
jpayne@69: * time zone, then calls {@link #getMetaZoneDisplayName}.
jpayne@69: *
jpayne@69: * @param tzID The canonical time zone ID.
jpayne@69: * @param type The display name type. See {@link #UTimeZoneNameType}.
jpayne@69: * @param date The date.
jpayne@69: * @param name Receives the display name for the time zone at the given date. When this object does not have a localized display
jpayne@69: * name for the time zone with the specified type and date, "bogus" state is set.
jpayne@69: * @return A reference to the result.
jpayne@69: * @stable ICU 50
jpayne@69: */
jpayne@69: virtual UnicodeString& getDisplayName(const UnicodeString& tzID, UTimeZoneNameType type, UDate date, UnicodeString& name) const;
jpayne@69:
jpayne@69: /**
jpayne@69: * @internal ICU internal only, for specific users only until proposed publicly.
jpayne@69: */
jpayne@69: virtual void loadAllDisplayNames(UErrorCode& status);
jpayne@69:
jpayne@69: /**
jpayne@69: * @internal ICU internal only, for specific users only until proposed publicly.
jpayne@69: */
jpayne@69: virtual void getDisplayNames(const UnicodeString& tzID, const UTimeZoneNameType types[], int32_t numTypes, UDate date, UnicodeString dest[], UErrorCode& status) const;
jpayne@69:
jpayne@69: /**
jpayne@69: * MatchInfoCollection
represents a collection of time zone name matches used by
jpayne@69: * {@link TimeZoneNames#find}.
jpayne@69: * @internal
jpayne@69: */
jpayne@69: class U_I18N_API MatchInfoCollection : public UMemory {
jpayne@69: public:
jpayne@69: /**
jpayne@69: * Constructor.
jpayne@69: * @internal
jpayne@69: */
jpayne@69: MatchInfoCollection();
jpayne@69: /**
jpayne@69: * Destructor.
jpayne@69: * @internal
jpayne@69: */
jpayne@69: virtual ~MatchInfoCollection();
jpayne@69:
jpayne@69: #ifndef U_HIDE_INTERNAL_API
jpayne@69: /**
jpayne@69: * Adds a zone match.
jpayne@69: * @param nameType The name type.
jpayne@69: * @param matchLength The match length.
jpayne@69: * @param tzID The time zone ID.
jpayne@69: * @param status Receives the status
jpayne@69: * @internal
jpayne@69: */
jpayne@69: void addZone(UTimeZoneNameType nameType, int32_t matchLength,
jpayne@69: const UnicodeString& tzID, UErrorCode& status);
jpayne@69:
jpayne@69: /**
jpayne@69: * Adds a meata zone match.
jpayne@69: * @param nameType The name type.
jpayne@69: * @param matchLength The match length.
jpayne@69: * @param mzID The metazone ID.
jpayne@69: * @param status Receives the status
jpayne@69: * @internal
jpayne@69: */
jpayne@69: void addMetaZone(UTimeZoneNameType nameType, int32_t matchLength,
jpayne@69: const UnicodeString& mzID, UErrorCode& status);
jpayne@69:
jpayne@69: /**
jpayne@69: * Returns the number of entries available in this object.
jpayne@69: * @return The number of entries.
jpayne@69: * @internal
jpayne@69: */
jpayne@69: int32_t size() const;
jpayne@69:
jpayne@69: /**
jpayne@69: * Returns the time zone name type of a match at the specified index.
jpayne@69: * @param idx The index
jpayne@69: * @return The time zone name type. If the specified idx is out of range,
jpayne@69: * it returns UTZNM_UNKNOWN.
jpayne@69: * @see UTimeZoneNameType
jpayne@69: * @internal
jpayne@69: */
jpayne@69: UTimeZoneNameType getNameTypeAt(int32_t idx) const;
jpayne@69:
jpayne@69: /**
jpayne@69: * Returns the match length of a match at the specified index.
jpayne@69: * @param idx The index
jpayne@69: * @return The match length. If the specified idx is out of range,
jpayne@69: * it returns 0.
jpayne@69: * @internal
jpayne@69: */
jpayne@69: int32_t getMatchLengthAt(int32_t idx) const;
jpayne@69:
jpayne@69: /**
jpayne@69: * Gets the zone ID of a match at the specified index.
jpayne@69: * @param idx The index
jpayne@69: * @param tzID Receives the zone ID.
jpayne@69: * @return TRUE if the zone ID was set to tzID.
jpayne@69: * @internal
jpayne@69: */
jpayne@69: UBool getTimeZoneIDAt(int32_t idx, UnicodeString& tzID) const;
jpayne@69:
jpayne@69: /**
jpayne@69: * Gets the metazone ID of a match at the specified index.
jpayne@69: * @param idx The index
jpayne@69: * @param mzID Receives the metazone ID
jpayne@69: * @return TRUE if the meta zone ID was set to mzID.
jpayne@69: * @internal
jpayne@69: */
jpayne@69: UBool getMetaZoneIDAt(int32_t idx, UnicodeString& mzID) const;
jpayne@69: #endif /* U_HIDE_INTERNAL_API */
jpayne@69:
jpayne@69: private:
jpayne@69: UVector* fMatches; // vector of MatchEntry
jpayne@69:
jpayne@69: UVector* matches(UErrorCode& status);
jpayne@69: };
jpayne@69:
jpayne@69: /**
jpayne@69: * Finds time zone name prefix matches for the input text at the
jpayne@69: * given offset and returns a collection of the matches.
jpayne@69: * @param text The text.
jpayne@69: * @param start The starting offset within the text.
jpayne@69: * @param types The set of name types represented by bitwise flags of UTimeZoneNameType enums,
jpayne@69: * or UTZNM_UNKNOWN for all name types.
jpayne@69: * @param status Receives the status.
jpayne@69: * @return A collection of matches (owned by the caller), or NULL if no matches are found.
jpayne@69: * @see UTimeZoneNameType
jpayne@69: * @see MatchInfoCollection
jpayne@69: * @internal
jpayne@69: */
jpayne@69: virtual MatchInfoCollection* find(const UnicodeString& text, int32_t start, uint32_t types, UErrorCode& status) const = 0;
jpayne@69: };
jpayne@69:
jpayne@69: U_NAMESPACE_END
jpayne@69:
jpayne@69: #endif
jpayne@69:
jpayne@69: #endif /* U_SHOW_CPLUSPLUS_API */
jpayne@69:
jpayne@69: #endif