basictz.h 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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 BASICTZ_H
  10. #define BASICTZ_H
  11. /**
  12. * \file
  13. * \brief C++ API: ICU TimeZone base class
  14. */
  15. #include "unicode/utypes.h"
  16. #if U_SHOW_CPLUSPLUS_API
  17. #if !UCONFIG_NO_FORMATTING
  18. #include "unicode/timezone.h"
  19. #include "unicode/tzrule.h"
  20. #include "unicode/tztrans.h"
  21. U_NAMESPACE_BEGIN
  22. // forward declarations
  23. class UVector;
  24. /**
  25. * <code>BasicTimeZone</code> is an abstract class extending <code>TimeZone</code>.
  26. * This class provides some additional methods to access time zone transitions and rules.
  27. * All ICU <code>TimeZone</code> concrete subclasses extend this class.
  28. * @stable ICU 3.8
  29. */
  30. class U_I18N_API BasicTimeZone: public TimeZone {
  31. public:
  32. /**
  33. * Destructor.
  34. * @stable ICU 3.8
  35. */
  36. virtual ~BasicTimeZone();
  37. /**
  38. * Clones this object polymorphically.
  39. * The caller owns the result and should delete it when done.
  40. * @return clone, or nullptr if an error occurred
  41. * @stable ICU 3.8
  42. */
  43. virtual BasicTimeZone* clone() const override = 0;
  44. /**
  45. * Gets the first time zone transition after the base time.
  46. * @param base The base time.
  47. * @param inclusive Whether the base time is inclusive or not.
  48. * @param result Receives the first transition after the base time.
  49. * @return true if the transition is found.
  50. * @stable ICU 3.8
  51. */
  52. virtual UBool getNextTransition(UDate base, UBool inclusive, TimeZoneTransition& result) const = 0;
  53. /**
  54. * Gets the most recent time zone transition before the base time.
  55. * @param base The base time.
  56. * @param inclusive Whether the base time is inclusive or not.
  57. * @param result Receives the most recent transition before the base time.
  58. * @return true if the transition is found.
  59. * @stable ICU 3.8
  60. */
  61. virtual UBool getPreviousTransition(UDate base, UBool inclusive, TimeZoneTransition& result) const = 0;
  62. /**
  63. * Checks if the time zone has equivalent transitions in the time range.
  64. * This method returns true when all of transition times, from/to standard
  65. * offsets and DST savings used by this time zone match the other in the
  66. * time range.
  67. * @param tz The <code>BasicTimeZone</code> object to be compared with.
  68. * @param start The start time of the evaluated time range (inclusive)
  69. * @param end The end time of the evaluated time range (inclusive)
  70. * @param ignoreDstAmount
  71. * When true, any transitions with only daylight saving amount
  72. * changes will be ignored, except either of them is zero.
  73. * For example, a transition from rawoffset 3:00/dstsavings 1:00
  74. * to rawoffset 2:00/dstsavings 2:00 is excluded from the comparison,
  75. * but a transition from rawoffset 2:00/dstsavings 1:00 to
  76. * rawoffset 3:00/dstsavings 0:00 is included.
  77. * @param ec Output param to filled in with a success or an error.
  78. * @return true if the other time zone has the equivalent transitions in the
  79. * time range.
  80. * @stable ICU 3.8
  81. */
  82. virtual UBool hasEquivalentTransitions(const BasicTimeZone& tz, UDate start, UDate end,
  83. UBool ignoreDstAmount, UErrorCode& ec) const;
  84. /**
  85. * Returns the number of <code>TimeZoneRule</code>s which represents time transitions,
  86. * for this time zone, that is, all <code>TimeZoneRule</code>s for this time zone except
  87. * <code>InitialTimeZoneRule</code>. The return value range is 0 or any positive value.
  88. * @param status Receives error status code.
  89. * @return The number of <code>TimeZoneRule</code>s representing time transitions.
  90. * @stable ICU 3.8
  91. */
  92. virtual int32_t countTransitionRules(UErrorCode& status) const = 0;
  93. /**
  94. * Gets the <code>InitialTimeZoneRule</code> and the set of <code>TimeZoneRule</code>
  95. * which represent time transitions for this time zone. On successful return,
  96. * the argument initial points to non-nullptr <code>InitialTimeZoneRule</code> and
  97. * the array trsrules is filled with 0 or multiple <code>TimeZoneRule</code>
  98. * instances up to the size specified by trscount. The results are referencing the
  99. * rule instance held by this time zone instance. Therefore, after this time zone
  100. * is destructed, they are no longer available.
  101. * @param initial Receives the initial timezone rule
  102. * @param trsrules Receives the timezone transition rules
  103. * @param trscount On input, specify the size of the array 'transitions' receiving
  104. * the timezone transition rules. On output, actual number of
  105. * rules filled in the array will be set.
  106. * @param status Receives error status code.
  107. * @stable ICU 3.8
  108. */
  109. virtual void getTimeZoneRules(const InitialTimeZoneRule*& initial,
  110. const TimeZoneRule* trsrules[], int32_t& trscount, UErrorCode& status) const = 0;
  111. /**
  112. * Gets the set of time zone rules valid at the specified time. Some known external time zone
  113. * implementations are not capable to handle historic time zone rule changes. Also some
  114. * implementations can only handle certain type of rule definitions.
  115. * If this time zone does not use any daylight saving time within about 1 year from the specified
  116. * time, only the <code>InitialTimeZone</code> is returned. Otherwise, the rule for standard
  117. * time and daylight saving time transitions are returned in addition to the
  118. * <code>InitialTimeZoneRule</code>. The standard and daylight saving time transition rules are
  119. * represented by <code>AnnualTimeZoneRule</code> with <code>DateTimeRule::DOW</code> for its date
  120. * rule and <code>DateTimeRule::WALL_TIME</code> for its time rule. Because daylight saving time
  121. * rule is changing time to time in many time zones and also mapping a transition time rule to
  122. * different type is lossy transformation, the set of rules returned by this method may be valid
  123. * for short period of time.
  124. * The time zone rule objects returned by this method is owned by the caller, so the caller is
  125. * responsible for deleting them after use.
  126. * @param date The date used for extracting time zone rules.
  127. * @param initial Receives the <code>InitialTimeZone</code>, always not nullptr.
  128. * @param std Receives the <code>AnnualTimeZoneRule</code> for standard time transitions.
  129. * When this time time zone does not observe daylight saving times around the
  130. * specified date, nullptr is set.
  131. * @param dst Receives the <code>AnnualTimeZoneRule</code> for daylight saving time
  132. * transitions. When this time zone does not observer daylight saving times
  133. * around the specified date, nullptr is set.
  134. * @param status Receives error status code.
  135. * @stable ICU 3.8
  136. */
  137. virtual void getSimpleRulesNear(UDate date, InitialTimeZoneRule*& initial,
  138. AnnualTimeZoneRule*& std, AnnualTimeZoneRule*& dst, UErrorCode& status) const;
  139. /**
  140. * Get time zone offsets from local wall time.
  141. * @stable ICU 69
  142. */
  143. virtual void getOffsetFromLocal(
  144. UDate date, UTimeZoneLocalOption nonExistingTimeOpt,
  145. UTimeZoneLocalOption duplicatedTimeOpt, int32_t& rawOffset,
  146. int32_t& dstOffset, UErrorCode& status) const;
  147. #ifndef U_HIDE_INTERNAL_API
  148. /**
  149. * The time type option bit flags used by getOffsetFromLocal
  150. * @internal
  151. */
  152. enum {
  153. kStandard = 0x01,
  154. kDaylight = 0x03,
  155. kFormer = 0x04, /* UCAL_TZ_LOCAL_FORMER */
  156. kLatter = 0x0C /* UCAL_TZ_LOCAL_LATTER */
  157. };
  158. /**
  159. * Get time zone offsets from local wall time.
  160. * @internal
  161. */
  162. void getOffsetFromLocal(UDate date, int32_t nonExistingTimeOpt, int32_t duplicatedTimeOpt,
  163. int32_t& rawOffset, int32_t& dstOffset, UErrorCode& status) const;
  164. #endif /* U_HIDE_INTERNAL_API */
  165. protected:
  166. #ifndef U_HIDE_INTERNAL_API
  167. /**
  168. * A time type option bit mask used by getOffsetFromLocal.
  169. * @internal
  170. */
  171. static constexpr int32_t kStdDstMask = kDaylight;
  172. /**
  173. * A time type option bit mask used by getOffsetFromLocal.
  174. * @internal
  175. */
  176. static constexpr int32_t kFormerLatterMask = kLatter;
  177. #endif /* U_HIDE_INTERNAL_API */
  178. /**
  179. * Default constructor.
  180. * @stable ICU 3.8
  181. */
  182. BasicTimeZone();
  183. /**
  184. * Construct a timezone with a given ID.
  185. * @param id a system time zone ID
  186. * @stable ICU 3.8
  187. */
  188. BasicTimeZone(const UnicodeString &id);
  189. /**
  190. * Copy constructor.
  191. * @param source the object to be copied.
  192. * @stable ICU 3.8
  193. */
  194. BasicTimeZone(const BasicTimeZone& source);
  195. /**
  196. * Copy assignment.
  197. * @stable ICU 3.8
  198. */
  199. BasicTimeZone& operator=(const BasicTimeZone&) = default;
  200. /**
  201. * Gets the set of TimeZoneRule instances applicable to the specified time and after.
  202. * @param start The start date used for extracting time zone rules
  203. * @param initial Output parameter, receives the InitialTimeZone.
  204. * Always not nullptr (except in case of error)
  205. * @param transitionRules Output parameter, a UVector of transition rules.
  206. * May be nullptr, if there are no transition rules.
  207. * The caller owns the returned vector; the UVector owns the rules.
  208. * @param status Receives error status code
  209. */
  210. void getTimeZoneRulesAfter(UDate start, InitialTimeZoneRule*& initial, UVector*& transitionRules,
  211. UErrorCode& status) const;
  212. };
  213. U_NAMESPACE_END
  214. #endif /* #if !UCONFIG_NO_FORMATTING */
  215. #endif /* U_SHOW_CPLUSPLUS_API */
  216. #endif // BASICTZ_H
  217. //eof