xref: /aosp_15_r20/external/icu/libicu/cts_headers/zrule.h (revision 0e209d3975ff4a8c132096b14b0e9364a753506e)
1*0e209d39SAndroid Build Coastguard Worker // © 2016 and later: Unicode, Inc. and others.
2*0e209d39SAndroid Build Coastguard Worker // License & terms of use: http://www.unicode.org/copyright.html
3*0e209d39SAndroid Build Coastguard Worker /*
4*0e209d39SAndroid Build Coastguard Worker *******************************************************************************
5*0e209d39SAndroid Build Coastguard Worker * Copyright (C) 2009-2016, International Business Machines Corporation and
6*0e209d39SAndroid Build Coastguard Worker * others. All Rights Reserved.
7*0e209d39SAndroid Build Coastguard Worker *******************************************************************************
8*0e209d39SAndroid Build Coastguard Worker */
9*0e209d39SAndroid Build Coastguard Worker #ifndef __ZRULE_H
10*0e209d39SAndroid Build Coastguard Worker #define __ZRULE_H
11*0e209d39SAndroid Build Coastguard Worker 
12*0e209d39SAndroid Build Coastguard Worker /**
13*0e209d39SAndroid Build Coastguard Worker  * \file
14*0e209d39SAndroid Build Coastguard Worker  * \brief C API: Time zone rule classes
15*0e209d39SAndroid Build Coastguard Worker  */
16*0e209d39SAndroid Build Coastguard Worker 
17*0e209d39SAndroid Build Coastguard Worker #include "unicode/utypes.h"
18*0e209d39SAndroid Build Coastguard Worker 
19*0e209d39SAndroid Build Coastguard Worker #if !UCONFIG_NO_FORMATTING
20*0e209d39SAndroid Build Coastguard Worker 
21*0e209d39SAndroid Build Coastguard Worker #include "unicode/uobject.h"
22*0e209d39SAndroid Build Coastguard Worker 
23*0e209d39SAndroid Build Coastguard Worker /**
24*0e209d39SAndroid Build Coastguard Worker  * A TimeZoneRule.  Use the zrule_* API to manipulate.  Create with
25*0e209d39SAndroid Build Coastguard Worker  * zrule_open*, and destroy with zrule_close.
26*0e209d39SAndroid Build Coastguard Worker  */
27*0e209d39SAndroid Build Coastguard Worker struct ZRule;
28*0e209d39SAndroid Build Coastguard Worker typedef struct ZRule ZRule;
29*0e209d39SAndroid Build Coastguard Worker 
30*0e209d39SAndroid Build Coastguard Worker /**
31*0e209d39SAndroid Build Coastguard Worker  * An InitialTimeZoneRule.  Use the izrule_* API to manipulate.  Create with
32*0e209d39SAndroid Build Coastguard Worker  * izrule_open*, and destroy with izrule_close.
33*0e209d39SAndroid Build Coastguard Worker  */
34*0e209d39SAndroid Build Coastguard Worker struct IZRule;
35*0e209d39SAndroid Build Coastguard Worker typedef struct IZRule IZRule;
36*0e209d39SAndroid Build Coastguard Worker 
37*0e209d39SAndroid Build Coastguard Worker /**
38*0e209d39SAndroid Build Coastguard Worker  * An AnnualTimeZoneRule.  Use the azrule_* API to manipulate.  Create with
39*0e209d39SAndroid Build Coastguard Worker  * azrule_open*, and destroy with azrule_close.
40*0e209d39SAndroid Build Coastguard Worker  */
41*0e209d39SAndroid Build Coastguard Worker struct AZRule;
42*0e209d39SAndroid Build Coastguard Worker typedef struct AZRule AZRule;
43*0e209d39SAndroid Build Coastguard Worker 
44*0e209d39SAndroid Build Coastguard Worker /*********************************************************************
45*0e209d39SAndroid Build Coastguard Worker  * ZRule API
46*0e209d39SAndroid Build Coastguard Worker  *********************************************************************/
47*0e209d39SAndroid Build Coastguard Worker 
48*0e209d39SAndroid Build Coastguard Worker /**
49*0e209d39SAndroid Build Coastguard Worker  * Disposes of the storage used by a ZRule object.  This function should
50*0e209d39SAndroid Build Coastguard Worker  * be called exactly once for objects returned by zrule_open*.
51*0e209d39SAndroid Build Coastguard Worker  * @param set the object to dispose of
52*0e209d39SAndroid Build Coastguard Worker  */
53*0e209d39SAndroid Build Coastguard Worker U_CAPI void U_EXPORT2
54*0e209d39SAndroid Build Coastguard Worker zrule_close(ZRule* rule);
55*0e209d39SAndroid Build Coastguard Worker 
56*0e209d39SAndroid Build Coastguard Worker /**
57*0e209d39SAndroid Build Coastguard Worker  * Returns true if rule1 is identical to rule2
58*0e209d39SAndroid Build Coastguard Worker  * and vis versa.
59*0e209d39SAndroid Build Coastguard Worker  * @param rule1 to be checked for containment
60*0e209d39SAndroid Build Coastguard Worker  * @param rule2 to be checked for containment
61*0e209d39SAndroid Build Coastguard Worker  * @return true if the test condition is met
62*0e209d39SAndroid Build Coastguard Worker  */
63*0e209d39SAndroid Build Coastguard Worker U_CAPI UBool U_EXPORT2
64*0e209d39SAndroid Build Coastguard Worker zrule_equals(const ZRule* rule1, const ZRule* rule2);
65*0e209d39SAndroid Build Coastguard Worker 
66*0e209d39SAndroid Build Coastguard Worker /**
67*0e209d39SAndroid Build Coastguard Worker  * Fills in "name" with the name of this time zone.
68*0e209d39SAndroid Build Coastguard Worker  * @param rule, the Zrule to use
69*0e209d39SAndroid Build Coastguard Worker  * @param name  Receives the name of this time zone.
70*0e209d39SAndroid Build Coastguard Worker  * @param nameLength, length of the returned name
71*0e209d39SAndroid Build Coastguard Worker  */
72*0e209d39SAndroid Build Coastguard Worker U_CAPI void U_EXPORT2
73*0e209d39SAndroid Build Coastguard Worker zrule_getName(ZRule* rule, UChar* name, int32_t nameLength);
74*0e209d39SAndroid Build Coastguard Worker 
75*0e209d39SAndroid Build Coastguard Worker /**
76*0e209d39SAndroid Build Coastguard Worker  * Gets the standard time offset.
77*0e209d39SAndroid Build Coastguard Worker  * @param rule, the Zrule to use
78*0e209d39SAndroid Build Coastguard Worker  * @return  The standard time offset from UTC in milliseconds.
79*0e209d39SAndroid Build Coastguard Worker  */
80*0e209d39SAndroid Build Coastguard Worker U_CAPI int32_t U_EXPORT2
81*0e209d39SAndroid Build Coastguard Worker zrule_getRawOffset(ZRule* rule);
82*0e209d39SAndroid Build Coastguard Worker 
83*0e209d39SAndroid Build Coastguard Worker /**
84*0e209d39SAndroid Build Coastguard Worker  * Gets the amount of daylight saving delta time from the standard time.
85*0e209d39SAndroid Build Coastguard Worker  * @param rule, the Zrule to use
86*0e209d39SAndroid Build Coastguard Worker  * @return  The amount of daylight saving offset used by this rule
87*0e209d39SAndroid Build Coastguard Worker  *          in milliseconds.
88*0e209d39SAndroid Build Coastguard Worker  */
89*0e209d39SAndroid Build Coastguard Worker U_CAPI int32_t U_EXPORT2
90*0e209d39SAndroid Build Coastguard Worker zrule_getDSTSavings(ZRule* rule);
91*0e209d39SAndroid Build Coastguard Worker 
92*0e209d39SAndroid Build Coastguard Worker /**
93*0e209d39SAndroid Build Coastguard Worker  * Returns if this rule represents the same rule and offsets as another.
94*0e209d39SAndroid Build Coastguard Worker  * When two ZRule objects differ only its names, this method
95*0e209d39SAndroid Build Coastguard Worker  * returns true.
96*0e209d39SAndroid Build Coastguard Worker  * @param rule1 to be checked for containment
97*0e209d39SAndroid Build Coastguard Worker  * @param rule2 to be checked for containment
98*0e209d39SAndroid Build Coastguard Worker  * @return  true if the other <code>TimeZoneRule</code> is the same as this one.
99*0e209d39SAndroid Build Coastguard Worker  */
100*0e209d39SAndroid Build Coastguard Worker U_CAPI UBool U_EXPORT2
101*0e209d39SAndroid Build Coastguard Worker zrule_isEquivalentTo(ZRule* rule1,  ZRule* rule2);
102*0e209d39SAndroid Build Coastguard Worker 
103*0e209d39SAndroid Build Coastguard Worker /*********************************************************************
104*0e209d39SAndroid Build Coastguard Worker  * IZRule API
105*0e209d39SAndroid Build Coastguard Worker  *********************************************************************/
106*0e209d39SAndroid Build Coastguard Worker 
107*0e209d39SAndroid Build Coastguard Worker /**
108*0e209d39SAndroid Build Coastguard Worker  * Constructs an IZRule with the name, the GMT offset of its
109*0e209d39SAndroid Build Coastguard Worker  * standard time and the amount of daylight saving offset adjustment.
110*0e209d39SAndroid Build Coastguard Worker  * @param name          The time zone name.
111*0e209d39SAndroid Build Coastguard Worker  * @param nameLength    The length of the time zone name.
112*0e209d39SAndroid Build Coastguard Worker  * @param rawOffset     The UTC offset of its standard time in milliseconds.
113*0e209d39SAndroid Build Coastguard Worker  * @param dstSavings    The amount of daylight saving offset adjustment in milliseconds.
114*0e209d39SAndroid Build Coastguard Worker  *                      If this ia a rule for standard time, the value of this argument is 0.
115*0e209d39SAndroid Build Coastguard Worker  */
116*0e209d39SAndroid Build Coastguard Worker U_CAPI IZRule* U_EXPORT2
117*0e209d39SAndroid Build Coastguard Worker izrule_open(const UChar* name, int32_t nameLength, int32_t rawOffset, int32_t dstSavings);
118*0e209d39SAndroid Build Coastguard Worker 
119*0e209d39SAndroid Build Coastguard Worker /**
120*0e209d39SAndroid Build Coastguard Worker  * Disposes of the storage used by a IZRule object.  This function should
121*0e209d39SAndroid Build Coastguard Worker  * be called exactly once for objects returned by izrule_open*.
122*0e209d39SAndroid Build Coastguard Worker  * @param set the object to dispose of
123*0e209d39SAndroid Build Coastguard Worker  */
124*0e209d39SAndroid Build Coastguard Worker U_CAPI void U_EXPORT2
125*0e209d39SAndroid Build Coastguard Worker izrule_close(IZRule* rule);
126*0e209d39SAndroid Build Coastguard Worker 
127*0e209d39SAndroid Build Coastguard Worker /**
128*0e209d39SAndroid Build Coastguard Worker  * Returns a copy of this object.
129*0e209d39SAndroid Build Coastguard Worker  * @param rule the original IZRule
130*0e209d39SAndroid Build Coastguard Worker  * @return the newly allocated copy of the IZRule
131*0e209d39SAndroid Build Coastguard Worker  */
132*0e209d39SAndroid Build Coastguard Worker U_CAPI IZRule* U_EXPORT2
133*0e209d39SAndroid Build Coastguard Worker izrule_clone(IZRule *rule);
134*0e209d39SAndroid Build Coastguard Worker 
135*0e209d39SAndroid Build Coastguard Worker /**
136*0e209d39SAndroid Build Coastguard Worker  * Returns true if rule1 is identical to rule2
137*0e209d39SAndroid Build Coastguard Worker  * and vis versa.
138*0e209d39SAndroid Build Coastguard Worker  * @param rule1 to be checked for containment
139*0e209d39SAndroid Build Coastguard Worker  * @param rule2 to be checked for containment
140*0e209d39SAndroid Build Coastguard Worker  * @return true if the test condition is met
141*0e209d39SAndroid Build Coastguard Worker  */
142*0e209d39SAndroid Build Coastguard Worker U_CAPI UBool U_EXPORT2
143*0e209d39SAndroid Build Coastguard Worker izrule_equals(const IZRule* rule1, const IZRule* rule2);
144*0e209d39SAndroid Build Coastguard Worker 
145*0e209d39SAndroid Build Coastguard Worker /**
146*0e209d39SAndroid Build Coastguard Worker  * Fills in "name" with the name of this time zone.
147*0e209d39SAndroid Build Coastguard Worker  * @param rule, the IZrule to use
148*0e209d39SAndroid Build Coastguard Worker  * @param name  Receives the name of this time zone.
149*0e209d39SAndroid Build Coastguard Worker  * @param nameLength, length of the returned name
150*0e209d39SAndroid Build Coastguard Worker  */
151*0e209d39SAndroid Build Coastguard Worker U_CAPI void U_EXPORT2
152*0e209d39SAndroid Build Coastguard Worker izrule_getName(IZRule* rule, UChar* & name, int32_t & nameLength);
153*0e209d39SAndroid Build Coastguard Worker 
154*0e209d39SAndroid Build Coastguard Worker /**
155*0e209d39SAndroid Build Coastguard Worker  * Gets the standard time offset.
156*0e209d39SAndroid Build Coastguard Worker  * @param rule, the IZrule to use
157*0e209d39SAndroid Build Coastguard Worker  * @return  The standard time offset from UTC in milliseconds.
158*0e209d39SAndroid Build Coastguard Worker  */
159*0e209d39SAndroid Build Coastguard Worker U_CAPI int32_t U_EXPORT2
160*0e209d39SAndroid Build Coastguard Worker izrule_getRawOffset(IZRule* rule);
161*0e209d39SAndroid Build Coastguard Worker 
162*0e209d39SAndroid Build Coastguard Worker /**
163*0e209d39SAndroid Build Coastguard Worker  * Gets the amount of daylight saving delta time from the standard time.
164*0e209d39SAndroid Build Coastguard Worker  * @param rule, the IZrule to use
165*0e209d39SAndroid Build Coastguard Worker  * @return  The amount of daylight saving offset used by this rule
166*0e209d39SAndroid Build Coastguard Worker  *          in milliseconds.
167*0e209d39SAndroid Build Coastguard Worker  */
168*0e209d39SAndroid Build Coastguard Worker U_CAPI int32_t U_EXPORT2
169*0e209d39SAndroid Build Coastguard Worker izrule_getDSTSavings(IZRule* rule);
170*0e209d39SAndroid Build Coastguard Worker 
171*0e209d39SAndroid Build Coastguard Worker /**
172*0e209d39SAndroid Build Coastguard Worker  * Returns if this rule represents the same rule and offsets as another.
173*0e209d39SAndroid Build Coastguard Worker  * When two IZRule objects differ only its names, this method
174*0e209d39SAndroid Build Coastguard Worker  * returns true.
175*0e209d39SAndroid Build Coastguard Worker  * @param rule1 to be checked for containment
176*0e209d39SAndroid Build Coastguard Worker  * @param rule2 to be checked for containment
177*0e209d39SAndroid Build Coastguard Worker  * @return  true if the other <code>TimeZoneRule</code> is the same as this one.
178*0e209d39SAndroid Build Coastguard Worker  */
179*0e209d39SAndroid Build Coastguard Worker U_CAPI UBool U_EXPORT2
180*0e209d39SAndroid Build Coastguard Worker izrule_isEquivalentTo(IZRule* rule1,  IZRule* rule2);
181*0e209d39SAndroid Build Coastguard Worker 
182*0e209d39SAndroid Build Coastguard Worker /**
183*0e209d39SAndroid Build Coastguard Worker  * Gets the very first time when this rule takes effect.
184*0e209d39SAndroid Build Coastguard Worker  * @param rule              The IZrule to use
185*0e209d39SAndroid Build Coastguard Worker  * @param prevRawOffset     The standard time offset from UTC before this rule
186*0e209d39SAndroid Build Coastguard Worker  *                          takes effect in milliseconds.
187*0e209d39SAndroid Build Coastguard Worker  * @param prevDSTSavings    The amount of daylight saving offset from the
188*0e209d39SAndroid Build Coastguard Worker  *                          standard time.
189*0e209d39SAndroid Build Coastguard Worker  * @param result            Receives the very first time when this rule takes effect.
190*0e209d39SAndroid Build Coastguard Worker  * @return  true if the start time is available.  When false is returned, output parameter
191*0e209d39SAndroid Build Coastguard Worker  *          "result" is unchanged.
192*0e209d39SAndroid Build Coastguard Worker  */
193*0e209d39SAndroid Build Coastguard Worker U_CAPI UBool U_EXPORT2
194*0e209d39SAndroid Build Coastguard Worker izrule_getFirstStart(IZRule* rule, int32_t prevRawOffset, int32_t prevDSTSavings,
195*0e209d39SAndroid Build Coastguard Worker                     UDate& result);
196*0e209d39SAndroid Build Coastguard Worker 
197*0e209d39SAndroid Build Coastguard Worker /**
198*0e209d39SAndroid Build Coastguard Worker  * Gets the final time when this rule takes effect.
199*0e209d39SAndroid Build Coastguard Worker  * @param rule              The IZrule to use
200*0e209d39SAndroid Build Coastguard Worker  * @param prevRawOffset     The standard time offset from UTC before this rule
201*0e209d39SAndroid Build Coastguard Worker  *                          takes effect in milliseconds.
202*0e209d39SAndroid Build Coastguard Worker  * @param prevDSTSavings    The amount of daylight saving offset from the
203*0e209d39SAndroid Build Coastguard Worker  *                          standard time.
204*0e209d39SAndroid Build Coastguard Worker  * @param result            Receives the final time when this rule takes effect.
205*0e209d39SAndroid Build Coastguard Worker  * @return  true if the start time is available.  When false is returned, output parameter
206*0e209d39SAndroid Build Coastguard Worker  *          "result" is unchanged.
207*0e209d39SAndroid Build Coastguard Worker  */
208*0e209d39SAndroid Build Coastguard Worker U_CAPI UBool U_EXPORT2
209*0e209d39SAndroid Build Coastguard Worker izrule_getFinalStart(IZRule* rule, int32_t prevRawOffset, int32_t prevDSTSavings,
210*0e209d39SAndroid Build Coastguard Worker                     UDate& result);
211*0e209d39SAndroid Build Coastguard Worker 
212*0e209d39SAndroid Build Coastguard Worker /**
213*0e209d39SAndroid Build Coastguard Worker  * Gets the first time when this rule takes effect after the specified time.
214*0e209d39SAndroid Build Coastguard Worker  * @param rule              The IZrule to use
215*0e209d39SAndroid Build Coastguard Worker  * @param base              The first start time after this base time will be returned.
216*0e209d39SAndroid Build Coastguard Worker  * @param prevRawOffset     The standard time offset from UTC before this rule
217*0e209d39SAndroid Build Coastguard Worker  *                          takes effect in milliseconds.
218*0e209d39SAndroid Build Coastguard Worker  * @param prevDSTSavings    The amount of daylight saving offset from the
219*0e209d39SAndroid Build Coastguard Worker  *                          standard time.
220*0e209d39SAndroid Build Coastguard Worker  * @param inclusive         Whether the base time is inclusive or not.
221*0e209d39SAndroid Build Coastguard Worker  * @param result            Receives The first time when this rule takes effect after
222*0e209d39SAndroid Build Coastguard Worker  *                          the specified base time.
223*0e209d39SAndroid Build Coastguard Worker  * @return  true if the start time is available.  When false is returned, output parameter
224*0e209d39SAndroid Build Coastguard Worker  *          "result" is unchanged.
225*0e209d39SAndroid Build Coastguard Worker  */
226*0e209d39SAndroid Build Coastguard Worker U_CAPI UBool U_EXPORT2
227*0e209d39SAndroid Build Coastguard Worker izrule_getNextStart(IZRule* rule, UDate base, int32_t prevRawOffset,
228*0e209d39SAndroid Build Coastguard Worker                    int32_t prevDSTSavings, UBool inclusive, UDate& result);
229*0e209d39SAndroid Build Coastguard Worker 
230*0e209d39SAndroid Build Coastguard Worker /**
231*0e209d39SAndroid Build Coastguard Worker  * Gets the most recent time when this rule takes effect before the specified time.
232*0e209d39SAndroid Build Coastguard Worker  * @param rule              The IZrule to use
233*0e209d39SAndroid Build Coastguard Worker  * @param base              The most recent time before this base time will be returned.
234*0e209d39SAndroid Build Coastguard Worker  * @param prevRawOffset     The standard time offset from UTC before this rule
235*0e209d39SAndroid Build Coastguard Worker  *                          takes effect in milliseconds.
236*0e209d39SAndroid Build Coastguard Worker  * @param prevDSTSavings    The amount of daylight saving offset from the
237*0e209d39SAndroid Build Coastguard Worker  *                          standard time.
238*0e209d39SAndroid Build Coastguard Worker  * @param inclusive         Whether the base time is inclusive or not.
239*0e209d39SAndroid Build Coastguard Worker  * @param result            Receives The most recent time when this rule takes effect before
240*0e209d39SAndroid Build Coastguard Worker  *                          the specified base time.
241*0e209d39SAndroid Build Coastguard Worker  * @return  true if the start time is available.  When false is returned, output parameter
242*0e209d39SAndroid Build Coastguard Worker  *          "result" is unchanged.
243*0e209d39SAndroid Build Coastguard Worker  */
244*0e209d39SAndroid Build Coastguard Worker U_CAPI UBool U_EXPORT2
245*0e209d39SAndroid Build Coastguard Worker izrule_getPreviousStart(IZRule* rule, UDate base, int32_t prevRawOffset,
246*0e209d39SAndroid Build Coastguard Worker                        int32_t prevDSTSavings, UBool inclusive, UDate& result);
247*0e209d39SAndroid Build Coastguard Worker 
248*0e209d39SAndroid Build Coastguard Worker 
249*0e209d39SAndroid Build Coastguard Worker /**
250*0e209d39SAndroid Build Coastguard Worker  * Return the class ID for this class. This is useful only for comparing to
251*0e209d39SAndroid Build Coastguard Worker  * a return value from getDynamicClassID(). For example:
252*0e209d39SAndroid Build Coastguard Worker  * <pre>
253*0e209d39SAndroid Build Coastguard Worker  * .   Base* polymorphic_pointer = createPolymorphicObject();
254*0e209d39SAndroid Build Coastguard Worker  * .   if (polymorphic_pointer->getDynamicClassID() ==
255*0e209d39SAndroid Build Coastguard Worker  * .       erived::getStaticClassID()) ...
256*0e209d39SAndroid Build Coastguard Worker  * </pre>
257*0e209d39SAndroid Build Coastguard Worker  * @param rule              The IZrule to use
258*0e209d39SAndroid Build Coastguard Worker  * @return          The class ID for all objects of this class.
259*0e209d39SAndroid Build Coastguard Worker  */
260*0e209d39SAndroid Build Coastguard Worker U_CAPI UClassID U_EXPORT2
261*0e209d39SAndroid Build Coastguard Worker izrule_getStaticClassID(IZRule* rule);
262*0e209d39SAndroid Build Coastguard Worker 
263*0e209d39SAndroid Build Coastguard Worker /**
264*0e209d39SAndroid Build Coastguard Worker  * Returns a unique class ID POLYMORPHICALLY. Pure virtual override. This
265*0e209d39SAndroid Build Coastguard Worker  * method is to implement a simple version of RTTI, since not all C++
266*0e209d39SAndroid Build Coastguard Worker  * compilers support genuine RTTI. Polymorphic operator==() and clone()
267*0e209d39SAndroid Build Coastguard Worker  * methods call this method.
268*0e209d39SAndroid Build Coastguard Worker  *
269*0e209d39SAndroid Build Coastguard Worker  * @param rule              The IZrule to use
270*0e209d39SAndroid Build Coastguard Worker  * @return          The class ID for this object. All objects of a
271*0e209d39SAndroid Build Coastguard Worker  *                  given class have the same class ID.  Objects of
272*0e209d39SAndroid Build Coastguard Worker  *                  other classes have different class IDs.
273*0e209d39SAndroid Build Coastguard Worker  */
274*0e209d39SAndroid Build Coastguard Worker U_CAPI UClassID U_EXPORT2
275*0e209d39SAndroid Build Coastguard Worker izrule_getDynamicClassID(IZRule* rule);
276*0e209d39SAndroid Build Coastguard Worker 
277*0e209d39SAndroid Build Coastguard Worker #endif
278*0e209d39SAndroid Build Coastguard Worker 
279*0e209d39SAndroid Build Coastguard Worker #endif
280