Permalink
Browse files

Merge pull request #57 from divide0/master

Fix Issue #36. timezone-js doesn't handle static dst offset rules
  • Loading branch information...
2 parents 582127e + a0d0d8b commit 915b3f3603cb66e8a3cfa0a96665b966105287a7 @longlho longlho committed Feb 8, 2013
Showing with 13 additions and 0 deletions.
  1. +6 −0 spec/date.spec.js
  2. +7 −0 src/date.js
View
@@ -315,4 +315,10 @@ describe('timezoneJS.Date', function () {
date.setHours(0, 1, 2, 3);
expect(date.getMilliseconds()).toEqual(3);
});
+
+ it("Handles static dst offsets in Zones like '1:00' instead of DST rule references.", function(){
+ var date = new timezoneJS.Date(Date.UTC(2012, 2, 1, 0, 0, 0, 0), "Pacific/Apia");
+ expect(date.getTimezoneOffset()).toBe(-840);
+ expect(date.toString("yyyy-MM-dd HH:mm:ss Z")).toBe("2012-03-01 14:00:00 WSDT");
+ });
});
View
@@ -540,6 +540,13 @@
var date = typeof dt === 'number' ? new Date(dt) : dt;
var ruleset = zone[1];
var basicOffset = zone[0];
+
+ // If the zone has a DST rule like '1:00', create a rule and return it
+ // instead of looking it up in the parsed rules
+ var staticDstMatch = ruleset.match(/^([0-9]):([0-9][0-9])$/);
+ if (staticDstMatch) {
+ return [-1000000,'max','-','Jan',1,parseTimeString('0:00'),parseInt(staticDstMatch[1]) * 60 + parseInt(staticDstMatch[2]), '-'];
+ }
//Convert a date to UTC. Depending on the 'type' parameter, the date
// parameter may be:

0 comments on commit 915b3f3

Please sign in to comment.