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