Commit c693847f authored by Mike Bostock's avatar Mike Bostock
Browse files

Merge branch 'fix-parse-timezone' into 3.4.6

parents b0c2edfa 00d7183a
......@@ -2675,7 +2675,7 @@
return n ? (date.y = d3_time_expandYear(+n[0]), i + n[0].length) : -1;
}
function d3_time_parseZone(date, string, i) {
return /^[+-]\d{4}$/.test(string = string.substring(i, i + 5)) ? (date.Z = +string,
return /^[+-]\d{4}$/.test(string = string.substring(i, i + 5)) ? (date.Z = -string,
i + 5) : -1;
}
function d3_time_expandYear(d) {
......
This diff is collapsed.
......@@ -292,7 +292,7 @@ function d3_time_parseYear(date, string, i) {
function d3_time_parseZone(date, string, i) {
return /^[+-]\d{4}$/.test(string = string.substring(i, i + 5))
? (date.Z = +string, i + 5)
? (date.Z = -string, i + 5) // sign differs from getTimezoneOffset!
: -1;
}
......
......@@ -328,8 +328,9 @@ suite.addBatch({
"parses timezone offset": function(format) {
var p = format("%m/%d/%Y %Z").parse;
assert.deepEqual(p("01/02/1990 +0000"), local(1990, 0, 1, 16));
assert.deepEqual(p("01/02/1990 +0100"), local(1990, 0, 1, 17));
assert.deepEqual(p("01/02/1990 -0100"), local(1990, 0, 1, 15));
assert.deepEqual(p("01/02/1990 +0100"), local(1990, 0, 1, 15));
assert.deepEqual(p("01/02/1990 -0100"), local(1990, 0, 1, 17));
assert.deepEqual(p("01/02/1990 -0800"), local(1990, 0, 2, 0));
},
"ignores optional padding modifier, skipping zeroes and spaces": function(format) {
var p = format("%-m/%0d/%_Y").parse;
......
......@@ -215,8 +215,9 @@ suite.addBatch({
"parses timezone offset": function(format) {
var p = format("%m/%d/%Y %Z").parse;
assert.deepEqual(p("01/02/1990 +0000"), utc(1990, 0, 2));
assert.deepEqual(p("01/02/1990 +0100"), utc(1990, 0, 2, 1));
assert.deepEqual(p("01/02/1990 -0100"), utc(1990, 0, 1, 23));
assert.deepEqual(p("01/02/1990 +0100"), utc(1990, 0, 1, 23));
assert.deepEqual(p("01/02/1990 -0100"), utc(1990, 0, 2, 1));
assert.deepEqual(p("01/02/1990 -0800"), time.local(1990, 0, 2));
}
}
}
......
var offset = 0;
exports.local = function(year, month, day, hours, minutes, seconds, milliseconds) {
var date = new Date();
var date = new Date;
date.setFullYear(year, month, day);
date.setHours(hours || 0, offset + (minutes || 0), seconds || 0, milliseconds || 0);
return date;
};
exports.utc = function(year, month, day, hours, minutes, seconds, milliseconds) {
var date = new Date();
var date = new Date;
date.setUTCFullYear(year, month, day);
date.setUTCHours(hours || 0, minutes || 0, seconds || 0, milliseconds || 0);
return date;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment