basictz.h 8.7 KB

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