/src/icu/icu4c/source/i18n/tztrans.cpp
Line | Count | Source |
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 | | |
21 | | UOBJECT_DEFINE_RTTI_IMPLEMENTATION(TimeZoneTransition) |
22 | | |
23 | | TimeZoneTransition::TimeZoneTransition(UDate time, const TimeZoneRule& from, const TimeZoneRule& to) |
24 | 0 | : UObject(), fTime(time), fFrom(from.clone()), fTo(to.clone()) { |
25 | 0 | } |
26 | | |
27 | | TimeZoneTransition::TimeZoneTransition() |
28 | 0 | : UObject(), fTime(0), fFrom(nullptr), fTo(nullptr) { |
29 | 0 | } |
30 | | |
31 | | TimeZoneTransition::TimeZoneTransition(const TimeZoneTransition& source) |
32 | 0 | : UObject(), fTime(source.fTime), fFrom(nullptr), fTo(nullptr) { |
33 | 0 | if (source.fFrom != nullptr) { |
34 | 0 | fFrom = source.fFrom->clone(); |
35 | 0 | } |
36 | |
|
37 | 0 | if (source.fTo != nullptr) { |
38 | 0 | fTo = source.fTo->clone(); |
39 | 0 | } |
40 | 0 | } |
41 | | |
42 | 0 | TimeZoneTransition::~TimeZoneTransition() { |
43 | 0 | delete fFrom; |
44 | 0 | delete fTo; |
45 | 0 | } |
46 | | |
47 | | TimeZoneTransition* |
48 | 0 | TimeZoneTransition::clone() const { |
49 | 0 | return new TimeZoneTransition(*this); |
50 | 0 | } |
51 | | |
52 | | TimeZoneTransition& |
53 | 0 | TimeZoneTransition::operator=(const TimeZoneTransition& right) { |
54 | 0 | if (this != &right) { |
55 | 0 | fTime = right.fTime; |
56 | 0 | setFrom(*right.fFrom); |
57 | 0 | setTo(*right.fTo); |
58 | 0 | } |
59 | 0 | return *this; |
60 | 0 | } |
61 | | |
62 | | bool |
63 | 0 | TimeZoneTransition::operator==(const TimeZoneTransition& that) const { |
64 | 0 | if (this == &that) { |
65 | 0 | return true; |
66 | 0 | } |
67 | 0 | if (typeid(*this) != typeid(that)) { |
68 | 0 | return false; |
69 | 0 | } |
70 | 0 | if (fTime != that.fTime) { |
71 | 0 | return false; |
72 | 0 | } |
73 | 0 | if ((fFrom == nullptr && that.fFrom == nullptr) |
74 | 0 | || (fFrom != nullptr && that.fFrom != nullptr && *fFrom == *(that.fFrom))) { |
75 | 0 | if ((fTo == nullptr && that.fTo == nullptr) |
76 | 0 | || (fTo != nullptr && that.fTo != nullptr && *fTo == *(that.fTo))) { |
77 | 0 | return true; |
78 | 0 | } |
79 | 0 | } |
80 | 0 | return false; |
81 | 0 | } |
82 | | |
83 | | bool |
84 | 0 | TimeZoneTransition::operator!=(const TimeZoneTransition& that) const { |
85 | 0 | return !operator==(that); |
86 | 0 | } |
87 | | |
88 | | void |
89 | 0 | TimeZoneTransition::setTime(UDate time) { |
90 | 0 | fTime = time; |
91 | 0 | } |
92 | | |
93 | | void |
94 | 0 | TimeZoneTransition::setFrom(const TimeZoneRule& from) { |
95 | 0 | delete fFrom; |
96 | 0 | fFrom = from.clone(); |
97 | 0 | } |
98 | | |
99 | | void |
100 | 0 | TimeZoneTransition::adoptFrom(TimeZoneRule* from) { |
101 | 0 | delete fFrom; |
102 | 0 | fFrom = from; |
103 | 0 | } |
104 | | |
105 | | void |
106 | 0 | TimeZoneTransition::setTo(const TimeZoneRule& to) { |
107 | 0 | delete fTo; |
108 | 0 | fTo = to.clone(); |
109 | 0 | } |
110 | | |
111 | | void |
112 | 0 | TimeZoneTransition::adoptTo(TimeZoneRule* to) { |
113 | 0 | delete fTo; |
114 | 0 | fTo = to; |
115 | 0 | } |
116 | | |
117 | | UDate |
118 | 0 | TimeZoneTransition::getTime() const { |
119 | 0 | return fTime; |
120 | 0 | } |
121 | | |
122 | | const TimeZoneRule* |
123 | 0 | TimeZoneTransition::getTo() const { |
124 | 0 | return fTo; |
125 | 0 | } |
126 | | |
127 | | const TimeZoneRule* |
128 | 0 | TimeZoneTransition::getFrom() const { |
129 | 0 | return fFrom; |
130 | 0 | } |
131 | | |
132 | | U_NAMESPACE_END |
133 | | |
134 | | #endif |
135 | | |
136 | | //eof |