• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /*
4 *******************************************************************************
5 * Copyright (C) 2009-2011, International Business Machines Corporation and
6 * others. All Rights Reserved.
7 *******************************************************************************
8 */
9 
10 /**
11  * \file
12  * \brief C API: Time zone rule classes
13  */
14 
15 #include "unicode/utypes.h"
16 
17 #if !UCONFIG_NO_FORMATTING
18 
19 #include "unicode/uobject.h"
20 #include "zrule.h"
21 #include "unicode/tzrule.h"
22 #include "cmemory.h"
23 #include "unicode/ustring.h"
24 #include "unicode/parsepos.h"
25 
26 U_NAMESPACE_USE
27 
28 /*********************************************************************
29  * ZRule API
30  *********************************************************************/
31 
32 U_CAPI void U_EXPORT2
zrule_close(ZRule * rule)33 zrule_close(ZRule* rule) {
34     delete (TimeZoneRule*)rule;
35 }
36 
37 U_CAPI UBool U_EXPORT2
zrule_equals(const ZRule * rule1,const ZRule * rule2)38 zrule_equals(const ZRule* rule1, const ZRule* rule2) {
39     return *(const TimeZoneRule*)rule1 == *(const TimeZoneRule*)rule2;
40 }
41 
42 U_CAPI void U_EXPORT2
zrule_getName(ZRule * rule,UChar * name,int32_t nameLength)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);
48     return;
49 }
50 
51 U_CAPI int32_t U_EXPORT2
zrule_getRawOffset(ZRule * rule)52 zrule_getRawOffset(ZRule* rule) {
53     return ((TimeZoneRule*)rule)->TimeZoneRule::getRawOffset();
54 }
55 
56 U_CAPI int32_t U_EXPORT2
zrule_getDSTSavings(ZRule * rule)57 zrule_getDSTSavings(ZRule* rule) {
58     return ((TimeZoneRule*)rule)->TimeZoneRule::getDSTSavings();
59 }
60 
61 U_CAPI UBool U_EXPORT2
zrule_isEquivalentTo(ZRule * rule1,ZRule * rule2)62 zrule_isEquivalentTo(ZRule* rule1,  ZRule* rule2) {
63     return ((TimeZoneRule*)rule1)->TimeZoneRule::isEquivalentTo(*(TimeZoneRule*)rule2);
64 }
65 
66 /*********************************************************************
67  * IZRule API
68  *********************************************************************/
69 
70 U_CAPI IZRule* U_EXPORT2
izrule_open(const UChar * name,int32_t nameLength,int32_t rawOffset,int32_t dstSavings)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);
74 }
75 
76 U_CAPI void U_EXPORT2
izrule_close(IZRule * rule)77 izrule_close(IZRule* rule) {
78     delete (InitialTimeZoneRule*)rule;
79 }
80 
81 U_CAPI IZRule* U_EXPORT2
izrule_clone(IZRule * rule)82 izrule_clone(IZRule *rule) {
83     return (IZRule*) (((InitialTimeZoneRule*)rule)->InitialTimeZoneRule::clone());
84 }
85 
86 U_CAPI UBool U_EXPORT2
izrule_equals(const IZRule * rule1,const IZRule * rule2)87 izrule_equals(const IZRule* rule1, const IZRule* rule2) {
88     return *(const InitialTimeZoneRule*)rule1 == *(const InitialTimeZoneRule*)rule2;
89 }
90 
91 U_CAPI void U_EXPORT2
izrule_getName(IZRule * rule,UChar * & name,int32_t & nameLength)92 izrule_getName(IZRule* rule, UChar* & name, int32_t & nameLength) {
93     // UnicodeString s(nameLength==-1, name, nameLength);
94     UnicodeString s;
95     ((InitialTimeZoneRule*)rule)->InitialTimeZoneRule::getName(s);
96     nameLength = s.length();
97     name = (UChar*)uprv_malloc(nameLength);
98     memcpy(name, s.getBuffer(), nameLength);
99     return;
100 }
101 
102 U_CAPI int32_t U_EXPORT2
izrule_getRawOffset(IZRule * rule)103 izrule_getRawOffset(IZRule* rule) {
104     return ((InitialTimeZoneRule*)rule)->InitialTimeZoneRule::getRawOffset();
105 }
106 
107 U_CAPI int32_t U_EXPORT2
izrule_getDSTSavings(IZRule * rule)108 izrule_getDSTSavings(IZRule* rule) {
109     return ((InitialTimeZoneRule*)rule)->InitialTimeZoneRule::getDSTSavings();
110 }
111 
112 U_CAPI UBool U_EXPORT2
izrule_isEquivalentTo(IZRule * rule1,IZRule * rule2)113 izrule_isEquivalentTo(IZRule* rule1,  IZRule* rule2) {
114     return ((InitialTimeZoneRule*)rule1)->InitialTimeZoneRule::isEquivalentTo(*(InitialTimeZoneRule*)rule2);
115 }
116 
117 U_CAPI UBool U_EXPORT2
izrule_getFirstStart(IZRule * rule,int32_t prevRawOffset,int32_t prevDSTSavings,UDate & result)118 izrule_getFirstStart(IZRule* rule, int32_t prevRawOffset, int32_t prevDSTSavings,
119                     UDate& result) {
120     return ((const InitialTimeZoneRule*)rule)->InitialTimeZoneRule::getFirstStart(prevRawOffset, prevDSTSavings, result);
121 }
122 
123 U_CAPI UBool U_EXPORT2
izrule_getFinalStart(IZRule * rule,int32_t prevRawOffset,int32_t prevDSTSavings,UDate & result)124 izrule_getFinalStart(IZRule* rule, int32_t prevRawOffset, int32_t prevDSTSavings,
125                     UDate& result) {
126     return ((InitialTimeZoneRule*)rule)->InitialTimeZoneRule::getFinalStart(prevRawOffset, prevDSTSavings, result);
127 }
128 
129 U_CAPI UBool U_EXPORT2
izrule_getNextStart(IZRule * rule,UDate base,int32_t prevRawOffset,int32_t prevDSTSavings,UBool inclusive,UDate & result)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);
133 }
134 
135 U_CAPI UBool U_EXPORT2
izrule_getPreviousStart(IZRule * rule,UDate base,int32_t prevRawOffset,int32_t prevDSTSavings,UBool inclusive,UDate & result)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);
139 }
140 
141 U_CAPI UClassID U_EXPORT2
izrule_getStaticClassID(IZRule * rule)142 izrule_getStaticClassID(IZRule* rule) {
143     return ((InitialTimeZoneRule*)rule)->InitialTimeZoneRule::getStaticClassID();
144 }
145 
146 U_CAPI UClassID U_EXPORT2
izrule_getDynamicClassID(IZRule * rule)147 izrule_getDynamicClassID(IZRule* rule) {
148     return ((InitialTimeZoneRule*)rule)->InitialTimeZoneRule::getDynamicClassID();
149 }
150 
151 #endif
152