| OLD | NEW |
| 1 /* | 1 /* |
| 2 ******************************************************************************* | 2 ******************************************************************************* |
| 3 * Copyright (C) 2008-2012, Google, International Business Machines Corporation
and | 3 * Copyright (C) 2008-2014, Google, International Business Machines Corporation
and |
| 4 * others. All Rights Reserved. | 4 * others. All Rights Reserved. |
| 5 ******************************************************************************* | 5 ******************************************************************************* |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "utypeinfo.h" // for 'typeid' to work | |
| 9 | |
| 10 #include "unicode/tmunit.h" | 8 #include "unicode/tmunit.h" |
| 9 #include "uassert.h" |
| 11 | 10 |
| 12 #if !UCONFIG_NO_FORMATTING | 11 #if !UCONFIG_NO_FORMATTING |
| 13 | 12 |
| 14 U_NAMESPACE_BEGIN | 13 U_NAMESPACE_BEGIN |
| 15 | 14 |
| 16 UOBJECT_DEFINE_RTTI_IMPLEMENTATION(TimeUnit) | 15 UOBJECT_DEFINE_RTTI_IMPLEMENTATION(TimeUnit) |
| 17 | 16 |
| 18 | 17 |
| 19 /* | 18 /* |
| 20 * There are only 7 time units. | 19 * There are only 7 time units. |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 if (timeUnitField < 0 || timeUnitField >= UTIMEUNIT_FIELD_COUNT) { | 62 if (timeUnitField < 0 || timeUnitField >= UTIMEUNIT_FIELD_COUNT) { |
| 64 status = U_ILLEGAL_ARGUMENT_ERROR; | 63 status = U_ILLEGAL_ARGUMENT_ERROR; |
| 65 return NULL; | 64 return NULL; |
| 66 } | 65 } |
| 67 return new TimeUnit(timeUnitField); | 66 return new TimeUnit(timeUnitField); |
| 68 } | 67 } |
| 69 | 68 |
| 70 | 69 |
| 71 TimeUnit::TimeUnit(TimeUnit::UTimeUnitFields timeUnitField) { | 70 TimeUnit::TimeUnit(TimeUnit::UTimeUnitFields timeUnitField) { |
| 72 fTimeUnitField = timeUnitField; | 71 fTimeUnitField = timeUnitField; |
| 72 switch (fTimeUnitField) { |
| 73 case UTIMEUNIT_YEAR: |
| 74 initTime("year"); |
| 75 break; |
| 76 case UTIMEUNIT_MONTH: |
| 77 initTime("month"); |
| 78 break; |
| 79 case UTIMEUNIT_DAY: |
| 80 initTime("day"); |
| 81 break; |
| 82 case UTIMEUNIT_WEEK: |
| 83 initTime("week"); |
| 84 break; |
| 85 case UTIMEUNIT_HOUR: |
| 86 initTime("hour"); |
| 87 break; |
| 88 case UTIMEUNIT_MINUTE: |
| 89 initTime("minute"); |
| 90 break; |
| 91 case UTIMEUNIT_SECOND: |
| 92 initTime("second"); |
| 93 break; |
| 94 default: |
| 95 U_ASSERT(false); |
| 96 break; |
| 97 } |
| 73 } | 98 } |
| 74 | 99 |
| 75 | |
| 76 TimeUnit::TimeUnit(const TimeUnit& other) | 100 TimeUnit::TimeUnit(const TimeUnit& other) |
| 77 : MeasureUnit(other) { | 101 : MeasureUnit(other), fTimeUnitField(other.fTimeUnitField) { |
| 78 *this = other; | |
| 79 } | 102 } |
| 80 | 103 |
| 81 | |
| 82 UObject* | 104 UObject* |
| 83 TimeUnit::clone() const { | 105 TimeUnit::clone() const { |
| 84 return new TimeUnit(*this); | 106 return new TimeUnit(*this); |
| 85 } | 107 } |
| 86 | 108 |
| 87 | |
| 88 TimeUnit& | 109 TimeUnit& |
| 89 TimeUnit::operator=(const TimeUnit& other) { | 110 TimeUnit::operator=(const TimeUnit& other) { |
| 90 if (this == &other) { | 111 if (this == &other) { |
| 91 return *this; | 112 return *this; |
| 92 } | 113 } |
| 114 MeasureUnit::operator=(other); |
| 93 fTimeUnitField = other.fTimeUnitField; | 115 fTimeUnitField = other.fTimeUnitField; |
| 94 return *this; | 116 return *this; |
| 95 } | 117 } |
| 96 | 118 |
| 97 | |
| 98 UBool | |
| 99 TimeUnit::operator==(const UObject& other) const { | |
| 100 return (typeid(*this) == typeid(other) | |
| 101 && fTimeUnitField == ((TimeUnit*)&other)->fTimeUnitField); | |
| 102 } | |
| 103 | |
| 104 | |
| 105 TimeUnit::UTimeUnitFields | 119 TimeUnit::UTimeUnitFields |
| 106 TimeUnit::getTimeUnitField() const { | 120 TimeUnit::getTimeUnitField() const { |
| 107 return fTimeUnitField; | 121 return fTimeUnitField; |
| 108 } | 122 } |
| 109 | 123 |
| 110 | |
| 111 TimeUnit::~TimeUnit() { | 124 TimeUnit::~TimeUnit() { |
| 112 } | 125 } |
| 113 | 126 |
| 114 | 127 |
| 115 U_NAMESPACE_END | 128 U_NAMESPACE_END |
| 116 | 129 |
| 117 #endif | 130 #endif |
| OLD | NEW |