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