Home | History | Annotate | Download | only in i18n
      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 
     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     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 
     85 UBool
     86 TimeZoneTransition::operator!=(const TimeZoneTransition& that) const {
     87     return !operator==(that);
     88 }
     89 
     90 void
     91 TimeZoneTransition::setTime(UDate time) {
     92     fTime = time;
     93 }
     94 
     95 void
     96 TimeZoneTransition::setFrom(const TimeZoneRule& from) {
     97     if (fFrom != NULL) {
     98         delete fFrom;
     99     }
    100     fFrom = from.clone();
    101 }
    102 
    103 void
    104 TimeZoneTransition::adoptFrom(TimeZoneRule* from) {
    105     if (fFrom != NULL) {
    106         delete fFrom;
    107     }
    108     fFrom = from;
    109 }
    110 
    111 void
    112 TimeZoneTransition::setTo(const TimeZoneRule& to) {
    113     if (fTo != NULL) {
    114         delete fTo;
    115     }
    116     fTo = to.clone();
    117 }
    118 
    119 void
    120 TimeZoneTransition::adoptTo(TimeZoneRule* to) {
    121     if (fTo != NULL) {
    122         delete fTo;
    123     }
    124     fTo = to;
    125 }
    126 
    127 UDate
    128 TimeZoneTransition::getTime(void) const {
    129     return fTime;
    130 }
    131 
    132 const TimeZoneRule*
    133 TimeZoneTransition::getTo(void) const {
    134     return fTo;
    135 }
    136 
    137 const TimeZoneRule*
    138 TimeZoneTransition::getFrom(void) const {
    139     return fFrom;
    140 }
    141 
    142 U_NAMESPACE_END
    143 
    144 #endif
    145 
    146 //eof
    147