This commit is contained in:
Mike Bostock 2011-08-14 20:02:49 -07:00
Родитель 959b8f9d18
Коммит a8d023d6f4
3 изменённых файлов: 89 добавлений и 68 удалений

89
test/time/months-test.js Normal file
Просмотреть файл

@ -0,0 +1,89 @@
require("../env");
require("../../d3");
require("../../d3.time");
var vows = require("vows"),
assert = require("assert");
var suite = vows.describe("d3.time.months");
suite.addBatch({
"months": {
topic: function() {
return d3.time.months;
},
"returns months": function(range) {
assert.deepEqual(range(local(2010, 10, 31), local(2011, 2, 1)), [
local(2010, 11, 1),
local(2011, 0, 1),
local(2011, 1, 1)
]);
},
"has an inclusive lower bound": function(range) {
assert.deepEqual(range(local(2010, 10, 31), local(2011, 2, 1))[0], local(2010, 11, 1));
},
"has an exclusive upper bound": function(range) {
assert.deepEqual(range(local(2010, 10, 31), local(2011, 2, 1))[2], local(2011, 1, 1));
},
"observes start of daylight savings time": function(range) {
assert.deepEqual(range(local(2011, 0, 1), local(2011, 4, 1)), [
local(2011, 0, 1),
local(2011, 1, 1),
local(2011, 2, 1),
local(2011, 3, 1)
]);
},
"observes end of daylight savings time": function(range) {
assert.deepEqual(range(local(2011, 9, 1), local(2012, 1, 1)), [
local(2011, 9, 1),
local(2011, 10, 1),
local(2011, 11, 1),
local(2012, 0, 1)
]);
},
"UTC": {
topic: function(range) {
return range.utc;
},
"returns months": function(range) {
assert.deepEqual(range(utc(2010, 10, 31), utc(2011, 2, 1)), [
utc(2010, 11, 1),
utc(2011, 0, 1),
utc(2011, 1, 1)
]);
},
"has an inclusive lower bound": function(range) {
assert.deepEqual(range(utc(2010, 10, 31), utc(2011, 2, 1))[0], utc(2010, 11, 1));
},
"has an exclusive upper bound": function(range) {
assert.deepEqual(range(utc(2010, 10, 31), utc(2011, 2, 1))[2], utc(2011, 1, 1));
},
"does not observe the start of daylight savings time": function(range) {
assert.deepEqual(range(utc(2011, 0, 1), utc(2011, 4, 1)), [
utc(2011, 0, 1),
utc(2011, 1, 1),
utc(2011, 2, 1),
utc(2011, 3, 1)
]);
},
"does not observe the end of daylight savings time": function(range) {
assert.deepEqual(range(utc(2011, 9, 1), utc(2012, 1, 1)), [
utc(2011, 9, 1),
utc(2011, 10, 1),
utc(2011, 11, 1),
utc(2012, 0, 1)
]);
}
}
}
});
function local(year, month, day, hours, minutes, seconds) {
return new Date(year, month, day, hours || 0, minutes || 0, seconds || 0);
}
function utc(year, month, day, hours, minutes, seconds) {
return new Date(Date.UTC(year, month, day, hours || 0, minutes || 0, seconds || 0));
}
suite.export(module);

Просмотреть файл

@ -1,34 +0,0 @@
require("./../../lib/env-js/envjs/node");
require("./../../d3");
require("./../../d3.time");
function parse(string) { return new Date(string); }
function format(date) { return date.toString(); }
console.log("months(2010-11-21T06:00:00Z, 2011-02-12T10:00:00Z):");
d3.time.months(parse("2010-11-21T06:00:00Z"), parse("2011-02-12T10:00:00Z")).forEach(log);
console.log("");
console.log("months(2011-01-02T07:00:00Z, 2011-04-24T11:00:00Z):");
d3.time.months(parse("2011-01-02T07:00:00Z"), parse("2011-04-24T11:00:00Z")).forEach(log);
console.log("");
console.log("months(2011-09-25T07:00:00Z, 2011-12-17T11:00:00Z):");
d3.time.months(parse("2011-09-25T07:00:00Z"), parse("2011-12-17T11:00:00Z")).forEach(log);
console.log("");
console.log("months(2011-09-25T07:00:00Z, 2012-12-17T11:00:00Z, 3):");
d3.time.months(parse("2011-09-25T07:00:00Z"), parse("2012-12-17T11:00:00Z"), 3).forEach(log);
console.log("");
console.log("months.utc(2010-11-20T22:00:00Z, 2011-02-12T02:00:00Z):");
d3.time.months.utc(parse("2010-11-20T22:00:00Z"), parse("2011-02-12T02:00:00Z")).forEach(log);
console.log("");
console.log("months.utc(2010-11-20T22:00:00Z, 2012-02-12T02:00:00Z, 3):");
d3.time.months.utc(parse("2010-11-20T22:00:00Z"), parse("2012-02-12T02:00:00Z"), 3).forEach(log);
console.log("");
function log(date) {
console.log(" " + format(date));
}

Просмотреть файл

@ -1,34 +0,0 @@
months(2010-11-21T06:00:00Z, 2011-02-12T10:00:00Z):
Wed Dec 01 2010 00:00:00 GMT-0800 (PST)
Sat Jan 01 2011 00:00:00 GMT-0800 (PST)
Tue Feb 01 2011 00:00:00 GMT-0800 (PST)
months(2011-01-02T07:00:00Z, 2011-04-24T11:00:00Z):
Tue Feb 01 2011 00:00:00 GMT-0800 (PST)
Tue Mar 01 2011 00:00:00 GMT-0800 (PST)
Fri Apr 01 2011 00:00:00 GMT-0700 (PDT)
months(2011-09-25T07:00:00Z, 2011-12-17T11:00:00Z):
Sat Oct 01 2011 00:00:00 GMT-0700 (PDT)
Tue Nov 01 2011 00:00:00 GMT-0700 (PDT)
Thu Dec 01 2011 00:00:00 GMT-0800 (PST)
months(2011-09-25T07:00:00Z, 2012-12-17T11:00:00Z, 3):
Sat Oct 01 2011 00:00:00 GMT-0700 (PDT)
Sun Jan 01 2012 00:00:00 GMT-0800 (PST)
Sun Apr 01 2012 00:00:00 GMT-0700 (PDT)
Sun Jul 01 2012 00:00:00 GMT-0700 (PDT)
Mon Oct 01 2012 00:00:00 GMT-0700 (PDT)
months.utc(2010-11-20T22:00:00Z, 2011-02-12T02:00:00Z):
Tue Nov 30 2010 16:00:00 GMT-0800 (PST)
Fri Dec 31 2010 16:00:00 GMT-0800 (PST)
Mon Jan 31 2011 16:00:00 GMT-0800 (PST)
months.utc(2010-11-20T22:00:00Z, 2012-02-12T02:00:00Z, 3):
Fri Dec 31 2010 16:00:00 GMT-0800 (PST)
Thu Mar 31 2011 17:00:00 GMT-0700 (PDT)
Thu Jun 30 2011 17:00:00 GMT-0700 (PDT)
Fri Sep 30 2011 17:00:00 GMT-0700 (PDT)
Sat Dec 31 2011 16:00:00 GMT-0800 (PST)