1// Copyright (C) 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 26U_NAMESPACE_USE 27 28U_CAPI VZone* U_EXPORT2 29vzone_openID(const UChar* ID, int32_t idLength){ 30 UnicodeString s(idLength==-1, ID, idLength); 31 return (VZone*) (VTimeZone::createVTimeZoneByID(s)); 32} 33 34U_CAPI VZone* U_EXPORT2 35vzone_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 40U_CAPI void U_EXPORT2 41vzone_close(VZone* zone) { 42 delete (VTimeZone*)zone; 43} 44 45U_CAPI VZone* U_EXPORT2 46vzone_clone(const VZone *zone) { 47 return (VZone*) (((VTimeZone*)zone)->VTimeZone::clone()); 48} 49 50U_CAPI UBool U_EXPORT2 51vzone_equals(const VZone* zone1, const VZone* zone2) { 52 return *(const VTimeZone*)zone1 == *(const VTimeZone*)zone2; 53} 54 55U_CAPI UBool U_EXPORT2 56vzone_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 66U_CAPI void U_EXPORT2 67vzone_setTZURL(VZone* zone, UChar* url, int32_t urlLength) { 68 UnicodeString s(urlLength==-1, url, urlLength); 69 ((VTimeZone*)zone)->VTimeZone::setTZURL(s); 70} 71 72U_CAPI UBool U_EXPORT2 73vzone_getLastModified(VZone* zone, UDate& lastModified) { 74 return ((VTimeZone*)zone)->VTimeZone::getLastModified(lastModified); 75} 76 77U_CAPI void U_EXPORT2 78vzone_setLastModified(VZone* zone, UDate lastModified) { 79 return ((VTimeZone*)zone)->VTimeZone::setLastModified(lastModified); 80} 81 82U_CAPI void U_EXPORT2 83vzone_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 94U_CAPI void U_EXPORT2 95vzone_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 106U_CAPI void U_EXPORT2 107vzone_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 118U_CAPI int32_t U_EXPORT2 119vzone_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 124U_CAPI int32_t U_EXPORT2 125vzone_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 131U_CAPI void U_EXPORT2 132vzone_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 137U_CAPI void U_EXPORT2 138vzone_setRawOffset(VZone* zone, int32_t offsetMillis) { 139 return ((VTimeZone*)zone)->VTimeZone::setRawOffset(offsetMillis); 140} 141 142U_CAPI int32_t U_EXPORT2 143vzone_getRawOffset(VZone* zone) { 144 return ((VTimeZone*)zone)->VTimeZone::getRawOffset(); 145} 146 147U_CAPI UBool U_EXPORT2 148vzone_useDaylightTime(VZone* zone) { 149 return ((VTimeZone*)zone)->VTimeZone::useDaylightTime(); 150} 151 152U_CAPI UBool U_EXPORT2 153vzone_inDaylightTime(VZone* zone, UDate date, UErrorCode& status) { 154 return ((VTimeZone*)zone)->VTimeZone::inDaylightTime(date, status); 155} 156 157U_CAPI UBool U_EXPORT2 158vzone_hasSameRules(VZone* zone, const VZone* other) { 159 return ((VTimeZone*)zone)->VTimeZone::hasSameRules(*(VTimeZone*)other); 160} 161 162U_CAPI UBool U_EXPORT2 163vzone_getNextTransition(VZone* zone, UDate base, UBool inclusive, ZTrans* result) { 164 return ((VTimeZone*)zone)->VTimeZone::getNextTransition(base, inclusive, *(TimeZoneTransition*)result); 165} 166 167U_CAPI UBool U_EXPORT2 168vzone_getPreviousTransition(VZone* zone, UDate base, UBool inclusive, ZTrans* result) { 169 return ((VTimeZone*)zone)->VTimeZone::getPreviousTransition(base, inclusive, *(TimeZoneTransition*)result); 170} 171 172U_CAPI int32_t U_EXPORT2 173vzone_countTransitionRules(VZone* zone, UErrorCode& status) { 174 return ((VTimeZone*)zone)->VTimeZone::countTransitionRules(status); 175} 176 177U_CAPI UClassID U_EXPORT2 178vzone_getStaticClassID(VZone* zone) { 179 return ((VTimeZone*)zone)->VTimeZone::getStaticClassID(); 180} 181 182U_CAPI UClassID U_EXPORT2 183vzone_getDynamicClassID(VZone* zone) { 184 return ((VTimeZone*)zone)->VTimeZone::getDynamicClassID(); 185} 186 187#endif 188