]>
git.saurik.com Git - apple/icu.git/blob - icuSources/i18n/unicode/basictz.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 *******************************************************************************
14 * \brief C++ API: ICU TimeZone base class
17 #include "unicode/utypes.h"
19 #if U_SHOW_CPLUSPLUS_API
21 #if !UCONFIG_NO_FORMATTING
23 #include "unicode/timezone.h"
24 #include "unicode/tzrule.h"
25 #include "unicode/tztrans.h"
29 // forward declarations
33 * <code>BasicTimeZone</code> is an abstract class extending <code>TimeZone</code>.
34 * This class provides some additional methods to access time zone transitions and rules.
35 * All ICU <code>TimeZone</code> concrete subclasses extend this class.
38 class U_I18N_API BasicTimeZone
: public TimeZone
{
44 virtual ~BasicTimeZone();
47 * Clones this object polymorphically.
48 * The caller owns the result and should delete it when done.
49 * @return clone, or nullptr if an error occurred
52 virtual BasicTimeZone
* clone() const = 0;
55 * Gets the first time zone transition after the base time.
56 * @param base The base time.
57 * @param inclusive Whether the base time is inclusive or not.
58 * @param result Receives the first transition after the base time.
59 * @return TRUE if the transition is found.
62 virtual UBool
getNextTransition(UDate base
, UBool inclusive
, TimeZoneTransition
& result
) const = 0;
65 * Gets the most recent time zone transition before the base time.
66 * @param base The base time.
67 * @param inclusive Whether the base time is inclusive or not.
68 * @param result Receives the most recent transition before the base time.
69 * @return TRUE if the transition is found.
72 virtual UBool
getPreviousTransition(UDate base
, UBool inclusive
, TimeZoneTransition
& result
) const = 0;
75 * Checks if the time zone has equivalent transitions in the time range.
76 * This method returns true when all of transition times, from/to standard
77 * offsets and DST savings used by this time zone match the other in the
79 * @param tz The <code>BasicTimeZone</code> object to be compared with.
80 * @param start The start time of the evaluated time range (inclusive)
81 * @param end The end time of the evaluated time range (inclusive)
82 * @param ignoreDstAmount
83 * When true, any transitions with only daylight saving amount
84 * changes will be ignored, except either of them is zero.
85 * For example, a transition from rawoffset 3:00/dstsavings 1:00
86 * to rawoffset 2:00/dstsavings 2:00 is excluded from the comparison,
87 * but a transtion from rawoffset 2:00/dstsavings 1:00 to
88 * rawoffset 3:00/dstsavings 0:00 is included.
89 * @param ec Output param to filled in with a success or an error.
90 * @return true if the other time zone has the equivalent transitions in the
94 virtual UBool
hasEquivalentTransitions(const BasicTimeZone
& tz
, UDate start
, UDate end
,
95 UBool ignoreDstAmount
, UErrorCode
& ec
) const;
98 * Returns the number of <code>TimeZoneRule</code>s which represents time transitions,
99 * for this time zone, that is, all <code>TimeZoneRule</code>s for this time zone except
100 * <code>InitialTimeZoneRule</code>. The return value range is 0 or any positive value.
101 * @param status Receives error status code.
102 * @return The number of <code>TimeZoneRule</code>s representing time transitions.
105 virtual int32_t countTransitionRules(UErrorCode
& status
) const = 0;
108 * Gets the <code>InitialTimeZoneRule</code> and the set of <code>TimeZoneRule</code>
109 * which represent time transitions for this time zone. On successful return,
110 * the argument initial points to non-NULL <code>InitialTimeZoneRule</code> and
111 * the array trsrules is filled with 0 or multiple <code>TimeZoneRule</code>
112 * instances up to the size specified by trscount. The results are referencing the
113 * rule instance held by this time zone instance. Therefore, after this time zone
114 * is destructed, they are no longer available.
115 * @param initial Receives the initial timezone rule
116 * @param trsrules Receives the timezone transition rules
117 * @param trscount On input, specify the size of the array 'transitions' receiving
118 * the timezone transition rules. On output, actual number of
119 * rules filled in the array will be set.
120 * @param status Receives error status code.
123 virtual void getTimeZoneRules(const InitialTimeZoneRule
*& initial
,
124 const TimeZoneRule
* trsrules
[], int32_t& trscount
, UErrorCode
& status
) const = 0;
127 * Gets the set of time zone rules valid at the specified time. Some known external time zone
128 * implementations are not capable to handle historic time zone rule changes. Also some
129 * implementations can only handle certain type of rule definitions.
130 * If this time zone does not use any daylight saving time within about 1 year from the specified
131 * time, only the <code>InitialTimeZone</code> is returned. Otherwise, the rule for standard
132 * time and daylight saving time transitions are returned in addition to the
133 * <code>InitialTimeZoneRule</code>. The standard and daylight saving time transition rules are
134 * represented by <code>AnnualTimeZoneRule</code> with <code>DateTimeRule::DOW</code> for its date
135 * rule and <code>DateTimeRule::WALL_TIME</code> for its time rule. Because daylight saving time
136 * rule is changing time to time in many time zones and also mapping a transition time rule to
137 * different type is lossy transformation, the set of rules returned by this method may be valid
138 * for short period of time.
139 * The time zone rule objects returned by this method is owned by the caller, so the caller is
140 * responsible for deleting them after use.
141 * @param date The date used for extracting time zone rules.
142 * @param initial Receives the <code>InitialTimeZone</code>, always not NULL.
143 * @param std Receives the <code>AnnualTimeZoneRule</code> for standard time transitions.
144 * When this time time zone does not observe daylight saving times around the
145 * specified date, NULL is set.
146 * @param dst Receives the <code>AnnualTimeZoneRule</code> for daylight saving time
147 * transitions. When this time zone does not observer daylight saving times
148 * around the specified date, NULL is set.
149 * @param status Receives error status code.
152 virtual void getSimpleRulesNear(UDate date
, InitialTimeZoneRule
*& initial
,
153 AnnualTimeZoneRule
*& std
, AnnualTimeZoneRule
*& dst
, UErrorCode
& status
) const;
156 #ifndef U_HIDE_INTERNAL_API
158 * The time type option bit flags used by getOffsetFromLocal
167 #endif /* U_HIDE_INTERNAL_API */
170 * Get time zone offsets from local wall time.
173 virtual void getOffsetFromLocal(UDate date
, int32_t nonExistingTimeOpt
, int32_t duplicatedTimeOpt
,
174 int32_t& rawOffset
, int32_t& dstOffset
, UErrorCode
& status
) const;
178 #ifndef U_HIDE_INTERNAL_API
180 * The time type option bit masks used by getOffsetFromLocal
184 kStdDstMask
= kDaylight
,
185 kFormerLatterMask
= kLatter
187 #endif /* U_HIDE_INTERNAL_API */
190 * Default constructor.
196 * Construct a timezone with a given ID.
197 * @param id a system time zone ID
200 BasicTimeZone(const UnicodeString
&id
);
204 * @param source the object to be copied.
207 BasicTimeZone(const BasicTimeZone
& source
);
210 * Gets the set of TimeZoneRule instances applicable to the specified time and after.
211 * @param start The start date used for extracting time zone rules
212 * @param initial Receives the InitialTimeZone, always not NULL
213 * @param transitionRules Receives the transition rules, could be NULL
214 * @param status Receives error status code
216 void getTimeZoneRulesAfter(UDate start
, InitialTimeZoneRule
*& initial
, UVector
*& transitionRules
,
217 UErrorCode
& status
) const;
222 #endif /* #if !UCONFIG_NO_FORMATTING */
224 #endif /* U_SHOW_CPLUSPLUS_API */