1/*
2*******************************************************************************
3* Copyright (C) 2007-2010, International Business Machines Corporation and
4* others. All Rights Reserved.
5*******************************************************************************
6*/
7
8#include <typeinfo>  // 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
73    if (fTime != that.fTime) {
74        return FALSE;
75    }
76    if ((fFrom == NULL && that.fFrom == NULL)
77        || (fFrom != NULL && that.fFrom != NULL && *fFrom == *(that.fFrom))) {
78        if ((fTo == NULL && that.fTo == NULL)
79            || (fTo != NULL && that.fTo != NULL && *fTo == *(that.fTo))) {
80            return TRUE;
81        }
82    }
83    return FALSE;
84}
85
86UBool
87TimeZoneTransition::operator!=(const TimeZoneTransition& that) const {
88    return !operator==(that);
89}
90
91void
92TimeZoneTransition::setTime(UDate time) {
93    fTime = time;
94}
95
96void
97TimeZoneTransition::setFrom(const TimeZoneRule& from) {
98    if (fFrom != NULL) {
99        delete fFrom;
100    }
101    fFrom = from.clone();
102}
103
104void
105TimeZoneTransition::adoptFrom(TimeZoneRule* from) {
106    if (fFrom != NULL) {
107        delete fFrom;
108    }
109    fFrom = from;
110}
111
112void
113TimeZoneTransition::setTo(const TimeZoneRule& to) {
114    if (fTo != NULL) {
115        delete fTo;
116    }
117    fTo = to.clone();
118}
119
120void
121TimeZoneTransition::adoptTo(TimeZoneRule* to) {
122    if (fTo != NULL) {
123        delete fTo;
124    }
125    fTo = to;
126}
127
128UDate
129TimeZoneTransition::getTime(void) const {
130    return fTime;
131}
132
133const TimeZoneRule*
134TimeZoneTransition::getTo(void) const {
135    return fTo;
136}
137
138const TimeZoneRule*
139TimeZoneTransition::getFrom(void) const {
140    return fFrom;
141}
142
143U_NAMESPACE_END
144
145#endif
146
147//eof
148