]>
git.saurik.com Git - apple/icu.git/blob - icuSources/i18n/unicode/vtzone.h
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 *******************************************************************************
5 * Copyright (C) 2007-2013, International Business Machines Corporation and
6 * others. All Rights Reserved.
7 *******************************************************************************
12 #include "unicode/utypes.h"
16 * \brief C++ API: RFC2445 VTIMEZONE support
19 #if !UCONFIG_NO_FORMATTING
21 #include "unicode/basictz.h"
23 #if U_SHOW_CPLUSPLUS_API
31 * <code>VTimeZone</code> is a class implementing RFC2445 VTIMEZONE. You can create a
32 * <code>VTimeZone</code> instance from a time zone ID supported by <code>TimeZone</code>.
33 * With the <code>VTimeZone</code> instance created from the ID, you can write out the rule
34 * in RFC2445 VTIMEZONE format. Also, you can create a <code>VTimeZone</code> instance
35 * from RFC2445 VTIMEZONE data stream, which allows you to calculate time
36 * zone offset by the rules defined by the data. Or, you can create a
37 * <code>VTimeZone</code> from any other ICU <code>BasicTimeZone</code>.
39 * Note: The consumer of this class reading or writing VTIMEZONE data is responsible to
40 * decode or encode Non-ASCII text. Methods reading/writing VTIMEZONE data in this class
41 * do nothing with MIME encoding.
44 class U_I18N_API VTimeZone
: public BasicTimeZone
{
48 * @param source The <code>VTimeZone</code> object to be copied.
51 VTimeZone(const VTimeZone
& source
);
60 * Assignment operator.
61 * @param right The object to be copied.
64 VTimeZone
& operator=(const VTimeZone
& right
);
67 * Return true if the given <code>TimeZone</code> objects are
68 * semantically equal. Objects of different subclasses are considered unequal.
69 * @param that The object to be compared with.
70 * @return true if the given <code>TimeZone</code> objects are
74 virtual UBool
operator==(const TimeZone
& that
) const;
77 * Return true if the given <code>TimeZone</code> objects are
78 * semantically unequal. Objects of different subclasses are considered unequal.
79 * @param that The object to be compared with.
80 * @return true if the given <code>TimeZone</code> objects are
81 * semantically unequal.
84 virtual UBool
operator!=(const TimeZone
& that
) const;
87 * Create a <code>VTimeZone</code> instance by the time zone ID.
88 * @param ID The time zone ID, such as America/New_York
89 * @return A <code>VTimeZone</code> object initialized by the time zone ID,
90 * or NULL when the ID is unknown.
93 static VTimeZone
* createVTimeZoneByID(const UnicodeString
& ID
);
96 * Create a <code>VTimeZone</code> instance using a basic time zone.
97 * @param basicTZ The basic time zone instance
98 * @param status Output param to filled in with a success or an error.
99 * @return A <code>VTimeZone</code> object initialized by the basic time zone.
102 static VTimeZone
* createVTimeZoneFromBasicTimeZone(const BasicTimeZone
& basicTZ
,
106 * Create a <code>VTimeZone</code> instance by RFC2445 VTIMEZONE data
108 * @param vtzdata The string including VTIMEZONE data block
109 * @param status Output param to filled in with a success or an error.
110 * @return A <code>VTimeZone</code> initialized by the VTIMEZONE data or
111 * NULL if failed to load the rule from the VTIMEZONE data.
114 static VTimeZone
* createVTimeZone(const UnicodeString
& vtzdata
, UErrorCode
& status
);
117 * Gets the RFC2445 TZURL property value. When a <code>VTimeZone</code> instance was
118 * created from VTIMEZONE data, the initial value is set by the TZURL property value
119 * in the data. Otherwise, the initial value is not set.
120 * @param url Receives the RFC2445 TZURL property value.
121 * @return TRUE if TZURL attribute is available and value is set.
124 UBool
getTZURL(UnicodeString
& url
) const;
127 * Sets the RFC2445 TZURL property value.
128 * @param url The TZURL property value.
131 void setTZURL(const UnicodeString
& url
);
134 * Gets the RFC2445 LAST-MODIFIED property value. When a <code>VTimeZone</code> instance
135 * was created from VTIMEZONE data, the initial value is set by the LAST-MODIFIED property
136 * value in the data. Otherwise, the initial value is not set.
137 * @param lastModified Receives the last modified date.
138 * @return TRUE if lastModified attribute is available and value is set.
141 UBool
getLastModified(UDate
& lastModified
) const;
144 * Sets the RFC2445 LAST-MODIFIED property value.
145 * @param lastModified The LAST-MODIFIED date.
148 void setLastModified(UDate lastModified
);
151 * Writes RFC2445 VTIMEZONE data for this time zone
152 * @param result Output param to filled in with the VTIMEZONE data.
153 * @param status Output param to filled in with a success or an error.
156 void write(UnicodeString
& result
, UErrorCode
& status
) const;
159 * Writes RFC2445 VTIMEZONE data for this time zone applicalbe
160 * for dates after the specified start time.
161 * @param start The start date.
162 * @param result Output param to filled in with the VTIMEZONE data.
163 * @param status Output param to filled in with a success or an error.
166 void write(UDate start
, UnicodeString
& result
, UErrorCode
& status
) const;
169 * Writes RFC2445 VTIMEZONE data applicalbe for the specified date.
170 * Some common iCalendar implementations can only handle a single time
171 * zone property or a pair of standard and daylight time properties using
172 * BYDAY rule with day of week (such as BYDAY=1SUN). This method produce
173 * the VTIMEZONE data which can be handled these implementations. The rules
174 * produced by this method can be used only for calculating time zone offset
175 * around the specified date.
176 * @param time The date used for rule extraction.
177 * @param result Output param to filled in with the VTIMEZONE data.
178 * @param status Output param to filled in with a success or an error.
181 void writeSimple(UDate time
, UnicodeString
& result
, UErrorCode
& status
) const;
184 * Clones TimeZone objects polymorphically. Clients are responsible for deleting
185 * the TimeZone object cloned.
186 * @return A new copy of this TimeZone object.
189 virtual TimeZone
* clone(void) const;
192 * Returns the TimeZone's adjusted GMT offset (i.e., the number of milliseconds to add
193 * to GMT to get local time in this time zone, taking daylight savings time into
194 * account) as of a particular reference date. The reference date is used to determine
195 * whether daylight savings time is in effect and needs to be figured into the offset
196 * that is returned (in other words, what is the adjusted GMT offset in this time zone
197 * at this particular date and time?). For the time zones produced by createTimeZone(),
198 * the reference data is specified according to the Gregorian calendar, and the date
199 * and time fields are local standard time.
201 * <p>Note: Don't call this method. Instead, call the getOffset(UDate...) overload,
202 * which returns both the raw and the DST offset for a given time. This method
203 * is retained only for backward compatibility.
205 * @param era The reference date's era
206 * @param year The reference date's year
207 * @param month The reference date's month (0-based; 0 is January)
208 * @param day The reference date's day-in-month (1-based)
209 * @param dayOfWeek The reference date's day-of-week (1-based; 1 is Sunday)
210 * @param millis The reference date's milliseconds in day, local standard time
211 * @param status Output param to filled in with a success or an error.
212 * @return The offset in milliseconds to add to GMT to get local time.
215 virtual int32_t getOffset(uint8_t era
, int32_t year
, int32_t month
, int32_t day
,
216 uint8_t dayOfWeek
, int32_t millis
, UErrorCode
& status
) const;
219 * Gets the time zone offset, for current date, modified in case of
220 * daylight savings. This is the offset to add *to* UTC to get local time.
222 * <p>Note: Don't call this method. Instead, call the getOffset(UDate...) overload,
223 * which returns both the raw and the DST offset for a given time. This method
224 * is retained only for backward compatibility.
226 * @param era The reference date's era
227 * @param year The reference date's year
228 * @param month The reference date's month (0-based; 0 is January)
229 * @param day The reference date's day-in-month (1-based)
230 * @param dayOfWeek The reference date's day-of-week (1-based; 1 is Sunday)
231 * @param millis The reference date's milliseconds in day, local standard time
232 * @param monthLength The length of the given month in days.
233 * @param status Output param to filled in with a success or an error.
234 * @return The offset in milliseconds to add to GMT to get local time.
237 virtual int32_t getOffset(uint8_t era
, int32_t year
, int32_t month
, int32_t day
,
238 uint8_t dayOfWeek
, int32_t millis
,
239 int32_t monthLength
, UErrorCode
& status
) const;
242 * Returns the time zone raw and GMT offset for the given moment
243 * in time. Upon return, local-millis = GMT-millis + rawOffset +
244 * dstOffset. All computations are performed in the proleptic
245 * Gregorian calendar. The default implementation in the TimeZone
246 * class delegates to the 8-argument getOffset().
248 * @param date moment in time for which to return offsets, in
249 * units of milliseconds from January 1, 1970 0:00 GMT, either GMT
250 * time or local wall time, depending on `local'.
251 * @param local if true, `date' is local wall time; otherwise it
253 * @param rawOffset output parameter to receive the raw offset, that
254 * is, the offset not including DST adjustments
255 * @param dstOffset output parameter to receive the DST offset,
256 * that is, the offset to be added to `rawOffset' to obtain the
257 * total offset between local and GMT time. If DST is not in
258 * effect, this value is zero; otherwise it is a positive value,
259 * typically one hour.
260 * @param ec input-output error code
263 virtual void getOffset(UDate date
, UBool local
, int32_t& rawOffset
,
264 int32_t& dstOffset
, UErrorCode
& ec
) const;
267 * Sets the TimeZone's raw GMT offset (i.e., the number of milliseconds to add
268 * to GMT to get local time, before taking daylight savings time into account).
270 * @param offsetMillis The new raw GMT offset for this time zone.
273 virtual void setRawOffset(int32_t offsetMillis
);
276 * Returns the TimeZone's raw GMT offset (i.e., the number of milliseconds to add
277 * to GMT to get local time, before taking daylight savings time into account).
279 * @return The TimeZone's raw GMT offset.
282 virtual int32_t getRawOffset(void) const;
285 * Queries if this time zone uses daylight savings time.
286 * @return true if this time zone uses daylight savings time,
290 virtual UBool
useDaylightTime(void) const;
293 * Queries if the given date is in daylight savings time in
295 * This method is wasteful since it creates a new GregorianCalendar and
296 * deletes it each time it is called. This is a deprecated method
297 * and provided only for Java compatibility.
299 * @param date the given UDate.
300 * @param status Output param filled in with success/error code.
301 * @return true if the given date is in daylight savings time,
303 * @deprecated ICU 2.4. Use Calendar::inDaylightTime() instead.
305 virtual UBool
inDaylightTime(UDate date
, UErrorCode
& status
) const;
308 * Returns true if this zone has the same rule and offset as another zone.
309 * That is, if this zone differs only in ID, if at all.
310 * @param other the <code>TimeZone</code> object to be compared with
311 * @return true if the given zone is the same as this one,
312 * with the possible exception of the ID
315 virtual UBool
hasSameRules(const TimeZone
& other
) const;
318 * Gets the first time zone transition after the base time.
319 * @param base The base time.
320 * @param inclusive Whether the base time is inclusive or not.
321 * @param result Receives the first transition after the base time.
322 * @return TRUE if the transition is found.
325 virtual UBool
getNextTransition(UDate base
, UBool inclusive
, TimeZoneTransition
& result
) const;
328 * Gets the most recent time zone transition before the base time.
329 * @param base The base time.
330 * @param inclusive Whether the base time is inclusive or not.
331 * @param result Receives the most recent transition before the base time.
332 * @return TRUE if the transition is found.
335 virtual UBool
getPreviousTransition(UDate base
, UBool inclusive
, TimeZoneTransition
& result
) const;
338 * Returns the number of <code>TimeZoneRule</code>s which represents time transitions,
339 * for this time zone, that is, all <code>TimeZoneRule</code>s for this time zone except
340 * <code>InitialTimeZoneRule</code>. The return value range is 0 or any positive value.
341 * @param status Receives error status code.
342 * @return The number of <code>TimeZoneRule</code>s representing time transitions.
345 virtual int32_t countTransitionRules(UErrorCode
& status
) const;
348 * Gets the <code>InitialTimeZoneRule</code> and the set of <code>TimeZoneRule</code>
349 * which represent time transitions for this time zone. On successful return,
350 * the argument initial points to non-NULL <code>InitialTimeZoneRule</code> and
351 * the array trsrules is filled with 0 or multiple <code>TimeZoneRule</code>
352 * instances up to the size specified by trscount. The results are referencing the
353 * rule instance held by this time zone instance. Therefore, after this time zone
354 * is destructed, they are no longer available.
355 * @param initial Receives the initial timezone rule
356 * @param trsrules Receives the timezone transition rules
357 * @param trscount On input, specify the size of the array 'transitions' receiving
358 * the timezone transition rules. On output, actual number of
359 * rules filled in the array will be set.
360 * @param status Receives error status code.
363 virtual void getTimeZoneRules(const InitialTimeZoneRule
*& initial
,
364 const TimeZoneRule
* trsrules
[], int32_t& trscount
, UErrorCode
& status
) const;
367 enum { DEFAULT_VTIMEZONE_LINES
= 100 };
370 * Default constructor.
373 static VTimeZone
* createVTimeZone(VTZReader
* reader
);
374 void write(VTZWriter
& writer
, UErrorCode
& status
) const;
375 void write(UDate start
, VTZWriter
& writer
, UErrorCode
& status
) const;
376 void writeSimple(UDate time
, VTZWriter
& writer
, UErrorCode
& status
) const;
377 void load(VTZReader
& reader
, UErrorCode
& status
);
378 void parse(UErrorCode
& status
);
380 void writeZone(VTZWriter
& w
, BasicTimeZone
& basictz
, UVector
* customProps
,
381 UErrorCode
& status
) const;
383 void writeHeaders(VTZWriter
& w
, UErrorCode
& status
) const;
384 void writeFooter(VTZWriter
& writer
, UErrorCode
& status
) const;
386 void writeZonePropsByTime(VTZWriter
& writer
, UBool isDst
, const UnicodeString
& zonename
,
387 int32_t fromOffset
, int32_t toOffset
, UDate time
, UBool withRDATE
,
388 UErrorCode
& status
) const;
389 void writeZonePropsByDOM(VTZWriter
& writer
, UBool isDst
, const UnicodeString
& zonename
,
390 int32_t fromOffset
, int32_t toOffset
,
391 int32_t month
, int32_t dayOfMonth
, UDate startTime
, UDate untilTime
,
392 UErrorCode
& status
) const;
393 void writeZonePropsByDOW(VTZWriter
& writer
, UBool isDst
, const UnicodeString
& zonename
,
394 int32_t fromOffset
, int32_t toOffset
,
395 int32_t month
, int32_t weekInMonth
, int32_t dayOfWeek
,
396 UDate startTime
, UDate untilTime
, UErrorCode
& status
) const;
397 void writeZonePropsByDOW_GEQ_DOM(VTZWriter
& writer
, UBool isDst
, const UnicodeString
& zonename
,
398 int32_t fromOffset
, int32_t toOffset
,
399 int32_t month
, int32_t dayOfMonth
, int32_t dayOfWeek
,
400 UDate startTime
, UDate untilTime
, UErrorCode
& status
) const;
401 void writeZonePropsByDOW_GEQ_DOM_sub(VTZWriter
& writer
, int32_t month
, int32_t dayOfMonth
,
402 int32_t dayOfWeek
, int32_t numDays
,
403 UDate untilTime
, int32_t fromOffset
, UErrorCode
& status
) const;
404 void writeZonePropsByDOW_LEQ_DOM(VTZWriter
& writer
, UBool isDst
, const UnicodeString
& zonename
,
405 int32_t fromOffset
, int32_t toOffset
,
406 int32_t month
, int32_t dayOfMonth
, int32_t dayOfWeek
,
407 UDate startTime
, UDate untilTime
, UErrorCode
& status
) const;
408 void writeFinalRule(VTZWriter
& writer
, UBool isDst
, const AnnualTimeZoneRule
* rule
,
409 int32_t fromRawOffset
, int32_t fromDSTSavings
,
410 UDate startTime
, UErrorCode
& status
) const;
412 void beginZoneProps(VTZWriter
& writer
, UBool isDst
, const UnicodeString
& zonename
,
413 int32_t fromOffset
, int32_t toOffset
, UDate startTime
, UErrorCode
& status
) const;
414 void endZoneProps(VTZWriter
& writer
, UBool isDst
, UErrorCode
& status
) const;
415 void beginRRULE(VTZWriter
& writer
, int32_t month
, UErrorCode
& status
) const;
416 void appendUNTIL(VTZWriter
& writer
, const UnicodeString
& until
, UErrorCode
& status
) const;
422 UnicodeString olsonzid
;
423 UnicodeString icutzver
;
427 * Return the class ID for this class. This is useful only for comparing to
428 * a return value from getDynamicClassID(). For example:
430 * . Base* polymorphic_pointer = createPolymorphicObject();
431 * . if (polymorphic_pointer->getDynamicClassID() ==
432 * . erived::getStaticClassID()) ...
434 * @return The class ID for all objects of this class.
437 static UClassID U_EXPORT2
getStaticClassID(void);
440 * Returns a unique class ID POLYMORPHICALLY. Pure virtual override. This
441 * method is to implement a simple version of RTTI, since not all C++
442 * compilers support genuine RTTI. Polymorphic operator==() and clone()
443 * methods call this method.
445 * @return The class ID for this object. All objects of a
446 * given class have the same class ID. Objects of
447 * other classes have different class IDs.
450 virtual UClassID
getDynamicClassID(void) const;
454 #endif // U_SHOW_CPLUSPLUS_API
456 #endif /* #if !UCONFIG_NO_FORMATTING */