diff --git a/test/time/day-test.js b/test/time/day-test.js index aee69678..74ba68d8 100644 --- a/test/time/day-test.js +++ b/test/time/day-test.js @@ -29,7 +29,7 @@ suite.addBatch({ assert.deepEqual(floor(utc(2011, 10, 6, 9)), local(2011, 10, 6)); assert.deepEqual(floor(utc(2011, 10, 6, 10)), local(2011, 10, 6)); }, - "utc": { + "UTC": { topic: function(floor) { return floor.utc; }, diff --git a/test/time/days-test.js b/test/time/days-test.js index f3154afd..e7b27809 100644 --- a/test/time/days-test.js +++ b/test/time/days-test.js @@ -41,7 +41,7 @@ suite.addBatch({ local(2011, 10, 8) ]); }, - "utc": { + "UTC": { topic: function(range) { return range.utc; }, diff --git a/test/time/minutes-test.js b/test/time/minutes-test.js new file mode 100644 index 00000000..bd2305c0 --- /dev/null +++ b/test/time/minutes-test.js @@ -0,0 +1,85 @@ +require("../env"); +require("../../d3"); +require("../../d3.time"); + +var vows = require("vows"), + assert = require("assert"); + +var suite = vows.describe("d3.time.minutes"); + +suite.addBatch({ + "minutes": { + topic: function() { + return d3.time.minutes; + }, + "returns minutes": function(range) { + assert.deepEqual(range(local(2010, 11, 31, 23, 59), local(2011, 0, 1, 0, 2)), [ + local(2010, 11, 31, 23, 59), + local(2011, 0, 1, 0, 0), + local(2011, 0, 1, 0, 1) + ]); + }, + "has an inclusive lower bound": function(range) { + assert.deepEqual(range(local(2010, 11, 31, 23, 59), local(2011, 0, 1, 0, 2))[0], local(2010, 11, 31, 23, 59)); + }, + "has an exclusive upper bound": function(range) { + assert.deepEqual(range(local(2010, 11, 31, 23, 59), local(2011, 0, 1, 0, 2))[2], local(2011, 0, 1, 0, 1)); + }, + "observes start of daylight savings time": function(range) { + assert.deepEqual(range(utc(2011, 2, 13, 9, 59), utc(2011, 2, 13, 10, 2)), [ + utc(2011, 2, 13, 9, 59), + utc(2011, 2, 13, 10, 0), + utc(2011, 2, 13, 10, 1) + ]); + }, + "observes end of daylight savings time": function(range) { + assert.deepEqual(range(utc(2011, 10, 6, 8, 59), utc(2011, 10, 6, 9, 2)), [ + utc(2011, 10, 6, 8, 59), + utc(2011, 10, 6, 9, 0), + utc(2011, 10, 6, 9, 1) + ]); + }, + "UTC": { + topic: function(range) { + return range.utc; + }, + "returns minutes": function(range) { + assert.deepEqual(range(utc(2010, 11, 31, 23, 59), utc(2011, 0, 1, 0, 2)), [ + utc(2010, 11, 31, 23, 59), + utc(2011, 0, 1, 0, 0), + utc(2011, 0, 1, 0, 1) + ]); + }, + "has an inclusive lower bound": function(range) { + assert.deepEqual(range(utc(2010, 11, 31, 23, 59), utc(2011, 0, 1, 0, 2))[0], utc(2010, 11, 31, 23, 59)); + }, + "has an exclusive upper bound": function(range) { + assert.deepEqual(range(utc(2010, 11, 31, 23, 59), utc(2011, 0, 1, 0, 2))[2], utc(2011, 0, 1, 0, 1)); + }, + "does not observe the start of daylight savings time": function(range) { + assert.deepEqual(range(utc(2011, 2, 13, 9, 59), utc(2011, 2, 13, 10, 2)), [ + utc(2011, 2, 13, 9, 59), + utc(2011, 2, 13, 10, 0), + utc(2011, 2, 13, 10, 1) + ]); + }, + "does not observe the end of daylight savings time": function(range) { + assert.deepEqual(range(utc(2011, 10, 6, 8, 59), utc(2011, 10, 6, 9, 2)), [ + utc(2011, 10, 6, 8, 59), + utc(2011, 10, 6, 9, 0), + utc(2011, 10, 6, 9, 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); diff --git a/test/time/test-minutes.js b/test/time/test-minutes.js deleted file mode 100644 index c16f0849..00000000 --- a/test/time/test-minutes.js +++ /dev/null @@ -1,30 +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("minutes(2011-01-01T07:58:00Z, 2011-01-01T08:02:00Z):"); -d3.time.minutes(parse("2011-01-01T07:58:00Z"), parse("2011-01-01T08:02:00Z")).forEach(log); -console.log(""); - -console.log("minutes(2011-03-13T09:58:00Z, 2011-03-13T10:02:00Z):"); -d3.time.minutes(parse("2011-03-13T09:58:00Z"), parse("2011-03-13T10:02:00Z")).forEach(log); -console.log(""); - -console.log("minutes(2011-03-13T09:58:00Z, 2011-03-13T11:02:00Z, 15):"); -d3.time.minutes(parse("2011-03-13T09:58:00Z"), parse("2011-03-13T11:02:00Z"), 15).forEach(log); -console.log(""); - -console.log("minutes.utc(2010-12-31T23:58:00Z, 2011-01-01T00:02:00Z):"); -d3.time.minutes.utc(parse("2010-12-31T23:58:00Z"), parse("2011-01-01T00:02:00Z")).forEach(log); -console.log(""); - -console.log("minutes.utc(2010-12-31T23:58:00Z, 2011-01-01T01:02:00Z, 15):"); -d3.time.minutes.utc(parse("2010-12-31T23:58:00Z"), parse("2011-01-01T01:02:00Z"), 15).forEach(log); -console.log(""); - -function log(date) { - console.log(" " + format(date)); -} diff --git a/test/time/test-minutes.out b/test/time/test-minutes.out deleted file mode 100644 index 97132f05..00000000 --- a/test/time/test-minutes.out +++ /dev/null @@ -1,32 +0,0 @@ -minutes(2011-01-01T07:58:00Z, 2011-01-01T08:02:00Z): - Fri Dec 31 2010 23:58:00 GMT-0800 (PST) - Fri Dec 31 2010 23:59:00 GMT-0800 (PST) - Sat Jan 01 2011 00:00:00 GMT-0800 (PST) - Sat Jan 01 2011 00:01:00 GMT-0800 (PST) - -minutes(2011-03-13T09:58:00Z, 2011-03-13T10:02:00Z): - Sun Mar 13 2011 01:58:00 GMT-0800 (PST) - Sun Mar 13 2011 01:59:00 GMT-0800 (PST) - Sun Mar 13 2011 03:00:00 GMT-0700 (PDT) - Sun Mar 13 2011 03:01:00 GMT-0700 (PDT) - -minutes(2011-03-13T09:58:00Z, 2011-03-13T11:02:00Z, 15): - Sun Mar 13 2011 03:00:00 GMT-0700 (PDT) - Sun Mar 13 2011 03:15:00 GMT-0700 (PDT) - Sun Mar 13 2011 03:30:00 GMT-0700 (PDT) - Sun Mar 13 2011 03:45:00 GMT-0700 (PDT) - Sun Mar 13 2011 04:00:00 GMT-0700 (PDT) - -minutes.utc(2010-12-31T23:58:00Z, 2011-01-01T00:02:00Z): - Fri Dec 31 2010 15:58:00 GMT-0800 (PST) - Fri Dec 31 2010 15:59:00 GMT-0800 (PST) - Fri Dec 31 2010 16:00:00 GMT-0800 (PST) - Fri Dec 31 2010 16:01:00 GMT-0800 (PST) - -minutes.utc(2010-12-31T23:58:00Z, 2011-01-01T01:02:00Z, 15): - Fri Dec 31 2010 16:00:00 GMT-0800 (PST) - Fri Dec 31 2010 16:15:00 GMT-0800 (PST) - Fri Dec 31 2010 16:30:00 GMT-0800 (PST) - Fri Dec 31 2010 16:45:00 GMT-0800 (PST) - Fri Dec 31 2010 17:00:00 GMT-0800 (PST) -