Skip to content

Commit

Permalink
use the relative setTimezone() in the custom Date constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
TooTallNate committed Apr 4, 2012
1 parent 149e58a commit 92ce475
Showing 1 changed file with 3 additions and 15 deletions.
18 changes: 3 additions & 15 deletions index.js
Expand Up @@ -497,21 +497,9 @@ function Date (year, month, day, hour, minute, second, millisecond, timezone) {
d = new _Date(year, month, day, hour, minute, second, millisecond); break;
}
if (timezone) {
// If a 'timezone' was supplied, then the "trick" is to create another Date
// instance with the 'setTimezone()' function called on it. After that, we
// can proxy all the 'set*()' calls to the new Date instance. This is
// pretty much a "hack", but it allows us to re-use the native Date
// constructor logic above...
var realD = new _Date(0);
realD.setTimezone(timezone);
realD.setMilliseconds(d.getMilliseconds());
realD.setSeconds(d.getSeconds());
realD.setMinutes(d.getMinutes());
realD.setHours(d.getHours());
realD.setDate(d.getDate());
realD.setMonth(d.getMonth());
realD.setFullYear(d.getFullYear());
d = realD;
// set time given timezone relative to the currently set local time
// (changing the internal "time" milliseconds value)
d.setTimezone(timezone, true);
}
return d;
}
Expand Down

0 comments on commit 92ce475

Please sign in to comment.