[Time] TimeDuration fix
authorPawel Kaczmarek <p.kaczmarek3@samsung.com>
Tue, 30 Dec 2014 10:30:22 +0000 (11:30 +0100)
committerRafal Galka <r.galka@samsung.com>
Tue, 30 Dec 2014 14:04:38 +0000 (23:04 +0900)
[Verification]
var duration = new tizen.TimeDuration(30, "MINS");
console.log('length: ' + duration.length);
console.log('unit: ' + duration.unit);
Should print:
length: 30
unit: MINS

Change-Id: I744a34ed0561a87f37e6c21ffc55817f36692605
Signed-off-by: Pawel Kaczmarek <p.kaczmarek3@samsung.com>
src/time/time_api.js

index ceb5350..99e00c4 100644 (file)
@@ -77,25 +77,33 @@ tizen.TimeDuration = function(length, unit) {
   if (!this || this.constructor != tizen.TimeDuration)
     throw new TypeError;
 
-  var length_ = Math.floor(length) || 0;
-  var unit_ = unit || 'MSECS';
-
-  Object.defineProperty(this, 'length', {
-    get: function() {
-      return length_; },
-    set: function(NewValue) {
-      if (NewValue != null)
-        length_ = Math.floor(NewValue); }});
-
-  Object.defineProperty(this, 'unit', {
-    get: function() {
-      return unit_; },
-    set: function(NewValue) {
-      if (TimeDurationUnit.indexOf(NewValue) >= 0)
-        unit_ = NewValue; }});
-
-  if (TimeDurationUnit.indexOf(this.unit) == -1)
-    this.unit = 'MSECS';
+  var length_ = length !== null ? Math.floor(length) : 0;
+  var unit_ = TimeDurationUnit.indexOf(unit) >= 0 ? unit : 'MSECS';
+
+  Object.defineProperties(this, {
+    length: {
+      get: function () {
+        return length_;
+      },
+      set: function (v) {
+        if (v !== null) {
+          length_ = Math.floor(v);
+        }
+      },
+      enumerable: true
+    },
+    unit: {
+      get: function () {
+        return unit_;
+      },
+      set: function (v) {
+        if (TimeDurationUnit.indexOf(v) >= 0) {
+          unit_ = v;
+        }
+      },
+      enumerable: true
+    }
+  });
 };
 
 function getMultiplier(unit) {