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