From 4fbf1947e96b63fe721e5c8b40af8c69cab0f486 Mon Sep 17 00:00:00 2001
From: Pawel Kaczmarek
Date: Tue, 30 Dec 2014 11:30:22 +0100
Subject: [PATCH] [Time] TimeDuration fix
[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
---
src/time/time_api.js | 46 ++++++++++++++++++++++++++------------------
1 file changed, 27 insertions(+), 19 deletions(-)
diff --git a/src/time/time_api.js b/src/time/time_api.js
index ceb53500..99e00c40 100644
--- a/src/time/time_api.js
+++ b/src/time/time_api.js
@@ -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) {
--
2.34.1