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 17 U_NAMESPACE_BEGIN 18 19 UOBJECT_DEFINE_RTTI_IMPLEMENTATION(TimeZoneTransition) 20 21 TimeZoneTransition::TimeZoneTransition(UDate time, const TimeZoneRule& from, const TimeZoneRule& to) 22 : UObject(), fTime(time), fFrom(from.clone()), fTo(to.clone()) { 23 } 24 25 TimeZoneTransition::TimeZoneTransition() 26 : UObject(), fTime(0), fFrom(NULL), fTo(NULL) { 27 } 28 29 TimeZoneTransition::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 40 TimeZoneTransition::~TimeZoneTransition() { 41 if (fFrom != NULL) { 42 delete fFrom; 43 } 44 if (fTo != NULL) { 45 delete fTo; 46 } 47 } 48 49 TimeZoneTransition* 50 TimeZoneTransition::clone(void) const { 51 return new TimeZoneTransition(*this); 52 } 53 54 TimeZoneTransition& 55 TimeZoneTransition::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 64 UBool 65 TimeZoneTransition::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 86 UBool 87 TimeZoneTransition::operator!=(const TimeZoneTransition& that) const { 88 return !operator==(that); 89 } 90 91 void 92 TimeZoneTransition::setTime(UDate time) { 93 fTime = time; 94 } 95 96 void 97 TimeZoneTransition::setFrom(const TimeZoneRule& from) { 98 if (fFrom != NULL) { 99 delete fFrom; 100 } 101 fFrom = from.clone(); 102 } 103 104 void 105 TimeZoneTransition::adoptFrom(TimeZoneRule* from) { 106 if (fFrom != NULL) { 107 delete fFrom; 108 } 109 fFrom = from; 110 } 111 112 void 113 TimeZoneTransition::setTo(const TimeZoneRule& to) { 114 if (fTo != NULL) { 115 delete fTo; 116 } 117 fTo = to.clone(); 118 } 119 120 void 121 TimeZoneTransition::adoptTo(TimeZoneRule* to) { 122 if (fTo != NULL) { 123 delete fTo; 124 } 125 fTo = to; 126 } 127 128 UDate 129 TimeZoneTransition::getTime(void) const { 130 return fTime; 131 } 132 133 const TimeZoneRule* 134 TimeZoneTransition::getTo(void) const { 135 return fTo; 136 } 137 138 const TimeZoneRule* 139 TimeZoneTransition::getFrom(void) const { 140 return fFrom; 141 } 142 143 U_NAMESPACE_END 144 145 #endif 146 147 //eof 148