]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/i18n/tmunit.cpp
ICU-64232.0.1.tar.gz
[apple/icu.git] / icuSources / i18n / tmunit.cpp
index fb31e252091e10c254942aa9dfb6c295a521fdcf..f169c30d35f57cd7dd51b73f0e7d07771242e024 100644 (file)
@@ -1,13 +1,14 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
 /*
  *******************************************************************************
- * Copyright (C) 2008-2010, Google, International Business Machines Corporation and
+ * Copyright (C) 2008-2014, Google, International Business Machines Corporation and
  * others. All Rights Reserved.
  *******************************************************************************
  */
 
-#include <typeinfo>  // for 'typeid' to work
-
 #include "unicode/tmunit.h"
+#include "uassert.h"
 
 #if !UCONFIG_NO_FORMATTING
 
@@ -70,44 +71,57 @@ TimeUnit::createInstance(TimeUnit::UTimeUnitFields timeUnitField,
 
 TimeUnit::TimeUnit(TimeUnit::UTimeUnitFields timeUnitField) {
     fTimeUnitField = timeUnitField;
+    switch (fTimeUnitField) {
+    case UTIMEUNIT_YEAR:
+        initTime("year");
+        break;
+    case UTIMEUNIT_MONTH:
+        initTime("month");
+        break;
+    case UTIMEUNIT_DAY:
+        initTime("day");
+        break;
+    case UTIMEUNIT_WEEK:
+        initTime("week");
+        break;
+    case UTIMEUNIT_HOUR:
+        initTime("hour");
+        break;
+    case UTIMEUNIT_MINUTE:
+        initTime("minute");
+        break;
+    case UTIMEUNIT_SECOND:
+        initTime("second");
+        break;
+    default:
+        UPRV_UNREACHABLE;
+    }
 }
 
-
 TimeUnit::TimeUnit(const TimeUnit& other) 
-:   MeasureUnit(other) {
-    *this = other;
+:   MeasureUnit(other), fTimeUnitField(other.fTimeUnitField) {
 }
 
-
 UObject* 
 TimeUnit::clone() const {
     return new TimeUnit(*this);
 }
 
-
 TimeUnit&
 TimeUnit::operator=(const TimeUnit& other) {
     if (this == &other) {
         return *this;
     }
+    MeasureUnit::operator=(other);
     fTimeUnitField = other.fTimeUnitField;
     return *this;
 }
 
-
-UBool 
-TimeUnit::operator==(const UObject& other) const {
-    return (typeid(*this) == typeid(other)
-            && fTimeUnitField == ((TimeUnit*)&other)->fTimeUnitField);
-}
-
-
 TimeUnit::UTimeUnitFields
 TimeUnit::getTimeUnitField() const {
     return fTimeUnitField;
 }
 
-
 TimeUnit::~TimeUnit() {
 }