Fixed a bug in TZDate constructor 47/70747/1
authorPiotr Kosko <p.kosko@samsung.com>
Fri, 20 May 2016 09:42:25 +0000 (11:42 +0200)
committerPiotr Kosko <p.kosko@samsung.com>
Fri, 20 May 2016 09:56:57 +0000 (11:56 +0200)
[Bug] With following conditions:
  1. Device local timezone uses DST.
  2. current date has +1 hour according to DST.
  3. Creating new tizen date with local timezone, on which date there would not be +1 hour DST
  created date would have incorrect time.

  Example:
  1. using timezone 'Europe/Warsaw'
  2. current date 20.05.2016 (+2 hour from UTC = 1 (for timezone) + 1 (for DST))
  3. line below returned 13, which was incorrect:
     var d = new tizen.TZDate(new Date(2016,01,20,13)); d.getHours();

[Verification] TCT passrate time - 100%.
  Verified in console - above example returned '13' which was correct value.

Change-Id: Iffff14814d2c5011561158cc7bd1db215659953a
Signed-off-by: Piotr Kosko <p.kosko@samsung.com>
src/time/time_api.js

index a29071d6b15a3bc463b68ff12256bd76535c6b63..ea6962b67f59cb0edbaf31f6d65f68b1f9544a7b 100644 (file)
@@ -66,8 +66,8 @@ function _getTimezoneOffset(timestamp, tzName) {
   return res;
 }
 
-function _getLocalTimezoneOffset() {
-  return -1 * (new Date().getTimezoneOffset()) * 60 * 1000; // cast to milliseconds
+function _getLocalTimezoneOffset(utcTimestamp) {
+  return -1 * (new Date(utcTimestamp).getTimezoneOffset()) * 60 * 1000; // cast to milliseconds
 }
 
 function _constructTZDate(obj, privateTZDate) {
@@ -82,7 +82,7 @@ function _constructTZDate(obj, privateTZDate) {
     tzName = tizen.time.getLocalTimezone();
 
     if (T.isNullOrUndefined(offset)) {
-      offset = _getLocalTimezoneOffset();
+      offset = _getLocalTimezoneOffset(utcTimestamp);
     }
     break;
 
@@ -145,8 +145,8 @@ tizen.TZDate = function(p1, p2, day, hours, minutes, seconds, milliseconds, time
       date = new Date(p1, p2, day, hours, minutes, seconds, milliseconds);
     }
 
-    var offset = _getLocalTimezoneOffset();
     var utcTimestamp = date.getTime();
+    var offset = _getLocalTimezoneOffset(utcTimestamp);
     var tzName = _LOCAL_ID;
 
     if (!T.isNullOrUndefined(timezone)) {