basictz.h 8.9 KB

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