Skip to content

Commit

Permalink
Fix for JavaScript's broken Date API.
Browse files Browse the repository at this point in the history
  • Loading branch information
mbostock committed Sep 4, 2012
1 parent ce502a4 commit 8000976
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
4 changes: 2 additions & 2 deletions d3.v2.js
Original file line number Diff line number Diff line change
Expand Up @@ -6918,8 +6918,8 @@
d3.time.hours = d3.time.hour.range;
d3.time.hours.utc = d3.time.hour.utc.range;
d3.time.day = d3_time_interval(function(date) {
var day = new d3_time(0, date.getMonth(), date.getDate());
day.setFullYear(date.getFullYear());
var day = new d3_time(1970, 0);
day.setFullYear(date.getFullYear(), date.getMonth(), date.getDate());
return day;
}, function(date, offset) {
date.setDate(date.getDate() + offset);
Expand Down
2 changes: 1 addition & 1 deletion d3.v2.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/time/day.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
d3.time.day = d3_time_interval(function(date) {
var day = new d3_time(0, date.getMonth(), date.getDate());
day.setFullYear(date.getFullYear());
var day = new d3_time(1970, 0);
day.setFullYear(date.getFullYear(), date.getMonth(), date.getDate());
return day;
}, function(date, offset) {
date.setDate(date.getDate() + offset);
Expand Down
4 changes: 4 additions & 0 deletions test/time/day-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ suite.addBatch({
assert.deepEqual(ceil(utc(2011, 10, 06, 08)), local(2011, 10, 07));
assert.deepEqual(ceil(utc(2011, 10, 06, 09)), local(2011, 10, 07));
assert.deepEqual(ceil(utc(2011, 10, 06, 10)), local(2011, 10, 07));
},
"handles midnight for leap years": function(ceil) {
assert.deepEqual(ceil(utc(2012, 02, 01, 00)), local(2012, 02, 01));
assert.deepEqual(ceil(utc(2012, 02, 01, 00)), local(2012, 02, 01));
}
},
"offset": {
Expand Down

0 comments on commit 8000976

Please sign in to comment.