}
}
+ function timezoneMinutesFromString(string) {
+ var tzchunk = (parseTokenTimezone.exec(string) || [])[0],
+ parts = (tzchunk + '').match(parseTimezoneChunker) || ['-', 0, 0],
+ minutes = +(parts[1] * 60) + ~~parts[2];
+
+ return parts[0] === '+' ? -minutes : minutes;
+ }
+
// function to convert string input to date
function addTimeToArrayFromToken(token, input, config) {
var a, b,
case 'Z' : // fall through to ZZ
case 'ZZ' :
config._useUTC = true;
- a = (input + '').match(parseTimezoneChunker);
- if (a && a[1]) {
- config._tzh = ~~a[1];
- }
- if (a && a[2]) {
- config._tzm = ~~a[2];
- }
- // reverse offsets
- if (a && a[0] === '+') {
- config._tzh = -config._tzh;
- config._tzm = -config._tzm;
- }
+ config._tzm = timezoneMinutesFromString(input);
break;
}
}
// add the offsets to the time to be parsed so that we can have a clean array for checking isValid
- input[3] += config._tzh || 0;
- input[4] += config._tzm || 0;
+ input[3] += ~~((config._tzm || 0) / 60);
+ input[4] += ~~((config._tzm || 0) % 60);
date = new Date(0);
zone : function (input) {
var offset = this._offset || 0;
if (input != null) {
+ if (typeof input === "string") {
+ input = timezoneMinutesFromString(input);
+ }
this._offset = input;
this._isUTC = true;
if (offset !== input) {
test.done();
},
+ "set zone with string" : function (test) {
+ var zone = moment();
+
+ zone.zone("+00:00");
+ test.equal(zone.zone(), 0, "set the zone with a timezone string");
+
+ zone.zone("2013-03-07T07:00:00-08:00");
+ test.equal(zone.zone(), 480, "set the zone with a string that does not begin with the timezone");
+
+ zone.zone("2013-03-07T07:00:00+0100");
+ test.equal(zone.zone(), -60, "set the zone with a string that uses the +0000 syntax");
+
+ test.done();
+ },
+
"change hours when changing the zone" : function (test) {
var zone = moment.utc([2000, 0, 1, 6]);