1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 *******************************************************************************
5 * Copyright (C) 2009-2011, International Business Machines Corporation and
6 * others. All Rights Reserved.
7 *******************************************************************************
12 * \brief C API: Time zone rule classes
15 #include "unicode/utypes.h"
17 #if !UCONFIG_NO_FORMATTING
19 #include "unicode/uobject.h"
21 #include "unicode/tzrule.h"
23 #include "unicode/ustring.h"
24 #include "unicode/parsepos.h"
28 /*********************************************************************
30 *********************************************************************/
33 zrule_close(ZRule
* rule
) {
34 delete (TimeZoneRule
*)rule
;
37 U_CAPI UBool U_EXPORT2
38 zrule_equals(const ZRule
* rule1
, const ZRule
* rule2
) {
39 return *(const TimeZoneRule
*)rule1
== *(const TimeZoneRule
*)rule2
;
43 zrule_getName(ZRule
* rule
, UChar
* name
, int32_t nameLength
) {
44 UnicodeString
s(nameLength
==-1, name
, nameLength
);
45 s
= ((TimeZoneRule
*)rule
)->TimeZoneRule::getName(s
);
46 nameLength
= s
.length();
47 memcpy(name
, s
.getBuffer(), nameLength
);
51 U_CAPI
int32_t U_EXPORT2
52 zrule_getRawOffset(ZRule
* rule
) {
53 return ((TimeZoneRule
*)rule
)->TimeZoneRule::getRawOffset();
56 U_CAPI
int32_t U_EXPORT2
57 zrule_getDSTSavings(ZRule
* rule
) {
58 return ((TimeZoneRule
*)rule
)->TimeZoneRule::getDSTSavings();
61 U_CAPI UBool U_EXPORT2
62 zrule_isEquivalentTo(ZRule
* rule1
, ZRule
* rule2
) {
63 return ((TimeZoneRule
*)rule1
)->TimeZoneRule::isEquivalentTo(*(TimeZoneRule
*)rule2
);
66 /*********************************************************************
68 *********************************************************************/
70 U_CAPI IZRule
* U_EXPORT2
71 izrule_open(const UChar
* name
, int32_t nameLength
, int32_t rawOffset
, int32_t dstSavings
) {
72 UnicodeString
s(nameLength
==-1, name
, nameLength
);
73 return (IZRule
*) new InitialTimeZoneRule(s
, rawOffset
, dstSavings
);
77 izrule_close(IZRule
* rule
) {
78 delete (InitialTimeZoneRule
*)rule
;
81 U_CAPI IZRule
* U_EXPORT2
82 izrule_clone(IZRule
*rule
) {
83 return (IZRule
*) (((InitialTimeZoneRule
*)rule
)->InitialTimeZoneRule::clone());
86 U_CAPI UBool U_EXPORT2
87 izrule_equals(const IZRule
* rule1
, const IZRule
* rule2
) {
88 return *(const InitialTimeZoneRule
*)rule1
== *(const InitialTimeZoneRule
*)rule2
;
92 izrule_getName(IZRule
* rule
, UChar
* & name
, int32_t & nameLength
) {
93 // UnicodeString s(nameLength==-1, name, nameLength);
95 ((InitialTimeZoneRule
*)rule
)->InitialTimeZoneRule::getName(s
);
96 nameLength
= s
.length();
97 name
= (UChar
*)uprv_malloc(nameLength
);
98 memcpy(name
, s
.getBuffer(), nameLength
);
102 U_CAPI
int32_t U_EXPORT2
103 izrule_getRawOffset(IZRule
* rule
) {
104 return ((InitialTimeZoneRule
*)rule
)->InitialTimeZoneRule::getRawOffset();
107 U_CAPI
int32_t U_EXPORT2
108 izrule_getDSTSavings(IZRule
* rule
) {
109 return ((InitialTimeZoneRule
*)rule
)->InitialTimeZoneRule::getDSTSavings();
112 U_CAPI UBool U_EXPORT2
113 izrule_isEquivalentTo(IZRule
* rule1
, IZRule
* rule2
) {
114 return ((InitialTimeZoneRule
*)rule1
)->InitialTimeZoneRule::isEquivalentTo(*(InitialTimeZoneRule
*)rule2
);
117 U_CAPI UBool U_EXPORT2
118 izrule_getFirstStart(IZRule
* rule
, int32_t prevRawOffset
, int32_t prevDSTSavings
,
120 return ((const InitialTimeZoneRule
*)rule
)->InitialTimeZoneRule::getFirstStart(prevRawOffset
, prevDSTSavings
, result
);
123 U_CAPI UBool U_EXPORT2
124 izrule_getFinalStart(IZRule
* rule
, int32_t prevRawOffset
, int32_t prevDSTSavings
,
126 return ((InitialTimeZoneRule
*)rule
)->InitialTimeZoneRule::getFinalStart(prevRawOffset
, prevDSTSavings
, result
);
129 U_CAPI UBool U_EXPORT2
130 izrule_getNextStart(IZRule
* rule
, UDate base
, int32_t prevRawOffset
,
131 int32_t prevDSTSavings
, UBool inclusive
, UDate
& result
) {
132 return ((InitialTimeZoneRule
*)rule
)->InitialTimeZoneRule::getNextStart(base
, prevRawOffset
, prevDSTSavings
, inclusive
, result
);
135 U_CAPI UBool U_EXPORT2
136 izrule_getPreviousStart(IZRule
* rule
, UDate base
, int32_t prevRawOffset
,
137 int32_t prevDSTSavings
, UBool inclusive
, UDate
& result
) {
138 return ((InitialTimeZoneRule
*)rule
)->InitialTimeZoneRule::getPreviousStart(base
, prevRawOffset
, prevDSTSavings
, inclusive
, result
);
141 U_CAPI UClassID U_EXPORT2
142 izrule_getStaticClassID(IZRule
* rule
) {
143 return ((InitialTimeZoneRule
*)rule
)->InitialTimeZoneRule::getStaticClassID();
146 U_CAPI UClassID U_EXPORT2
147 izrule_getDynamicClassID(IZRule
* rule
) {
148 return ((InitialTimeZoneRule
*)rule
)->InitialTimeZoneRule::getDynamicClassID();