• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 *******************************************************************************
3 * Copyright (C) 2009-2010, International Business Machines Corporation and         *
4 * others. All Rights Reserved.                                                *
5 *******************************************************************************
6 */
7 
8 /**
9  * \file
10  * \brief C API: VTimeZone classes
11  */
12 
13 #include "unicode/utypes.h"
14 #include "unicode/utypes.h"
15 #include "unicode/uobject.h"
16 #include "vzone.h"
17 #include "unicode/vtzone.h"
18 #include "cmemory.h"
19 #include "unicode/ustring.h"
20 #include "unicode/parsepos.h"
21 
22 U_NAMESPACE_USE
23 
24 U_CAPI VZone* U_EXPORT2
vzone_openID(const UChar * ID,int32_t idLength)25 vzone_openID(const UChar* ID, int32_t idLength){
26     UnicodeString s(idLength==-1, ID, idLength);
27     return (VZone*) (VTimeZone::createVTimeZoneByID(s));
28 }
29 
30 U_CAPI VZone* U_EXPORT2
vzone_openData(const UChar * vtzdata,int32_t vtzdataLength,UErrorCode & status)31 vzone_openData(const UChar* vtzdata, int32_t vtzdataLength, UErrorCode& status) {
32     UnicodeString s(vtzdataLength==-1, vtzdata, vtzdataLength);
33     return (VZone*) (VTimeZone::createVTimeZone(s,status));
34 }
35 
36 U_CAPI void U_EXPORT2
vzone_close(VZone * zone)37 vzone_close(VZone* zone) {
38     delete (VTimeZone*)zone;
39 }
40 
41 U_CAPI VZone* U_EXPORT2
vzone_clone(const VZone * zone)42 vzone_clone(const VZone *zone) {
43     return (VZone*) (((VTimeZone*)zone)->VTimeZone::clone());
44 }
45 
46 U_CAPI UBool U_EXPORT2
vzone_equals(const VZone * zone1,const VZone * zone2)47 vzone_equals(const VZone* zone1, const VZone* zone2) {
48     return *(const VTimeZone*)zone1 == *(const VTimeZone*)zone2;
49 }
50 
51 U_CAPI UBool U_EXPORT2
vzone_getTZURL(VZone * zone,UChar * & url,int32_t & urlLength)52 vzone_getTZURL(VZone* zone, UChar* & url, int32_t & urlLength) {
53     UnicodeString s;
54     UBool b = ((VTimeZone*)zone)->VTimeZone::getTZURL(s);
55 
56     urlLength = s.length();
57     memcpy(url,s.getBuffer(),urlLength);
58 
59     return b;
60 }
61 
62 U_CAPI void U_EXPORT2
vzone_setTZURL(VZone * zone,UChar * url,int32_t urlLength)63 vzone_setTZURL(VZone* zone, UChar* url, int32_t urlLength) {
64     UnicodeString s(urlLength==-1, url, urlLength);
65     return ((VTimeZone*)zone)->VTimeZone::setTZURL(url);
66 }
67 
68 U_CAPI UBool U_EXPORT2
vzone_getLastModified(VZone * zone,UDate & lastModified)69 vzone_getLastModified(VZone* zone, UDate& lastModified) {
70     return ((VTimeZone*)zone)->VTimeZone::getLastModified(lastModified);
71 }
72 
73 U_CAPI void U_EXPORT2
vzone_setLastModified(VZone * zone,UDate lastModified)74 vzone_setLastModified(VZone* zone, UDate lastModified) {
75     return ((VTimeZone*)zone)->VTimeZone::setLastModified(lastModified);
76 }
77 
78 U_CAPI void U_EXPORT2
vzone_write(VZone * zone,UChar * & result,int32_t & resultLength,UErrorCode & status)79 vzone_write(VZone* zone, UChar* & result, int32_t & resultLength, UErrorCode& status) {
80     UnicodeString s;
81     ((VTimeZone*)zone)->VTimeZone::write(s, status);
82 
83     resultLength = s.length();
84     result = (UChar*)uprv_malloc(resultLength);
85     memcpy(result,s.getBuffer(),resultLength);
86 
87     return;
88 }
89 
90 U_CAPI void U_EXPORT2
vzone_writeFromStart(VZone * zone,UDate start,UChar * & result,int32_t & resultLength,UErrorCode & status)91 vzone_writeFromStart(VZone* zone, UDate start, UChar* & result, int32_t & resultLength, UErrorCode& status) {
92     UnicodeString s;
93     ((VTimeZone*)zone)->VTimeZone::write(start, s, status);
94 
95     resultLength = s.length();
96     result = (UChar*)uprv_malloc(resultLength);
97     memcpy(result,s.getBuffer(),resultLength);
98 
99     return;
100 }
101 
102 U_CAPI void U_EXPORT2
vzone_writeSimple(VZone * zone,UDate time,UChar * & result,int32_t & resultLength,UErrorCode & status)103 vzone_writeSimple(VZone* zone, UDate time, UChar* & result, int32_t & resultLength, UErrorCode& status) {
104     UnicodeString s;
105     ((VTimeZone*)zone)->VTimeZone::writeSimple(time, s, status);
106 
107     resultLength = s.length();
108     result = (UChar*)uprv_malloc(resultLength);
109     memcpy(result,s.getBuffer(),resultLength);
110 
111     return;
112 }
113 
114 U_CAPI int32_t U_EXPORT2
vzone_getOffset(VZone * zone,uint8_t era,int32_t year,int32_t month,int32_t day,uint8_t dayOfWeek,int32_t millis,UErrorCode & status)115 vzone_getOffset(VZone* zone, uint8_t era, int32_t year, int32_t month, int32_t day,
116                 uint8_t dayOfWeek, int32_t millis, UErrorCode& status) {
117     return ((VTimeZone*)zone)->VTimeZone::getOffset(era, year, month, day, dayOfWeek, millis, status);
118 }
119 
120 U_CAPI int32_t U_EXPORT2
vzone_getOffset2(VZone * zone,uint8_t era,int32_t year,int32_t month,int32_t day,uint8_t dayOfWeek,int32_t millis,int32_t monthLength,UErrorCode & status)121 vzone_getOffset2(VZone* zone, uint8_t era, int32_t year, int32_t month, int32_t day,
122                 uint8_t dayOfWeek, int32_t millis,
123                 int32_t monthLength, UErrorCode& status) {
124     return ((VTimeZone*)zone)->VTimeZone::getOffset(era, year, month, day, dayOfWeek, millis, monthLength, status);
125 }
126 
127 U_CAPI void U_EXPORT2
vzone_getOffset3(VZone * zone,UDate date,UBool local,int32_t & rawOffset,int32_t & dstOffset,UErrorCode & ec)128 vzone_getOffset3(VZone* zone, UDate date, UBool local, int32_t& rawOffset,
129                 int32_t& dstOffset, UErrorCode& ec) {
130     return ((VTimeZone*)zone)->VTimeZone::getOffset(date, local, rawOffset, dstOffset, ec);
131 }
132 
133 U_CAPI void U_EXPORT2
vzone_setRawOffset(VZone * zone,int32_t offsetMillis)134 vzone_setRawOffset(VZone* zone, int32_t offsetMillis) {
135     return ((VTimeZone*)zone)->VTimeZone::setRawOffset(offsetMillis);
136 }
137 
138 U_CAPI int32_t U_EXPORT2
vzone_getRawOffset(VZone * zone)139 vzone_getRawOffset(VZone* zone) {
140     return ((VTimeZone*)zone)->VTimeZone::getRawOffset();
141 }
142 
143 U_CAPI UBool U_EXPORT2
vzone_useDaylightTime(VZone * zone)144 vzone_useDaylightTime(VZone* zone) {
145     return ((VTimeZone*)zone)->VTimeZone::useDaylightTime();
146 }
147 
148 U_CAPI UBool U_EXPORT2
vzone_inDaylightTime(VZone * zone,UDate date,UErrorCode & status)149 vzone_inDaylightTime(VZone* zone, UDate date, UErrorCode& status) {
150     return ((VTimeZone*)zone)->VTimeZone::inDaylightTime(date, status);
151 }
152 
153 U_CAPI UBool U_EXPORT2
vzone_hasSameRules(VZone * zone,const VZone * other)154 vzone_hasSameRules(VZone* zone, const VZone* other) {
155     return ((VTimeZone*)zone)->VTimeZone::hasSameRules(*(VTimeZone*)other);
156 }
157 
158 U_CAPI UBool U_EXPORT2
vzone_getNextTransition(VZone * zone,UDate base,UBool inclusive,ZTrans * result)159 vzone_getNextTransition(VZone* zone, UDate base, UBool inclusive, ZTrans* result) {
160     return ((VTimeZone*)zone)->VTimeZone::getNextTransition(base, inclusive, *(TimeZoneTransition*)result);
161 }
162 
163 U_CAPI UBool U_EXPORT2
vzone_getPreviousTransition(VZone * zone,UDate base,UBool inclusive,ZTrans * result)164 vzone_getPreviousTransition(VZone* zone, UDate base, UBool inclusive, ZTrans* result) {
165     return ((VTimeZone*)zone)->VTimeZone::getPreviousTransition(base, inclusive, *(TimeZoneTransition*)result);
166 }
167 
168 U_CAPI int32_t U_EXPORT2
vzone_countTransitionRules(VZone * zone,UErrorCode & status)169 vzone_countTransitionRules(VZone* zone, UErrorCode& status) {
170     return ((VTimeZone*)zone)->VTimeZone::countTransitionRules(status);
171 }
172 
173 U_CAPI UClassID U_EXPORT2
vzone_getStaticClassID(VZone * zone)174 vzone_getStaticClassID(VZone* zone) {
175     return ((VTimeZone*)zone)->VTimeZone::getStaticClassID();
176 }
177 
178 U_CAPI UClassID U_EXPORT2
vzone_getDynamicClassID(VZone * zone)179 vzone_getDynamicClassID(VZone* zone) {
180     return ((VTimeZone*)zone)->VTimeZone::getDynamicClassID();
181 }
182