Browse files

Merge remote-tracking branch 'remotes/jasondavies/date-2d'

Conflicts:
	d3.v2.min.js
	src/time/format.js
  • Loading branch information...
2 parents 73c7f98 + 42b9253 commit 14131c8c8c00c8e03317a39e56948f9e4bbd1759 @GerHobbelt committed Jul 15, 2012
Showing with 23 additions and 18 deletions.
  1. +4 −3 d3.latest.js
  2. +4 −3 d3.v2.js
  3. +4 −0 d3.v2.min.js
  4. +3 −4 src/time/format.js
  5. +8 −8 test/time/format-test.js
View
7 d3.latest.js
@@ -8974,11 +8974,12 @@ function d3_time_parseFullYear(date, string, i) {
function d3_time_parseYear(date, string, i) {
d3_time_numberRe.lastIndex = 0;
var n = d3_time_numberRe.exec(string.substring(i, i + 2));
- return n ? (date.y = d3_time_century() + +n[0], i += n[0].length) : -1;
+ return n ? (date.y = d3_time_yearExpand(+n[0]), i += n[0].length) : -1;
}
-function d3_time_century() {
- return ~~(new Date().getFullYear() / 1000) * 1000;
+function d3_time_yearExpand(d) {
+ // convert to 4-digit year according to POSIX/ISO rules (strptime) ~ http://docs.python.org/py3k/library/time.html
+ return d + (((d >= 69) && (d < 100)) ? 1900 : 2000);
}
function d3_time_parseMonthNumber(date, string, i) {
View
7 d3.v2.js
@@ -8974,11 +8974,12 @@ function d3_time_parseFullYear(date, string, i) {
function d3_time_parseYear(date, string, i) {
d3_time_numberRe.lastIndex = 0;
var n = d3_time_numberRe.exec(string.substring(i, i + 2));
- return n ? (date.y = d3_time_century() + +n[0], i += n[0].length) : -1;
+ return n ? (date.y = d3_time_yearExpand(+n[0]), i += n[0].length) : -1;
}
-function d3_time_century() {
- return ~~(new Date().getFullYear() / 1000) * 1000;
+function d3_time_yearExpand(d) {
+ // convert to 4-digit year according to POSIX/ISO rules (strptime) ~ http://docs.python.org/py3k/library/time.html
+ return d + (((d >= 69) && (d < 100)) ? 1900 : 2000);
}
function d3_time_parseMonthNumber(date, string, i) {
View
4 d3.v2.min.js
4 additions, 0 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
7 src/time/format.js
@@ -232,13 +232,12 @@ function d3_time_parseFullYear(date, string, i) {
function d3_time_parseYear(date, string, i) {
d3_time_numberRe.lastIndex = 0;
var n = d3_time_numberRe.exec(string.substring(i, i + 2));
- return n ? (date.y = d3_time_century(+n[0]) + +n[0], i += n[0].length) : -1;
+ return n ? (date.y = d3_time_yearExpand(+n[0]), i += n[0].length) : -1;
}
-function d3_time_century(two_digit_year) {
- if (!arguments.length) return 2000; // old code: return ~~(new Date().getFullYear() / 1000) * 1000; always produced '2000' anyway, unless you'd had your clock adjusted to the years beyond 1000 A.D. or 3000 A.D.
+function d3_time_yearExpand(d) {
// convert to 4-digit year according to POSIX/ISO rules (strptime) ~ http://docs.python.org/py3k/library/time.html
- return ((two_digit_year >= 69) && (two_digit_year < 100)) ? 1900 : 2000;
+ return d + (((d >= 69) && (d < 100)) ? 1900 : 2000);
}
function d3_time_parseMonthNumber(date, string, i) {
View
16 test/time/format-test.js
@@ -334,14 +334,14 @@ suite.addBatch({
},
"parses numeric date": function(format) {
var p = format("%m/%d/%y").parse;
- assert.deepEqual(p("01/01/90"), local(2090, 0, 1));
- assert.deepEqual(p("02/03/91"), local(2091, 1, 3));
+ assert.deepEqual(p("01/01/90"), local(1990, 0, 1));
+ assert.deepEqual(p("02/03/91"), local(1991, 1, 3));
assert.isNull(p("03/10/2010"));
},
"parses locale date": function(format) {
var p = format("%x").parse;
- assert.deepEqual(p("01/01/90"), local(2090, 0, 1));
- assert.deepEqual(p("02/03/91"), local(2091, 1, 3));
+ assert.deepEqual(p("01/01/90"), local(1990, 0, 1));
+ assert.deepEqual(p("02/03/91"), local(1991, 1, 3));
assert.isNull(p("03/10/2010"));
},
"parses abbreviated month, date and year": function(format) {
@@ -415,14 +415,14 @@ suite.addBatch({
},
"parses numeric date": function(format) {
var p = format("%m/%d/%y").parse;
- assert.deepEqual(p("01/01/90"), utc(2090, 0, 1));
- assert.deepEqual(p("02/03/91"), utc(2091, 1, 3));
+ assert.deepEqual(p("01/01/90"), utc(1990, 0, 1));
+ assert.deepEqual(p("02/03/91"), utc(1991, 1, 3));
assert.isNull(p("03/10/2010"));
},
"parses locale date": function(format) {
var p = format("%x").parse;
- assert.deepEqual(p("01/01/90"), utc(2090, 0, 1));
- assert.deepEqual(p("02/03/91"), utc(2091, 1, 3));
+ assert.deepEqual(p("01/01/90"), utc(1990, 0, 1));
+ assert.deepEqual(p("02/03/91"), utc(1991, 1, 3));
assert.isNull(p("03/10/2010"));
},
"parses abbreviated month, date and year": function(format) {

0 comments on commit 14131c8

Please sign in to comment.