saheb11 / datejs

Automatically exported from code.google.com/p/datejs
Other
0 stars 0 forks source link

Adding time fails during DST switches #119

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?

var d = new Date('Sun Mar 27 2011 01:59:00 GMT+0100 (CET)');
d.addMinutes(1);

What is the expected output? What do you see instead?

The expected result is 'Sun Mar 27 2011 03:00:00 GMT+0200 (CET)' but the actual 
result is 'Sun Mar 27 2011 01:00:00 GMT+0200 (CET)'

The problem is that setMilliseconds() (which is the final operation on any time 
adding/substraction in datejs) does not work across DST boundaries. The 
solution is simple though:

--- a/horde/js/date/date.js
+++ b/horde/js/date/date.js
@@ -222,7 +222,7 @@
      * @return {Date}    this
      */
     $P.addMilliseconds = function (value) {
-        this.setMilliseconds(this.getMilliseconds() + value * 1);
+        this.setTime(this.getTime() + value * 1);
         return this;
     };

Original issue reported on code.google.com by jan.schn...@gmail.com on 27 Mar 2011 at 1:53

GoogleCodeExporter commented 8 years ago
I get the same problem, but you have to be in CET to test this example you set. 
I'm in WET now so it would give me Sun Mar 27 2011 00:00:00 GMT+0000 (WET) 
after adding that minute (Sun Mar 31 2013 02:00:00 GMT+0100 (WEST) before 
adding).

If you need to test out this, you just need to set it to your timezone DST 
problem:
http://www.timeanddate.com/worldclock/timezone.html?n=133

Original comment by fgue...@sugarcrm.com on 2 Mar 2013 at 2:18

GoogleCodeExporter commented 8 years ago
fixed in the current build on my fork: https://github.com/abritinthebay/datejs/

Original comment by darkcr...@gmail.com on 17 Sep 2013 at 11:04