| 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 |
| 33 |
zrule_close(ZRule* rule) { |
| 34 |
delete (TimeZoneRule*)rule; |
| 35 |
} |
| 36 |
|
| 37 |
U_CAPI UBool U_EXPORT2 |
| 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 |
| 43 |
zrule_getName(ZRule* rule, char16_t* 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 |
} |
| 49 |
|
| 50 |
U_CAPI int32_t U_EXPORT2 |
| 51 |
zrule_getRawOffset(ZRule* rule) { |
| 52 |
return ((TimeZoneRule*)rule)->TimeZoneRule::getRawOffset(); |
| 53 |
} |
| 54 |
|
| 55 |
U_CAPI int32_t U_EXPORT2 |
| 56 |
zrule_getDSTSavings(ZRule* rule) { |
| 57 |
return ((TimeZoneRule*)rule)->TimeZoneRule::getDSTSavings(); |
| 58 |
} |
| 59 |
|
| 60 |
U_CAPI UBool U_EXPORT2 |
| 61 |
zrule_isEquivalentTo(ZRule* rule1, ZRule* rule2) { |
| 62 |
return ((TimeZoneRule*)rule1)->TimeZoneRule::isEquivalentTo(*(TimeZoneRule*)rule2); |
| 63 |
} |
| 64 |
|
| 65 |
/********************************************************************* |
| 66 |
* IZRule API |
| 67 |
*********************************************************************/ |
| 68 |
|
| 69 |
U_CAPI IZRule* U_EXPORT2 |
| 70 |
izrule_open(const char16_t* name, int32_t nameLength, int32_t rawOffset, int32_t dstSavings) { |
| 71 |
UnicodeString s(nameLength==-1, name, nameLength); |
| 72 |
return (IZRule*) new InitialTimeZoneRule(s, rawOffset, dstSavings); |
| 73 |
} |
| 74 |
|
| 75 |
U_CAPI void U_EXPORT2 |
| 76 |
izrule_close(IZRule* rule) { |
| 77 |
delete (InitialTimeZoneRule*)rule; |
| 78 |
} |
| 79 |
|
| 80 |
U_CAPI IZRule* U_EXPORT2 |
| 81 |
izrule_clone(IZRule *rule) { |
| 82 |
return (IZRule*) (((InitialTimeZoneRule*)rule)->InitialTimeZoneRule::clone()); |
| 83 |
} |
| 84 |
|
| 85 |
U_CAPI UBool U_EXPORT2 |
| 86 |
izrule_equals(const IZRule* rule1, const IZRule* rule2) { |
| 87 |
return *(const InitialTimeZoneRule*)rule1 == *(const InitialTimeZoneRule*)rule2; |
| 88 |
} |
| 89 |
|
| 90 |
U_CAPI void U_EXPORT2 |
| 91 |
izrule_getName(IZRule* rule, char16_t* & name, int32_t & nameLength) { |
| 92 |
// UnicodeString s(nameLength==-1, name, nameLength); |
| 93 |
UnicodeString s; |
| 94 |
((InitialTimeZoneRule*)rule)->InitialTimeZoneRule::getName(s); |
| 95 |
nameLength = s.length(); |
| 96 |
name = (char16_t*)uprv_malloc(nameLength); |
| 97 |
memcpy(name, s.getBuffer(), nameLength); |
| 98 |
} |
| 99 |
|
| 100 |
U_CAPI int32_t U_EXPORT2 |
| 101 |
izrule_getRawOffset(IZRule* rule) { |
| 102 |
return ((InitialTimeZoneRule*)rule)->InitialTimeZoneRule::getRawOffset(); |
| 103 |
} |
| 104 |
|
| 105 |
U_CAPI int32_t U_EXPORT2 |
| 106 |
izrule_getDSTSavings(IZRule* rule) { |
| 107 |
return ((InitialTimeZoneRule*)rule)->InitialTimeZoneRule::getDSTSavings(); |
| 108 |
} |
| 109 |
|
| 110 |
U_CAPI UBool U_EXPORT2 |
| 111 |
izrule_isEquivalentTo(IZRule* rule1, IZRule* rule2) { |
| 112 |
return ((InitialTimeZoneRule*)rule1)->InitialTimeZoneRule::isEquivalentTo(*(InitialTimeZoneRule*)rule2); |
| 113 |
} |
| 114 |
|
| 115 |
U_CAPI UBool U_EXPORT2 |
| 116 |
izrule_getFirstStart(IZRule* rule, int32_t prevRawOffset, int32_t prevDSTSavings, |
| 117 |
UDate& result) { |
| 118 |
return ((const InitialTimeZoneRule*)rule)->InitialTimeZoneRule::getFirstStart(prevRawOffset, prevDSTSavings, result); |
| 119 |
} |
| 120 |
|
| 121 |
U_CAPI UBool U_EXPORT2 |
| 122 |
izrule_getFinalStart(IZRule* rule, int32_t prevRawOffset, int32_t prevDSTSavings, |
| 123 |
UDate& result) { |
| 124 |
return ((InitialTimeZoneRule*)rule)->InitialTimeZoneRule::getFinalStart(prevRawOffset, prevDSTSavings, result); |
| 125 |
} |
| 126 |
|
| 127 |
U_CAPI UBool U_EXPORT2 |
| 128 |
izrule_getNextStart(IZRule* rule, UDate base, int32_t prevRawOffset, |
| 129 |
int32_t prevDSTSavings, UBool inclusive, UDate& result) { |
| 130 |
return ((InitialTimeZoneRule*)rule)->InitialTimeZoneRule::getNextStart(base, prevRawOffset, prevDSTSavings, inclusive, result); |
| 131 |
} |
| 132 |
|
| 133 |
U_CAPI UBool U_EXPORT2 |
| 134 |
izrule_getPreviousStart(IZRule* rule, UDate base, int32_t prevRawOffset, |
| 135 |
int32_t prevDSTSavings, UBool inclusive, UDate& result) { |
| 136 |
return ((InitialTimeZoneRule*)rule)->InitialTimeZoneRule::getPreviousStart(base, prevRawOffset, prevDSTSavings, inclusive, result); |
| 137 |
} |
| 138 |
|
| 139 |
U_CAPI UClassID U_EXPORT2 |
| 140 |
izrule_getStaticClassID(IZRule* rule) { |
| 141 |
return ((InitialTimeZoneRule*)rule)->InitialTimeZoneRule::getStaticClassID(); |
| 142 |
} |
| 143 |
|
| 144 |
U_CAPI UClassID U_EXPORT2 |
| 145 |
izrule_getDynamicClassID(IZRule* rule) { |
| 146 |
return ((InitialTimeZoneRule*)rule)->InitialTimeZoneRule::getDynamicClassID(); |
| 147 |
} |
| 148 |
|
| 149 |
#endif |