blob: 3199b78ea833e92c23c487fc19cbc79a745b4b59 [file] [log] [blame]
Fredrik Roubert0596fae2017-04-18 21:34:02 +02001// © 2016 and later: Unicode, Inc. and others.
Fredrik Roubert64339d32016-10-21 19:43:16 +02002// License & terms of use: http://www.unicode.org/copyright.html
Jean-Baptiste Queruac04d0b2009-07-17 17:11:19 -07003/*
4*******************************************************************************
Craig Cornelius54dcd9b2013-02-15 14:03:14 -08005* Copyright (C) 2007-2012, International Business Machines Corporation and
claireho27f65472011-06-09 11:11:49 -07006* others. All Rights Reserved.
Jean-Baptiste Queruac04d0b2009-07-17 17:11:19 -07007*******************************************************************************
8*/
9
Craig Cornelius54dcd9b2013-02-15 14:03:14 -080010#include "utypeinfo.h" // for 'typeid' to work
claireho27f65472011-06-09 11:11:49 -070011
Jean-Baptiste Queruac04d0b2009-07-17 17:11:19 -070012#include "unicode/utypes.h"
13
14#if !UCONFIG_NO_FORMATTING
15
16#include "unicode/tzrule.h"
17#include "unicode/tztrans.h"
18
19U_NAMESPACE_BEGIN
20
21UOBJECT_DEFINE_RTTI_IMPLEMENTATION(TimeZoneTransition)
22
23TimeZoneTransition::TimeZoneTransition(UDate time, const TimeZoneRule& from, const TimeZoneRule& to)
24: UObject(), fTime(time), fFrom(from.clone()), fTo(to.clone()) {
25}
26
27TimeZoneTransition::TimeZoneTransition()
28: UObject(), fTime(0), fFrom(NULL), fTo(NULL) {
29}
30
31TimeZoneTransition::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
42TimeZoneTransition::~TimeZoneTransition() {
43 if (fFrom != NULL) {
44 delete fFrom;
45 }
46 if (fTo != NULL) {
47 delete fTo;
48 }
49}
50
51TimeZoneTransition*
52TimeZoneTransition::clone(void) const {
53 return new TimeZoneTransition(*this);
54}
55
56TimeZoneTransition&
57TimeZoneTransition::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
66UBool
67TimeZoneTransition::operator==(const TimeZoneTransition& that) const {
68 if (this == &that) {
69 return TRUE;
70 }
claireho27f65472011-06-09 11:11:49 -070071 if (typeid(*this) != typeid(that)) {
Jean-Baptiste Queruac04d0b2009-07-17 17:11:19 -070072 return FALSE;
73 }
74 if (fTime != that.fTime) {
75 return FALSE;
76 }
claireho27f65472011-06-09 11:11:49 -070077 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))) {
Jean-Baptiste Queruac04d0b2009-07-17 17:11:19 -070081 return TRUE;
82 }
83 }
84 return FALSE;
85}
86
87UBool
88TimeZoneTransition::operator!=(const TimeZoneTransition& that) const {
89 return !operator==(that);
90}
91
92void
93TimeZoneTransition::setTime(UDate time) {
94 fTime = time;
95}
96
97void
98TimeZoneTransition::setFrom(const TimeZoneRule& from) {
99 if (fFrom != NULL) {
100 delete fFrom;
101 }
102 fFrom = from.clone();
103}
104
105void
106TimeZoneTransition::adoptFrom(TimeZoneRule* from) {
107 if (fFrom != NULL) {
108 delete fFrom;
109 }
110 fFrom = from;
111}
112
113void
114TimeZoneTransition::setTo(const TimeZoneRule& to) {
115 if (fTo != NULL) {
116 delete fTo;
117 }
118 fTo = to.clone();
119}
120
121void
122TimeZoneTransition::adoptTo(TimeZoneRule* to) {
123 if (fTo != NULL) {
124 delete fTo;
125 }
126 fTo = to;
127}
128
129UDate
130TimeZoneTransition::getTime(void) const {
131 return fTime;
132}
133
134const TimeZoneRule*
135TimeZoneTransition::getTo(void) const {
136 return fTo;
137}
138
139const TimeZoneRule*
140TimeZoneTransition::getFrom(void) const {
141 return fFrom;
142}
143
144U_NAMESPACE_END
145
146#endif
147
148//eof