Permalink
Browse files

Fix for JavaScript's broken Date API.

  • Loading branch information...
1 parent ce502a4 commit 80009768b63c2f40283115be86ace3fed8e1e0fc @mbostock mbostock committed Sep 4, 2012
Showing with 9 additions and 5 deletions.
  1. +2 −2 d3.v2.js
  2. +1 −1 d3.v2.min.js
  3. +2 −2 src/time/day.js
  4. +4 −0 test/time/day-test.js
View
@@ -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);
View
Oops, something went wrong.
View
@@ -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);
@@ -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": {

0 comments on commit 8000976

Please sign in to comment.