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