vzone.cpp (5690B)
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 29 vzone_openID(const char16_t* 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 35 vzone_openData(const char16_t* 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 41 vzone_close(VZone* zone) { 42 delete (VTimeZone*)zone; 43 } 44 45 U_CAPI VZone* U_EXPORT2 46 vzone_clone(const VZone *zone) { 47 return (VZone*) (((VTimeZone*)zone)->VTimeZone::clone()); 48 } 49 50 U_CAPI UBool U_EXPORT2 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 56 vzone_getTZURL(VZone* zone, char16_t* & 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 67 vzone_setTZURL(VZone* zone, char16_t* 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 73 vzone_getLastModified(VZone* zone, UDate& lastModified) { 74 return ((VTimeZone*)zone)->VTimeZone::getLastModified(lastModified); 75 } 76 77 U_CAPI void U_EXPORT2 78 vzone_setLastModified(VZone* zone, UDate lastModified) { 79 return ((VTimeZone*)zone)->VTimeZone::setLastModified(lastModified); 80 } 81 82 U_CAPI void U_EXPORT2 83 vzone_write(VZone* zone, char16_t* & result, int32_t & resultLength, UErrorCode& status) { 84 UnicodeString s; 85 ((VTimeZone*)zone)->VTimeZone::write(s, status); 86 87 resultLength = s.length(); 88 result = (char16_t*)uprv_malloc(resultLength); 89 memcpy(result,s.getBuffer(),resultLength); 90 } 91 92 U_CAPI void U_EXPORT2 93 vzone_writeFromStart(VZone* zone, UDate start, char16_t* & result, int32_t & resultLength, UErrorCode& status) { 94 UnicodeString s; 95 ((VTimeZone*)zone)->VTimeZone::write(start, s, status); 96 97 resultLength = s.length(); 98 result = (char16_t*)uprv_malloc(resultLength); 99 memcpy(result,s.getBuffer(),resultLength); 100 } 101 102 U_CAPI void U_EXPORT2 103 vzone_writeSimple(VZone* zone, UDate time, char16_t* & result, int32_t & resultLength, UErrorCode& status) { 104 UnicodeString s; 105 ((VTimeZone*)zone)->VTimeZone::writeSimple(time, s, status); 106 107 resultLength = s.length(); 108 result = (char16_t*)uprv_malloc(resultLength); 109 memcpy(result,s.getBuffer(),resultLength); 110 } 111 112 U_CAPI int32_t U_EXPORT2 113 vzone_getOffset(VZone* zone, uint8_t era, int32_t year, int32_t month, int32_t day, 114 uint8_t dayOfWeek, int32_t millis, UErrorCode& status) { 115 return ((VTimeZone*)zone)->VTimeZone::getOffset(era, year, month, day, dayOfWeek, millis, status); 116 } 117 118 U_CAPI int32_t U_EXPORT2 119 vzone_getOffset2(VZone* zone, uint8_t era, int32_t year, int32_t month, int32_t day, 120 uint8_t dayOfWeek, int32_t millis, 121 int32_t monthLength, UErrorCode& status) { 122 return ((VTimeZone*)zone)->VTimeZone::getOffset(era, year, month, day, dayOfWeek, millis, monthLength, status); 123 } 124 125 U_CAPI void U_EXPORT2 126 vzone_getOffset3(VZone* zone, UDate date, UBool local, int32_t& rawOffset, 127 int32_t& dstOffset, UErrorCode& ec) { 128 return ((VTimeZone*)zone)->VTimeZone::getOffset(date, local, rawOffset, dstOffset, ec); 129 } 130 131 U_CAPI void U_EXPORT2 132 vzone_setRawOffset(VZone* zone, int32_t offsetMillis) { 133 return ((VTimeZone*)zone)->VTimeZone::setRawOffset(offsetMillis); 134 } 135 136 U_CAPI int32_t U_EXPORT2 137 vzone_getRawOffset(VZone* zone) { 138 return ((VTimeZone*)zone)->VTimeZone::getRawOffset(); 139 } 140 141 U_CAPI UBool U_EXPORT2 142 vzone_useDaylightTime(VZone* zone) { 143 return ((VTimeZone*)zone)->VTimeZone::useDaylightTime(); 144 } 145 146 U_CAPI UBool U_EXPORT2 147 vzone_inDaylightTime(VZone* zone, UDate date, UErrorCode& status) { 148 return ((VTimeZone*)zone)->VTimeZone::inDaylightTime(date, status); 149 } 150 151 U_CAPI UBool U_EXPORT2 152 vzone_hasSameRules(VZone* zone, const VZone* other) { 153 return ((VTimeZone*)zone)->VTimeZone::hasSameRules(*(VTimeZone*)other); 154 } 155 156 U_CAPI UBool U_EXPORT2 157 vzone_getNextTransition(VZone* zone, UDate base, UBool inclusive, ZTrans* result) { 158 return ((VTimeZone*)zone)->VTimeZone::getNextTransition(base, inclusive, *(TimeZoneTransition*)result); 159 } 160 161 U_CAPI UBool U_EXPORT2 162 vzone_getPreviousTransition(VZone* zone, UDate base, UBool inclusive, ZTrans* result) { 163 return ((VTimeZone*)zone)->VTimeZone::getPreviousTransition(base, inclusive, *(TimeZoneTransition*)result); 164 } 165 166 U_CAPI int32_t U_EXPORT2 167 vzone_countTransitionRules(VZone* zone, UErrorCode& status) { 168 return ((VTimeZone*)zone)->VTimeZone::countTransitionRules(status); 169 } 170 171 U_CAPI UClassID U_EXPORT2 172 vzone_getStaticClassID(VZone* zone) { 173 return ((VTimeZone*)zone)->VTimeZone::getStaticClassID(); 174 } 175 176 U_CAPI UClassID U_EXPORT2 177 vzone_getDynamicClassID(VZone* zone) { 178 return ((VTimeZone*)zone)->VTimeZone::getDynamicClassID(); 179 } 180 181 #endif