Skip to content

Commit

Permalink
Merge pull request moment#25 from hurrymaplelad/parse-local
Browse files Browse the repository at this point in the history
Alternative construct moment local to timezone
  • Loading branch information
timrwood committed Aug 19, 2013
2 parents 964d351 + bcbed77 commit 56f9844
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
5 changes: 4 additions & 1 deletion moment-timezone.js
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,10 @@
for (i = 0; i < len; i++) {
args[i] = arguments[i];
}
return moment.apply(null, args).tz(arguments[len]);
var m = moment.apply(null, args);
var preTzOffset = m.zone();
m.tz(arguments[len]);
return m.add('minutes', m.zone() - preTzOffset);
};

moment.tz.add = add;
Expand Down
13 changes: 13 additions & 0 deletions tests/parse.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
var moment = require("../index");

exports["parse"] = {
"parse" : function (t) {
t.equal(moment.tz("2013-01-01T00:00:00", "America/New_York").format(), "2013-01-01T00:00:00-05:00", "2013-01-01T00:00:00 in America/New_York should be 2013-01-01T00:00:00-05:00");
t.equal(moment.tz("2013-01-01T00:00:00", "America/Los_Angeles").format(), "2013-01-01T00:00:00-08:00", "2013-01-01T00:00:00 in America/Los_Angeles should be 2013-01-01T00:00:00-08:00");
t.equal(moment.tz("2013-01-01T00:00:00", "Europe/Paris").format(), "2013-01-01T00:00:00+01:00", "2013-01-01T00:00:00 in Europe/Paris should be 2013-01-01T00:00:00+01:00");
t.equal(moment.tz("2013-01-01T00:00:00", "Asia/Seoul").format(), "2013-01-01T00:00:00+09:00", "2013-01-01T00:00:00 in Asia/Seoul should be 2013-01-01T00:00:00+09:00");

t.equal(moment.tz([2013, 0, 1, 0, 0, 0], "America/New_York").format(), "2013-01-01T00:00:00-05:00", "Array constructor respects argument tzid");
t.done();
}
};

0 comments on commit 56f9844

Please sign in to comment.