Skip to content

Commit

Permalink
Fix for the timezone issues (thanks to Tenzin NL on https://code.goog…
Browse files Browse the repository at this point in the history
  • Loading branch information
vitch committed Mar 24, 2013
1 parent 18bec3b commit e02cfc8
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions date.js
Expand Up @@ -317,8 +317,15 @@ Date.fullYearStart = '20';
* @cat Plugins/Methods/Date
*/
add("addDays", function(num) {
//this.setDate(this.getDate() + num);
this.setTime(this.getTime() + (num*86400000) );
var timezoneOffsetBefore = this.getTimezoneOffset(),
timezoneOffsetAfter;
this.setTime(this.getTime() + (num*86400000) );
timezoneOffsetAfter = this.getTimezoneOffset();

// If the timezone has changed between days then adjust the time to reflect this
if(timezoneOffsetAfter !== timezoneOffsetBefore){
this.setTime(this.getTime() + ((timezoneOffsetAfter-timezoneOffsetBefore) * 60 * 1000));
}
return this;
});

Expand Down Expand Up @@ -418,9 +425,9 @@ Date.fullYearStart = '20';
.split('D').join(this.getDayName(true))
.split('mmmm').join(this.getMonthName(false))
.split('mmm').join(this.getMonthName(true))
.split('mm').join(_zeroPad(this.getMonth()+1))
.split('hh').join(_zeroPad(this.getHours()))
.split('min').join(_zeroPad(this.getMinutes()))
.split('mm').join(_zeroPad(this.getMonth()+1))
.split('hh').join(_zeroPad(this.getHours()))
.split('min').join(_zeroPad(this.getMinutes()))
.split('ss').join(_zeroPad(this.getSeconds()));
});

Expand Down

0 comments on commit e02cfc8

Please sign in to comment.