Home | History | Annotate | Download | only in i18n
      1 /*
      2 *******************************************************************************
      3 * Copyright (C) 2007, International Business Machines Corporation and         *
      4 * others. All Rights Reserved.                                                *
      5 *******************************************************************************
      6 */
      7 
      8 #include "unicode/utypes.h"
      9 
     10 #if !UCONFIG_NO_FORMATTING
     11 
     12 #include "unicode/tzrule.h"
     13 #include "unicode/tztrans.h"
     14 
     15 U_NAMESPACE_BEGIN
     16 
     17 UOBJECT_DEFINE_RTTI_IMPLEMENTATION(TimeZoneTransition)
     18 
     19 TimeZoneTransition::TimeZoneTransition(UDate time, const TimeZoneRule& from, const TimeZoneRule& to)
     20 : UObject(), fTime(time), fFrom(from.clone()), fTo(to.clone()) {
     21 }
     22 
     23 TimeZoneTransition::TimeZoneTransition()
     24 : UObject(), fTime(0), fFrom(NULL), fTo(NULL) {
     25 }
     26 
     27 TimeZoneTransition::TimeZoneTransition(const TimeZoneTransition& source)
     28 : UObject(), fTime(source.fTime), fFrom(NULL), fTo(NULL) {
     29       if (source.fFrom != NULL) {
     30           fFrom = source.fFrom->clone();
     31       }
     32 
     33       if (source.fTo != NULL) {
     34           fTo = source.fTo->clone();
     35       }
     36 }
     37 
     38 TimeZoneTransition::~TimeZoneTransition() {
     39     if (fFrom != NULL) {
     40         delete fFrom;
     41     }
     42     if (fTo != NULL) {
     43         delete fTo;
     44     }
     45 }
     46 
     47 TimeZoneTransition*
     48 TimeZoneTransition::clone(void) 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 UBool
     63 TimeZoneTransition::operator==(const TimeZoneTransition& that) const {
     64     if (this == &that) {
     65         return TRUE;
     66     }
     67     if (getDynamicClassID() != that.getDynamicClassID()) {
     68         return FALSE;
     69     }
     70     if (fTime != that.fTime) {
     71         return FALSE;
     72     }
     73     if (fFrom == NULL && that.fFrom == NULL
     74         || fFrom != NULL && that.fFrom != NULL && *fFrom == *(that.fFrom)) {
     75         if (fTo == NULL && that.fTo == NULL
     76             || fTo != NULL && that.fTo != NULL && *fTo == *(that.fTo)) {
     77             return TRUE;
     78         }
     79     }
     80     return FALSE;
     81 }
     82 
     83 UBool
     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     if (fFrom != NULL) {
     96         delete fFrom;
     97     }
     98     fFrom = from.clone();
     99 }
    100 
    101 void
    102 TimeZoneTransition::adoptFrom(TimeZoneRule* from) {
    103     if (fFrom != NULL) {
    104         delete fFrom;
    105     }
    106     fFrom = from;
    107 }
    108 
    109 void
    110 TimeZoneTransition::setTo(const TimeZoneRule& to) {
    111     if (fTo != NULL) {
    112         delete fTo;
    113     }
    114     fTo = to.clone();
    115 }
    116 
    117 void
    118 TimeZoneTransition::adoptTo(TimeZoneRule* to) {
    119     if (fTo != NULL) {
    120         delete fTo;
    121     }
    122     fTo = to;
    123 }
    124 
    125 UDate
    126 TimeZoneTransition::getTime(void) const {
    127     return fTime;
    128 }
    129 
    130 const TimeZoneRule*
    131 TimeZoneTransition::getTo(void) const {
    132     return fTo;
    133 }
    134 
    135 const TimeZoneRule*
    136 TimeZoneTransition::getFrom(void) const {
    137     return fFrom;
    138 }
    139 
    140 U_NAMESPACE_END
    141 
    142 #endif
    143 
    144 //eof
    145