zrule.cpp revision 50294ead5e5d23f5bbfed76e00e6b510bd41eee1
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: Time zone rule classes 11 */ 12 13#include "unicode/utypes.h" 14#include "unicode/utypes.h" 15#include "unicode/uobject.h" 16#include "zrule.h" 17#include "unicode/tzrule.h" 18#include "cmemory.h" 19#include "unicode/ustring.h" 20#include "unicode/parsepos.h" 21 22U_NAMESPACE_USE 23 24/********************************************************************* 25 * ZRule API 26 *********************************************************************/ 27 28U_CAPI void U_EXPORT2 29zrule_close(ZRule* rule) { 30 delete (TimeZoneRule*)rule; 31} 32 33U_CAPI UBool U_EXPORT2 34zrule_equals(const ZRule* rule1, const ZRule* rule2) { 35 return *(const TimeZoneRule*)rule1 == *(const TimeZoneRule*)rule2; 36} 37 38U_CAPI void U_EXPORT2 39zrule_getName(ZRule* rule, UChar* name, int32_t nameLength) { 40 UnicodeString s(nameLength==-1, name, nameLength); 41 s = ((TimeZoneRule*)rule)->TimeZoneRule::getName(s); 42 nameLength = s.length(); 43 memcpy(name, s.getBuffer(), nameLength); 44 return; 45} 46 47U_CAPI int32_t U_EXPORT2 48zrule_getRawOffset(ZRule* rule) { 49 return ((TimeZoneRule*)rule)->TimeZoneRule::getRawOffset(); 50} 51 52U_CAPI int32_t U_EXPORT2 53zrule_getDSTSavings(ZRule* rule) { 54 return ((TimeZoneRule*)rule)->TimeZoneRule::getDSTSavings(); 55} 56 57U_CAPI UBool U_EXPORT2 58zrule_isEquivalentTo(ZRule* rule1, ZRule* rule2) { 59 return ((TimeZoneRule*)rule1)->TimeZoneRule::isEquivalentTo(*(TimeZoneRule*)rule2); 60} 61 62/********************************************************************* 63 * IZRule API 64 *********************************************************************/ 65 66U_CAPI IZRule* U_EXPORT2 67izrule_open(const UChar* name, int32_t nameLength, int32_t rawOffset, int32_t dstSavings) { 68 UnicodeString s(nameLength==-1, name, nameLength); 69 return (IZRule*) new InitialTimeZoneRule(name, rawOffset, dstSavings); 70} 71 72U_CAPI void U_EXPORT2 73izrule_close(IZRule* rule) { 74 delete (InitialTimeZoneRule*)rule; 75} 76 77U_CAPI IZRule* U_EXPORT2 78izrule_clone(IZRule *rule) { 79 return (IZRule*) (((InitialTimeZoneRule*)rule)->InitialTimeZoneRule::clone()); 80} 81 82U_CAPI UBool U_EXPORT2 83izrule_equals(const IZRule* rule1, const IZRule* rule2) { 84 return *(const InitialTimeZoneRule*)rule1 == *(const InitialTimeZoneRule*)rule2; 85} 86 87U_CAPI void U_EXPORT2 88izrule_getName(IZRule* rule, UChar* & name, int32_t & nameLength) { 89 // UnicodeString s(nameLength==-1, name, nameLength); 90 UnicodeString s; 91 ((InitialTimeZoneRule*)rule)->InitialTimeZoneRule::getName(s); 92 nameLength = s.length(); 93 name = (UChar*)uprv_malloc(nameLength); 94 memcpy(name, s.getBuffer(), nameLength); 95 return; 96} 97 98U_CAPI int32_t U_EXPORT2 99izrule_getRawOffset(IZRule* rule) { 100 return ((InitialTimeZoneRule*)rule)->InitialTimeZoneRule::getRawOffset(); 101} 102 103U_CAPI int32_t U_EXPORT2 104izrule_getDSTSavings(IZRule* rule) { 105 return ((InitialTimeZoneRule*)rule)->InitialTimeZoneRule::getDSTSavings(); 106} 107 108U_CAPI UBool U_EXPORT2 109izrule_isEquivalentTo(IZRule* rule1, IZRule* rule2) { 110 return ((InitialTimeZoneRule*)rule1)->InitialTimeZoneRule::isEquivalentTo(*(InitialTimeZoneRule*)rule2); 111} 112 113U_CAPI UBool U_EXPORT2 114izrule_getFirstStart(IZRule* rule, int32_t prevRawOffset, int32_t prevDSTSavings, 115 UDate& result) { 116 return ((const InitialTimeZoneRule*)rule)->InitialTimeZoneRule::getFirstStart(prevRawOffset, prevDSTSavings, result); 117} 118 119U_CAPI UBool U_EXPORT2 120izrule_getFinalStart(IZRule* rule, int32_t prevRawOffset, int32_t prevDSTSavings, 121 UDate& result) { 122 return ((InitialTimeZoneRule*)rule)->InitialTimeZoneRule::getFinalStart(prevRawOffset, prevDSTSavings, result); 123} 124 125U_CAPI UBool U_EXPORT2 126izrule_getNextStart(IZRule* rule, UDate base, int32_t prevRawOffset, 127 int32_t prevDSTSavings, UBool inclusive, UDate& result) { 128 return ((InitialTimeZoneRule*)rule)->InitialTimeZoneRule::getNextStart(base, prevRawOffset, prevDSTSavings, inclusive, result); 129} 130 131U_CAPI UBool U_EXPORT2 132izrule_getPreviousStart(IZRule* rule, UDate base, int32_t prevRawOffset, 133 int32_t prevDSTSavings, UBool inclusive, UDate& result) { 134 return ((InitialTimeZoneRule*)rule)->InitialTimeZoneRule::getPreviousStart(base, prevRawOffset, prevDSTSavings, inclusive, result); 135} 136 137U_CAPI UClassID U_EXPORT2 138izrule_getStaticClassID(IZRule* rule) { 139 return ((InitialTimeZoneRule*)rule)->InitialTimeZoneRule::getStaticClassID(); 140} 141 142U_CAPI UClassID U_EXPORT2 143izrule_getDynamicClassID(IZRule* rule) { 144 return ((InitialTimeZoneRule*)rule)->InitialTimeZoneRule::getDynamicClassID(); 145} 146 147