|
||||
Warning, file /include/unicode/vtzone.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 // © 2016 and later: Unicode, Inc. and others. 0002 // License & terms of use: http://www.unicode.org/copyright.html 0003 /* 0004 ******************************************************************************* 0005 * Copyright (C) 2007-2013, International Business Machines Corporation and 0006 * others. All Rights Reserved. 0007 ******************************************************************************* 0008 */ 0009 #ifndef VTZONE_H 0010 #define VTZONE_H 0011 0012 #include "unicode/utypes.h" 0013 0014 #if U_SHOW_CPLUSPLUS_API 0015 0016 /** 0017 * \file 0018 * \brief C++ API: RFC2445 VTIMEZONE support 0019 */ 0020 0021 #if !UCONFIG_NO_FORMATTING 0022 0023 #include "unicode/basictz.h" 0024 0025 U_NAMESPACE_BEGIN 0026 0027 class VTZWriter; 0028 class VTZReader; 0029 class UVector; 0030 0031 /** 0032 * <code>VTimeZone</code> is a class implementing RFC2445 VTIMEZONE. You can create a 0033 * <code>VTimeZone</code> instance from a time zone ID supported by <code>TimeZone</code>. 0034 * With the <code>VTimeZone</code> instance created from the ID, you can write out the rule 0035 * in RFC2445 VTIMEZONE format. Also, you can create a <code>VTimeZone</code> instance 0036 * from RFC2445 VTIMEZONE data stream, which allows you to calculate time 0037 * zone offset by the rules defined by the data. Or, you can create a 0038 * <code>VTimeZone</code> from any other ICU <code>BasicTimeZone</code>. 0039 * <br><br> 0040 * Note: The consumer of this class reading or writing VTIMEZONE data is responsible to 0041 * decode or encode Non-ASCII text. Methods reading/writing VTIMEZONE data in this class 0042 * do nothing with MIME encoding. 0043 * @stable ICU 3.8 0044 */ 0045 class U_I18N_API VTimeZone : public BasicTimeZone { 0046 public: 0047 /** 0048 * Copy constructor. 0049 * @param source The <code>VTimeZone</code> object to be copied. 0050 * @stable ICU 3.8 0051 */ 0052 VTimeZone(const VTimeZone& source); 0053 0054 /** 0055 * Destructor. 0056 * @stable ICU 3.8 0057 */ 0058 virtual ~VTimeZone(); 0059 0060 /** 0061 * Assignment operator. 0062 * @param right The object to be copied. 0063 * @stable ICU 3.8 0064 */ 0065 VTimeZone& operator=(const VTimeZone& right); 0066 0067 /** 0068 * Return true if the given <code>TimeZone</code> objects are 0069 * semantically equal. Objects of different subclasses are considered unequal. 0070 * @param that The object to be compared with. 0071 * @return true if the given <code>TimeZone</code> objects are 0072 *semantically equal. 0073 * @stable ICU 3.8 0074 */ 0075 virtual bool operator==(const TimeZone& that) const override; 0076 0077 /** 0078 * Return true if the given <code>TimeZone</code> objects are 0079 * semantically unequal. Objects of different subclasses are considered unequal. 0080 * @param that The object to be compared with. 0081 * @return true if the given <code>TimeZone</code> objects are 0082 * semantically unequal. 0083 * @stable ICU 3.8 0084 */ 0085 virtual bool operator!=(const TimeZone& that) const; 0086 0087 /** 0088 * Create a <code>VTimeZone</code> instance by the time zone ID. 0089 * @param ID The time zone ID, such as America/New_York 0090 * @return A <code>VTimeZone</code> object initialized by the time zone ID, 0091 * or nullptr when the ID is unknown. 0092 * @stable ICU 3.8 0093 */ 0094 static VTimeZone* createVTimeZoneByID(const UnicodeString& ID); 0095 0096 /** 0097 * Create a <code>VTimeZone</code> instance using a basic time zone. 0098 * @param basicTZ The basic time zone instance 0099 * @param status Output param to filled in with a success or an error. 0100 * @return A <code>VTimeZone</code> object initialized by the basic time zone. 0101 * @stable ICU 4.6 0102 */ 0103 static VTimeZone* createVTimeZoneFromBasicTimeZone(const BasicTimeZone& basicTZ, 0104 UErrorCode &status); 0105 0106 /** 0107 * Create a <code>VTimeZone</code> instance by RFC2445 VTIMEZONE data 0108 * 0109 * @param vtzdata The string including VTIMEZONE data block 0110 * @param status Output param to filled in with a success or an error. 0111 * @return A <code>VTimeZone</code> initialized by the VTIMEZONE data or 0112 * nullptr if failed to load the rule from the VTIMEZONE data. 0113 * @stable ICU 3.8 0114 */ 0115 static VTimeZone* createVTimeZone(const UnicodeString& vtzdata, UErrorCode& status); 0116 0117 /** 0118 * Gets the RFC2445 TZURL property value. When a <code>VTimeZone</code> instance was 0119 * created from VTIMEZONE data, the initial value is set by the TZURL property value 0120 * in the data. Otherwise, the initial value is not set. 0121 * @param url Receives the RFC2445 TZURL property value. 0122 * @return true if TZURL attribute is available and value is set. 0123 * @stable ICU 3.8 0124 */ 0125 UBool getTZURL(UnicodeString& url) const; 0126 0127 /** 0128 * Sets the RFC2445 TZURL property value. 0129 * @param url The TZURL property value. 0130 * @stable ICU 3.8 0131 */ 0132 void setTZURL(const UnicodeString& url); 0133 0134 /** 0135 * Gets the RFC2445 LAST-MODIFIED property value. When a <code>VTimeZone</code> instance 0136 * was created from VTIMEZONE data, the initial value is set by the LAST-MODIFIED property 0137 * value in the data. Otherwise, the initial value is not set. 0138 * @param lastModified Receives the last modified date. 0139 * @return true if lastModified attribute is available and value is set. 0140 * @stable ICU 3.8 0141 */ 0142 UBool getLastModified(UDate& lastModified) const; 0143 0144 /** 0145 * Sets the RFC2445 LAST-MODIFIED property value. 0146 * @param lastModified The LAST-MODIFIED date. 0147 * @stable ICU 3.8 0148 */ 0149 void setLastModified(UDate lastModified); 0150 0151 /** 0152 * Writes RFC2445 VTIMEZONE data for this time zone 0153 * @param result Output param to filled in with the VTIMEZONE data. 0154 * @param status Output param to filled in with a success or an error. 0155 * @stable ICU 3.8 0156 */ 0157 void write(UnicodeString& result, UErrorCode& status) const; 0158 0159 /** 0160 * Writes RFC2445 VTIMEZONE data for this time zone applicable 0161 * for dates after the specified start time. 0162 * @param start The start date. 0163 * @param result Output param to filled in with the VTIMEZONE data. 0164 * @param status Output param to filled in with a success or an error. 0165 * @stable ICU 3.8 0166 */ 0167 void write(UDate start, UnicodeString& result, UErrorCode& status) const; 0168 0169 /** 0170 * Writes RFC2445 VTIMEZONE data applicable for the specified date. 0171 * Some common iCalendar implementations can only handle a single time 0172 * zone property or a pair of standard and daylight time properties using 0173 * BYDAY rule with day of week (such as BYDAY=1SUN). This method produce 0174 * the VTIMEZONE data which can be handled these implementations. The rules 0175 * produced by this method can be used only for calculating time zone offset 0176 * around the specified date. 0177 * @param time The date used for rule extraction. 0178 * @param result Output param to filled in with the VTIMEZONE data. 0179 * @param status Output param to filled in with a success or an error. 0180 * @stable ICU 3.8 0181 */ 0182 void writeSimple(UDate time, UnicodeString& result, UErrorCode& status) const; 0183 0184 /** 0185 * Clones TimeZone objects polymorphically. Clients are responsible for deleting 0186 * the TimeZone object cloned. 0187 * @return A new copy of this TimeZone object. 0188 * @stable ICU 3.8 0189 */ 0190 virtual VTimeZone* clone() const override; 0191 0192 /** 0193 * Returns the TimeZone's adjusted GMT offset (i.e., the number of milliseconds to add 0194 * to GMT to get local time in this time zone, taking daylight savings time into 0195 * account) as of a particular reference date. The reference date is used to determine 0196 * whether daylight savings time is in effect and needs to be figured into the offset 0197 * that is returned (in other words, what is the adjusted GMT offset in this time zone 0198 * at this particular date and time?). For the time zones produced by createTimeZone(), 0199 * the reference data is specified according to the Gregorian calendar, and the date 0200 * and time fields are local standard time. 0201 * 0202 * <p>Note: Don't call this method. Instead, call the getOffset(UDate...) overload, 0203 * which returns both the raw and the DST offset for a given time. This method 0204 * is retained only for backward compatibility. 0205 * 0206 * @param era The reference date's era 0207 * @param year The reference date's year 0208 * @param month The reference date's month (0-based; 0 is January) 0209 * @param day The reference date's day-in-month (1-based) 0210 * @param dayOfWeek The reference date's day-of-week (1-based; 1 is Sunday) 0211 * @param millis The reference date's milliseconds in day, local standard time 0212 * @param status Output param to filled in with a success or an error. 0213 * @return The offset in milliseconds to add to GMT to get local time. 0214 * @stable ICU 3.8 0215 */ 0216 virtual int32_t getOffset(uint8_t era, int32_t year, int32_t month, int32_t day, 0217 uint8_t dayOfWeek, int32_t millis, UErrorCode& status) const override; 0218 0219 /** 0220 * Gets the time zone offset, for current date, modified in case of 0221 * daylight savings. This is the offset to add *to* UTC to get local time. 0222 * 0223 * <p>Note: Don't call this method. Instead, call the getOffset(UDate...) overload, 0224 * which returns both the raw and the DST offset for a given time. This method 0225 * is retained only for backward compatibility. 0226 * 0227 * @param era The reference date's era 0228 * @param year The reference date's year 0229 * @param month The reference date's month (0-based; 0 is January) 0230 * @param day The reference date's day-in-month (1-based) 0231 * @param dayOfWeek The reference date's day-of-week (1-based; 1 is Sunday) 0232 * @param millis The reference date's milliseconds in day, local standard time 0233 * @param monthLength The length of the given month in days. 0234 * @param status Output param to filled in with a success or an error. 0235 * @return The offset in milliseconds to add to GMT to get local time. 0236 * @stable ICU 3.8 0237 */ 0238 virtual int32_t getOffset(uint8_t era, int32_t year, int32_t month, int32_t day, 0239 uint8_t dayOfWeek, int32_t millis, 0240 int32_t monthLength, UErrorCode& status) const override; 0241 0242 /** 0243 * Returns the time zone raw and GMT offset for the given moment 0244 * in time. Upon return, local-millis = GMT-millis + rawOffset + 0245 * dstOffset. All computations are performed in the proleptic 0246 * Gregorian calendar. The default implementation in the TimeZone 0247 * class delegates to the 8-argument getOffset(). 0248 * 0249 * @param date moment in time for which to return offsets, in 0250 * units of milliseconds from January 1, 1970 0:00 GMT, either GMT 0251 * time or local wall time, depending on `local'. 0252 * @param local if true, `date' is local wall time; otherwise it 0253 * is in GMT time. 0254 * @param rawOffset output parameter to receive the raw offset, that 0255 * is, the offset not including DST adjustments 0256 * @param dstOffset output parameter to receive the DST offset, 0257 * that is, the offset to be added to `rawOffset' to obtain the 0258 * total offset between local and GMT time. If DST is not in 0259 * effect, this value is zero; otherwise it is a positive value, 0260 * typically one hour. 0261 * @param ec input-output error code 0262 * @stable ICU 3.8 0263 */ 0264 virtual void getOffset(UDate date, UBool local, int32_t& rawOffset, 0265 int32_t& dstOffset, UErrorCode& ec) const override; 0266 0267 /** 0268 * Get time zone offsets from local wall time. 0269 * @stable ICU 69 0270 */ 0271 virtual void getOffsetFromLocal( 0272 UDate date, UTimeZoneLocalOption nonExistingTimeOpt, 0273 UTimeZoneLocalOption duplicatedTimeOpt, 0274 int32_t& rawOffset, int32_t& dstOffset, UErrorCode& status) const override; 0275 0276 /** 0277 * Sets the TimeZone's raw GMT offset (i.e., the number of milliseconds to add 0278 * to GMT to get local time, before taking daylight savings time into account). 0279 * 0280 * @param offsetMillis The new raw GMT offset for this time zone. 0281 * @stable ICU 3.8 0282 */ 0283 virtual void setRawOffset(int32_t offsetMillis) override; 0284 0285 /** 0286 * Returns the TimeZone's raw GMT offset (i.e., the number of milliseconds to add 0287 * to GMT to get local time, before taking daylight savings time into account). 0288 * 0289 * @return The TimeZone's raw GMT offset. 0290 * @stable ICU 3.8 0291 */ 0292 virtual int32_t getRawOffset(void) const override; 0293 0294 /** 0295 * Queries if this time zone uses daylight savings time. 0296 * @return true if this time zone uses daylight savings time, 0297 * false, otherwise. 0298 * @stable ICU 3.8 0299 */ 0300 virtual UBool useDaylightTime(void) const override; 0301 0302 #ifndef U_FORCE_HIDE_DEPRECATED_API 0303 /** 0304 * Queries if the given date is in daylight savings time in 0305 * this time zone. 0306 * This method is wasteful since it creates a new GregorianCalendar and 0307 * deletes it each time it is called. This is a deprecated method 0308 * and provided only for Java compatibility. 0309 * 0310 * @param date the given UDate. 0311 * @param status Output param filled in with success/error code. 0312 * @return true if the given date is in daylight savings time, 0313 * false, otherwise. 0314 * @deprecated ICU 2.4. Use Calendar::inDaylightTime() instead. 0315 */ 0316 virtual UBool inDaylightTime(UDate date, UErrorCode& status) const override; 0317 #endif // U_FORCE_HIDE_DEPRECATED_API 0318 0319 /** 0320 * Returns true if this zone has the same rule and offset as another zone. 0321 * That is, if this zone differs only in ID, if at all. 0322 * @param other the <code>TimeZone</code> object to be compared with 0323 * @return true if the given zone is the same as this one, 0324 * with the possible exception of the ID 0325 * @stable ICU 3.8 0326 */ 0327 virtual UBool hasSameRules(const TimeZone& other) const override; 0328 0329 /** 0330 * Gets the first time zone transition after the base time. 0331 * @param base The base time. 0332 * @param inclusive Whether the base time is inclusive or not. 0333 * @param result Receives the first transition after the base time. 0334 * @return true if the transition is found. 0335 * @stable ICU 3.8 0336 */ 0337 virtual UBool getNextTransition(UDate base, UBool inclusive, TimeZoneTransition& result) const override; 0338 0339 /** 0340 * Gets the most recent time zone transition before the base time. 0341 * @param base The base time. 0342 * @param inclusive Whether the base time is inclusive or not. 0343 * @param result Receives the most recent transition before the base time. 0344 * @return true if the transition is found. 0345 * @stable ICU 3.8 0346 */ 0347 virtual UBool getPreviousTransition(UDate base, UBool inclusive, TimeZoneTransition& result) const override; 0348 0349 /** 0350 * Returns the number of <code>TimeZoneRule</code>s which represents time transitions, 0351 * for this time zone, that is, all <code>TimeZoneRule</code>s for this time zone except 0352 * <code>InitialTimeZoneRule</code>. The return value range is 0 or any positive value. 0353 * @param status Receives error status code. 0354 * @return The number of <code>TimeZoneRule</code>s representing time transitions. 0355 * @stable ICU 3.8 0356 */ 0357 virtual int32_t countTransitionRules(UErrorCode& status) const override; 0358 0359 /** 0360 * Gets the <code>InitialTimeZoneRule</code> and the set of <code>TimeZoneRule</code> 0361 * which represent time transitions for this time zone. On successful return, 0362 * the argument initial points to non-nullptr <code>InitialTimeZoneRule</code> and 0363 * the array trsrules is filled with 0 or multiple <code>TimeZoneRule</code> 0364 * instances up to the size specified by trscount. The results are referencing the 0365 * rule instance held by this time zone instance. Therefore, after this time zone 0366 * is destructed, they are no longer available. 0367 * @param initial Receives the initial timezone rule 0368 * @param trsrules Receives the timezone transition rules 0369 * @param trscount On input, specify the size of the array 'transitions' receiving 0370 * the timezone transition rules. On output, actual number of 0371 * rules filled in the array will be set. 0372 * @param status Receives error status code. 0373 * @stable ICU 3.8 0374 */ 0375 virtual void getTimeZoneRules(const InitialTimeZoneRule*& initial, 0376 const TimeZoneRule* trsrules[], int32_t& trscount, UErrorCode& status) const override; 0377 0378 private: 0379 enum { DEFAULT_VTIMEZONE_LINES = 100 }; 0380 0381 /** 0382 * Default constructor. 0383 */ 0384 VTimeZone(); 0385 void write(VTZWriter& writer, UErrorCode& status) const; 0386 void write(UDate start, VTZWriter& writer, UErrorCode& status) const; 0387 void writeSimple(UDate time, VTZWriter& writer, UErrorCode& status) const; 0388 void load(VTZReader& reader, UErrorCode& status); 0389 void parse(UErrorCode& status); 0390 0391 void writeZone(VTZWriter& w, BasicTimeZone& basictz, UVector* customProps, 0392 UErrorCode& status) const; 0393 0394 void writeHeaders(VTZWriter& w, UErrorCode& status) const; 0395 void writeFooter(VTZWriter& writer, UErrorCode& status) const; 0396 0397 void writeZonePropsByTime(VTZWriter& writer, UBool isDst, const UnicodeString& zonename, 0398 int32_t fromOffset, int32_t toOffset, UDate time, UBool withRDATE, 0399 UErrorCode& status) const; 0400 void writeZonePropsByDOM(VTZWriter& writer, UBool isDst, const UnicodeString& zonename, 0401 int32_t fromOffset, int32_t toOffset, 0402 int32_t month, int32_t dayOfMonth, UDate startTime, UDate untilTime, 0403 UErrorCode& status) const; 0404 void writeZonePropsByDOW(VTZWriter& writer, UBool isDst, const UnicodeString& zonename, 0405 int32_t fromOffset, int32_t toOffset, 0406 int32_t month, int32_t weekInMonth, int32_t dayOfWeek, 0407 UDate startTime, UDate untilTime, UErrorCode& status) const; 0408 void writeZonePropsByDOW_GEQ_DOM(VTZWriter& writer, UBool isDst, const UnicodeString& zonename, 0409 int32_t fromOffset, int32_t toOffset, 0410 int32_t month, int32_t dayOfMonth, int32_t dayOfWeek, 0411 UDate startTime, UDate untilTime, UErrorCode& status) const; 0412 void writeZonePropsByDOW_GEQ_DOM_sub(VTZWriter& writer, int32_t month, int32_t dayOfMonth, 0413 int32_t dayOfWeek, int32_t numDays, 0414 UDate untilTime, int32_t fromOffset, UErrorCode& status) const; 0415 void writeZonePropsByDOW_LEQ_DOM(VTZWriter& writer, UBool isDst, const UnicodeString& zonename, 0416 int32_t fromOffset, int32_t toOffset, 0417 int32_t month, int32_t dayOfMonth, int32_t dayOfWeek, 0418 UDate startTime, UDate untilTime, UErrorCode& status) const; 0419 void writeFinalRule(VTZWriter& writer, UBool isDst, const AnnualTimeZoneRule* rule, 0420 int32_t fromRawOffset, int32_t fromDSTSavings, 0421 UDate startTime, UErrorCode& status) const; 0422 0423 void beginZoneProps(VTZWriter& writer, UBool isDst, const UnicodeString& zonename, 0424 int32_t fromOffset, int32_t toOffset, UDate startTime, UErrorCode& status) const; 0425 void endZoneProps(VTZWriter& writer, UBool isDst, UErrorCode& status) const; 0426 void beginRRULE(VTZWriter& writer, int32_t month, UErrorCode& status) const; 0427 void appendUNTIL(VTZWriter& writer, const UnicodeString& until, UErrorCode& status) const; 0428 0429 BasicTimeZone *tz; 0430 UVector *vtzlines; 0431 UnicodeString tzurl; 0432 UDate lastmod; 0433 UnicodeString olsonzid; 0434 UnicodeString icutzver; 0435 0436 public: 0437 /** 0438 * Return the class ID for this class. This is useful only for comparing to 0439 * a return value from getDynamicClassID(). For example: 0440 * <pre> 0441 * . Base* polymorphic_pointer = createPolymorphicObject(); 0442 * . if (polymorphic_pointer->getDynamicClassID() == 0443 * . erived::getStaticClassID()) ... 0444 * </pre> 0445 * @return The class ID for all objects of this class. 0446 * @stable ICU 3.8 0447 */ 0448 static UClassID U_EXPORT2 getStaticClassID(void); 0449 0450 /** 0451 * Returns a unique class ID POLYMORPHICALLY. Pure virtual override. This 0452 * method is to implement a simple version of RTTI, since not all C++ 0453 * compilers support genuine RTTI. Polymorphic operator==() and clone() 0454 * methods call this method. 0455 * 0456 * @return The class ID for this object. All objects of a 0457 * given class have the same class ID. Objects of 0458 * other classes have different class IDs. 0459 * @stable ICU 3.8 0460 */ 0461 virtual UClassID getDynamicClassID(void) const override; 0462 }; 0463 0464 U_NAMESPACE_END 0465 0466 #endif /* #if !UCONFIG_NO_FORMATTING */ 0467 0468 #endif /* U_SHOW_CPLUSPLUS_API */ 0469 0470 #endif // VTZONE_H 0471 //eof
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |