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