1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /*
4 *******************************************************************************
5 * Copyright (C) 2007-2012, International Business Machines Corporation and
6 * others. All Rights Reserved.
7 *******************************************************************************
8 */
9
10 #include "utypeinfo.h" // for 'typeid' to work
11
12 #include "unicode/utypes.h"
13
14 #if !UCONFIG_NO_FORMATTING
15
16 #include "unicode/tzrule.h"
17 #include "unicode/tztrans.h"
18
19 U_NAMESPACE_BEGIN
20
UOBJECT_DEFINE_RTTI_IMPLEMENTATION(TimeZoneTransition)21 UOBJECT_DEFINE_RTTI_IMPLEMENTATION(TimeZoneTransition)
22
23 TimeZoneTransition::TimeZoneTransition(UDate time, const TimeZoneRule& from, const TimeZoneRule& to)
24 : UObject(), fTime(time), fFrom(from.clone()), fTo(to.clone()) {
25 }
26
TimeZoneTransition()27 TimeZoneTransition::TimeZoneTransition()
28 : UObject(), fTime(0), fFrom(NULL), fTo(NULL) {
29 }
30
TimeZoneTransition(const TimeZoneTransition & source)31 TimeZoneTransition::TimeZoneTransition(const TimeZoneTransition& source)
32 : UObject(), fTime(source.fTime), fFrom(NULL), fTo(NULL) {
33 if (source.fFrom != NULL) {
34 fFrom = source.fFrom->clone();
35 }
36
37 if (source.fTo != NULL) {
38 fTo = source.fTo->clone();
39 }
40 }
41
~TimeZoneTransition()42 TimeZoneTransition::~TimeZoneTransition() {
43 if (fFrom != NULL) {
44 delete fFrom;
45 }
46 if (fTo != NULL) {
47 delete fTo;
48 }
49 }
50
51 TimeZoneTransition*
clone(void) const52 TimeZoneTransition::clone(void) const {
53 return new TimeZoneTransition(*this);
54 }
55
56 TimeZoneTransition&
operator =(const TimeZoneTransition & right)57 TimeZoneTransition::operator=(const TimeZoneTransition& right) {
58 if (this != &right) {
59 fTime = right.fTime;
60 setFrom(*right.fFrom);
61 setTo(*right.fTo);
62 }
63 return *this;
64 }
65
66 bool
operator ==(const TimeZoneTransition & that) const67 TimeZoneTransition::operator==(const TimeZoneTransition& that) const {
68 if (this == &that) {
69 return true;
70 }
71 if (typeid(*this) != typeid(that)) {
72 return false;
73 }
74 if (fTime != that.fTime) {
75 return false;
76 }
77 if ((fFrom == NULL && that.fFrom == NULL)
78 || (fFrom != NULL && that.fFrom != NULL && *fFrom == *(that.fFrom))) {
79 if ((fTo == NULL && that.fTo == NULL)
80 || (fTo != NULL && that.fTo != NULL && *fTo == *(that.fTo))) {
81 return true;
82 }
83 }
84 return false;
85 }
86
87 bool
operator !=(const TimeZoneTransition & that) const88 TimeZoneTransition::operator!=(const TimeZoneTransition& that) const {
89 return !operator==(that);
90 }
91
92 void
setTime(UDate time)93 TimeZoneTransition::setTime(UDate time) {
94 fTime = time;
95 }
96
97 void
setFrom(const TimeZoneRule & from)98 TimeZoneTransition::setFrom(const TimeZoneRule& from) {
99 if (fFrom != NULL) {
100 delete fFrom;
101 }
102 fFrom = from.clone();
103 }
104
105 void
adoptFrom(TimeZoneRule * from)106 TimeZoneTransition::adoptFrom(TimeZoneRule* from) {
107 if (fFrom != NULL) {
108 delete fFrom;
109 }
110 fFrom = from;
111 }
112
113 void
setTo(const TimeZoneRule & to)114 TimeZoneTransition::setTo(const TimeZoneRule& to) {
115 if (fTo != NULL) {
116 delete fTo;
117 }
118 fTo = to.clone();
119 }
120
121 void
adoptTo(TimeZoneRule * to)122 TimeZoneTransition::adoptTo(TimeZoneRule* to) {
123 if (fTo != NULL) {
124 delete fTo;
125 }
126 fTo = to;
127 }
128
129 UDate
getTime(void) const130 TimeZoneTransition::getTime(void) const {
131 return fTime;
132 }
133
134 const TimeZoneRule*
getTo(void) const135 TimeZoneTransition::getTo(void) const {
136 return fTo;
137 }
138
139 const TimeZoneRule*
getFrom(void) const140 TimeZoneTransition::getFrom(void) const {
141 return fFrom;
142 }
143
144 U_NAMESPACE_END
145
146 #endif
147
148 //eof
149