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