zonemeta.h 4.9 KB

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