Commit bd09d37e authored by Mike Bostock's avatar Mike Bostock
Browse files

Refactor time tests for minimal load.

parent 68be0ac8
import "interval";
import "time";
import "year";
d3.time.day = d3_time_interval(function(date) {
var day = new d3_time(1970, 0);
day.setFullYear(date.getFullYear(), date.getMonth(), date.getDate());
......
import "format";
import "format-utc";
import "time";
var d3_time_formatIso = d3.time.format.utc("%Y-%m-%dT%H:%M:%S.%LZ");
......
import "../arrays/map";
import "../format/requote";
import "time";
import "day";
import "format-localized";
import "time";
import "week";
d3.time.format = function(template) {
var n = template.length;
......
import "../core/true";
import "../scale/linear";
import "format";
import "format-utc";
import "scale";
var d3_time_scaleUTCMethods = d3_time_scaleLocalMethods.map(function(m) {
......
......@@ -3,13 +3,14 @@ import "../core/rebind";
import "../core/true";
import "../scale/linear";
import "../scale/nice";
import "day";
import "format";
import "second";
import "minute";
import "hour";
import "day";
import "week";
import "minute";
import "month";
import "second";
import "time";
import "week";
import "year";
function d3_time_scale(linear, methods, format) {
......
......@@ -43,3 +43,7 @@ module.exports = function() {
return topic;
};
process.on("uncaughtException", function(e) {
console.trace(e.stack);
});
require("../env");
var vows = require("vows"),
load = require("../load"),
assert = require("../assert"),
time = require("./time"),
local = time.local,
......@@ -10,9 +9,7 @@ var suite = vows.describe("d3.time.day");
suite.addBatch({
"day": {
topic: function() {
return d3.time.day;
},
topic: load("time/day").expression("d3.time.day"),
"defaults to floor": function(interval) {
assert.strictEqual(interval, interval.floor);
},
......
require("../env");
var vows = require("vows"),
assert = require("../assert"),
time = require("./time"),
local = time.local,
utc = time.utc;
load = require("../load"),
assert = require("../assert");
var suite = vows.describe("d3.time.dayOfYear");
suite.addBatch({
"dayOfYear": {
topic: function() {
return d3.time.dayOfYear;
},
topic: load("time/day").expression("d3.time.dayOfYear"),
"no floating-point rounding error": function(dayOfYear) {
assert.equal(dayOfYear(new Date(2011, 4, 9)), 128);
}
......
require("../env");
var vows = require("vows"),
load = require("../load"),
assert = require("../assert"),
time = require("./time"),
local = time.local,
......@@ -10,9 +9,7 @@ var suite = vows.describe("d3.time.days");
suite.addBatch({
"days": {
topic: function() {
return d3.time.days;
},
topic: load("time/day").expression("d3.time.days"),
"returns midnights": function(range) {
assert.deepEqual(range(local(2010, 11, 31, 12), local(2011, 0, 3, 12)), [
local(2011, 0, 1),
......
var vows = require("vows"),
load = require("../load"),
assert = require("../assert"),
time = require("./time"),
utc = time.utc;
var suite = vows.describe("d3.time.format");
suite.addBatch({
"format.iso": {
topic: load("time/format-iso").expression("d3.time.format.iso"),
"toString is %Y-%m-%dT%H:%M:%S.%LZ": function(format) {
assert.equal(format + "", "%Y-%m-%dT%H:%M:%S.%LZ");
},
"formats as ISO 8601": function(format) {
assert.equal(format(utc(1990, 0, 1, 0, 0, 0)), "1990-01-01T00:00:00.000Z");
assert.equal(format(utc(2011, 11, 31, 23, 59, 59)), "2011-12-31T23:59:59.000Z");
},
"parse": {
"parses as ISO 8601": function(format) {
var p = format.parse;
assert.deepEqual(p("1990-01-01T00:00:00.000Z"), utc(1990, 0, 1, 0, 0, 0));
assert.deepEqual(p("2011-12-31T23:59:59.000Z"), utc(2011, 11, 31, 23, 59, 59));
assert.isNull(p("1990-01-01T00:00:00.000X"));
}
}
}
});
suite.export(module);
require("../env");
var vows = require("vows"),
load = require("../load"),
assert = require("../assert"),
time = require("./time"),
local = time.local,
utc = time.utc;
local = time.local;
var suite = vows.describe("d3.time.format");
suite.addBatch({
"format": {
topic: function() {
return d3.time.format;
},
topic: load("time/format").expression("d3.time.format"),
"formats abbreviated weekday": function(format) {
var f = format("%a");
assert.equal(f(local(1990, 0, 1)), "Mon");
......@@ -162,321 +158,84 @@ suite.addBatch({
var f = format("%%");
assert.equal(f(local(1990, 0, 1)), "%");
},
"UTC": {
topic: function(format) {
return format.utc;
},
"formats abbreviated weekday": function(format) {
var f = format("%a");
assert.equal(f(utc(1990, 0, 1)), "Mon");
assert.equal(f(utc(1990, 0, 2)), "Tue");
assert.equal(f(utc(1990, 0, 3)), "Wed");
assert.equal(f(utc(1990, 0, 4)), "Thu");
assert.equal(f(utc(1990, 0, 5)), "Fri");
assert.equal(f(utc(1990, 0, 6)), "Sat");
assert.equal(f(utc(1990, 0, 7)), "Sun");
},
"formats weekday": function(format) {
var f = format("%A");
assert.equal(f(utc(1990, 0, 1)), "Monday");
assert.equal(f(utc(1990, 0, 2)), "Tuesday");
assert.equal(f(utc(1990, 0, 3)), "Wednesday");
assert.equal(f(utc(1990, 0, 4)), "Thursday");
assert.equal(f(utc(1990, 0, 5)), "Friday");
assert.equal(f(utc(1990, 0, 6)), "Saturday");
assert.equal(f(utc(1990, 0, 7)), "Sunday");
},
"formats abbreviated month": function(format) {
var f = format("%b");
assert.equal(f(utc(1990, 0, 1)), "Jan");
assert.equal(f(utc(1990, 1, 1)), "Feb");
assert.equal(f(utc(1990, 2, 1)), "Mar");
assert.equal(f(utc(1990, 3, 1)), "Apr");
assert.equal(f(utc(1990, 4, 1)), "May");
assert.equal(f(utc(1990, 5, 1)), "Jun");
assert.equal(f(utc(1990, 6, 1)), "Jul");
assert.equal(f(utc(1990, 7, 1)), "Aug");
assert.equal(f(utc(1990, 8, 1)), "Sep");
assert.equal(f(utc(1990, 9, 1)), "Oct");
assert.equal(f(utc(1990, 10, 1)), "Nov");
assert.equal(f(utc(1990, 11, 1)), "Dec");
},
"formats locale date and time": function(format) {
var f = format("%c");
assert.equal(f(utc(1990, 0, 1)), "Mon Jan 1 00:00:00 1990");
},
"formats zero-padded date": function(format) {
var f = format("%d");
assert.equal(f(utc(1990, 0, 1)), "01");
},
"formats space-padded date": function(format) {
var f = format("%e");
assert.equal(f(utc(1990, 0, 1)), " 1");
},
"formats zero-padded hour (24)": function(format) {
var f = format("%H");
assert.equal(f(utc(1990, 0, 1, 0)), "00");
assert.equal(f(utc(1990, 0, 1, 13)), "13");
},
"formats zero-padded hour (12)": function(format) {
var f = format("%I");
assert.equal(f(utc(1990, 0, 1, 0)), "12");
assert.equal(f(utc(1990, 0, 1, 13)), "01");
},
"formats zero-padded day of year": function(format) {
var f = format("%j");
assert.equal(f(utc(1990, 0, 1)), "001");
assert.equal(f(utc(1990, 5, 1)), "152");
assert.equal(f(utc(2010, 2, 13, 23)), "072");
assert.equal(f(utc(2010, 2, 14, 00)), "073"); // DST begins
assert.equal(f(utc(2010, 2, 15, 00)), "074");
assert.equal(f(utc(2010, 10, 6, 23)), "310");
assert.equal(f(utc(2010, 10, 7, 00)), "311"); // DST ends
assert.equal(f(utc(2010, 10, 8, 00)), "312");
},
"formats zero-padded month": function(format) {
var f = format("%m");
assert.equal(f(utc(1990, 0, 1)), "01");
assert.equal(f(utc(1990, 9, 1)), "10");
},
"formats zero-padded minute": function(format) {
var f = format("%M");
assert.equal(f(utc(1990, 0, 1, 0, 0)), "00");
assert.equal(f(utc(1990, 0, 1, 0, 32)), "32");
},
"formats AM or PM": function(format) {
var f = format("%p");
assert.equal(f(utc(1990, 0, 1, 0)), "AM");
assert.equal(f(utc(1990, 0, 1, 13)), "PM");
},
"formats zero-padded second": function(format) {
var f = format("%S");
assert.equal(f(utc(1990, 0, 1, 0, 0, 0)), "00");
assert.equal(f(utc(1990, 0, 1, 0, 0, 32)), "32");
},
"formats zero-padded millisecond": function(format) {
var f = format("%L");
assert.equal(f(utc(1990, 0, 1, 0, 0, 0, 0)), "000");
assert.equal(f(utc(1990, 0, 1, 0, 0, 0, 432)), "432");
},
"formats zero-padded week number": function(format) {
var f = format("%U");
assert.equal(f(utc(1990, 0, 1)), "00");
assert.equal(f(utc(1990, 5, 1)), "21");
assert.equal(f(utc(2010, 2, 13, 23)), "10");
assert.equal(f(utc(2010, 2, 14, 00)), "11"); // DST begins
assert.equal(f(utc(2010, 2, 15, 00)), "11");
assert.equal(f(utc(2010, 10, 6, 23)), "44");
assert.equal(f(utc(2010, 10, 7, 00)), "45"); // DST ends
assert.equal(f(utc(2010, 10, 8, 00)), "45");
},
"formats locale date": function(format) {
var f = format("%x");
assert.equal(f(utc(1990, 0, 1)), "01/01/1990");
assert.equal(f(utc(2010, 5, 1)), "06/01/2010");
},
"formats locale time": function(format) {
var f = format("%X");
assert.equal(f(utc(1990, 0, 1)), "00:00:00");
assert.equal(f(utc(1990, 0, 1, 13, 34, 59)), "13:34:59");
},
"formats zero-padded two-digit year": function(format) {
var f = format("%y");
assert.equal(f(utc(1990, 0, 1)), "90");
assert.equal(f(utc(2002, 0, 1)), "02");
},
"formats zero-padded four-digit year": function(format) {
var f = format("%Y");
assert.equal(f(utc(123, 0, 1)), "0123");
assert.equal(f(utc(1990, 0, 1)), "1990");
assert.equal(f(utc(2002, 0, 1)), "2002");
assert.equal(f(utc(10002, 0, 1)), "0002");
},
"formats time zone": function(format) {
var f = format("%Z");
assert.equal(f(utc(1990, 0, 1)), "+0000");
},
"formats literal percent sign": function(format) {
var f = format("%%");
assert.equal(f(utc(1990, 0, 1)), "%");
},
},
"ISO": {
topic: function(format) {
return format.iso;
},
"toString is %Y-%m-%dT%H:%M:%S.%LZ": function(format) {
assert.equal(format + "", "%Y-%m-%dT%H:%M:%S.%LZ");
},
"formats as ISO 8601": function(format) {
assert.equal(format(utc(1990, 0, 1, 0, 0, 0)), "1990-01-01T00:00:00.000Z");
assert.equal(format(utc(2011, 11, 31, 23, 59, 59)), "2011-12-31T23:59:59.000Z");
}
}
},
"parse": {
topic: function() {
return d3.time.format;
},
"parses abbreviated weekday and numeric date": function(format) {
var p = format("%a %m/%d/%Y").parse;
assert.deepEqual(p("Sun 01/01/1990"), local(1990, 0, 1));
assert.deepEqual(p("Wed 02/03/1991"), local(1991, 1, 3));
assert.isNull(p("XXX 03/10/2010"));
},
"parses weekday and numeric date": function(format) {
var p = format("%A %m/%d/%Y").parse;
assert.deepEqual(p("Sunday 01/01/1990"), local(1990, 0, 1));
assert.deepEqual(p("Wednesday 02/03/1991"), local(1991, 1, 3));
assert.isNull(p("Caturday 03/10/2010"));
},
"parses numeric date": function(format) {
var p = format("%m/%d/%y").parse;
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/1990"), local(1990, 0, 1));
assert.deepEqual(p("02/03/1991"), local(1991, 1, 3));
assert.deepEqual(p("03/10/2010"), local(2010, 2, 10));
},
"parses abbreviated month, date and year": function(format) {
var p = format("%b %d, %Y").parse;
assert.deepEqual(p("jan 01, 1990"), local(1990, 0, 1));
assert.deepEqual(p("feb 2, 2010"), local(2010, 1, 2));
assert.isNull(p("jan. 1, 1990"));
},
"parses month, date and year": function(format) {
var p = format("%B %d, %Y").parse;
assert.deepEqual(p("january 01, 1990"), local(1990, 0, 1));
assert.deepEqual(p("February 2, 2010"), local(2010, 1, 2));
assert.isNull(p("jan 1, 1990"));
},
"parses locale date and time": function(format) {
var p = format("%c").parse;
assert.deepEqual(p("Mon Jan 1 00:00:00 1990"), local(1990, 0, 1));
assert.deepEqual(p("Sun Jan 1 00:00:00 1990"), local(1990, 0, 1));
assert.deepEqual(p("Mon Jan 01 00:00:00 1990"), local(1990, 0, 1));
assert.deepEqual(p("Mon Jan 1 00:00:00 1990"), local(1990, 0, 1));
assert.deepEqual(p("Mon Jan 1 0:0:0 1990"), local(1990, 0, 1));
},
"parses twenty-four hour, minute and second": function(format) {
var p = format("%H:%M:%S").parse;
assert.deepEqual(p("00:00:00"), local(1900, 0, 1, 0, 0, 0));
assert.deepEqual(p("11:59:59"), local(1900, 0, 1, 11, 59, 59));
assert.deepEqual(p("12:00:00"), local(1900, 0, 1, 12, 0, 0));
assert.deepEqual(p("12:00:01"), local(1900, 0, 1, 12, 0, 1));
assert.deepEqual(p("23:59:59"), local(1900, 0, 1, 23, 59, 59));
},
"parses locale time": function(format) {
var p = format("%X").parse;
assert.deepEqual(p("00:00:00"), local(1900, 0, 1, 0, 0, 0));
assert.deepEqual(p("11:59:59"), local(1900, 0, 1, 11, 59, 59));
assert.deepEqual(p("12:00:00"), local(1900, 0, 1, 12, 0, 0));
assert.deepEqual(p("12:00:01"), local(1900, 0, 1, 12, 0, 1));
assert.deepEqual(p("23:59:59"), local(1900, 0, 1, 23, 59, 59));
},
"parses twelve hour, minute and second": function(format) {
var p = format("%I:%M:%S %p").parse;
assert.deepEqual(p("12:00:00 am"), local(1900, 0, 1, 0, 0, 0));
assert.deepEqual(p("11:59:59 AM"), local(1900, 0, 1, 11, 59, 59));
assert.deepEqual(p("12:00:00 pm"), local(1900, 0, 1, 12, 0, 0));
assert.deepEqual(p("12:00:01 pm"), local(1900, 0, 1, 12, 0, 1));
assert.deepEqual(p("11:59:59 PM"), local(1900, 0, 1, 23, 59, 59));
},
"doesn't crash when given weird strings": function(format) {
try {
Object.prototype.foo = 10;
var p = format("%b %d, %Y").parse;
assert.isNull(p("foo 1, 1990"));
} finally {
delete Object.prototype.foo;
}
},
"UTC": {
topic: function(format) {
return format.utc;
},
"parse": {
"parses abbreviated weekday and numeric date": function(format) {
var p = format("%a %m/%d/%Y").parse;
assert.deepEqual(p("Sun 01/01/1990"), utc(1990, 0, 1));
assert.deepEqual(p("Wed 02/03/1991"), utc(1991, 1, 3));
assert.deepEqual(p("Sun 01/01/1990"), local(1990, 0, 1));
assert.deepEqual(p("Wed 02/03/1991"), local(1991, 1, 3));
assert.isNull(p("XXX 03/10/2010"));
},
"parses weekday and numeric date": function(format) {
var p = format("%A %m/%d/%Y").parse;
assert.deepEqual(p("Sunday 01/01/1990"), utc(1990, 0, 1));
assert.deepEqual(p("Wednesday 02/03/1991"), utc(1991, 1, 3));
assert.deepEqual(p("Sunday 01/01/1990"), local(1990, 0, 1));
assert.deepEqual(p("Wednesday 02/03/1991"), local(1991, 1, 3));
assert.isNull(p("Caturday 03/10/2010"));
},
"parses numeric date": function(format) {
var p = format("%m/%d/%y").parse;
assert.deepEqual(p("01/01/90"), utc(1990, 0, 1));
assert.deepEqual(p("02/03/91"), utc(1991, 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/1990"), utc(1990, 0, 1));
assert.deepEqual(p("02/03/1991"), utc(1991, 1, 3));
assert.deepEqual(p("03/10/2010"), utc(2010, 2, 10));
assert.deepEqual(p("01/01/1990"), local(1990, 0, 1));
assert.deepEqual(p("02/03/1991"), local(1991, 1, 3));
assert.deepEqual(p("03/10/2010"), local(2010, 2, 10));
},
"parses abbreviated month, date and year": function(format) {
var p = format("%b %d, %Y").parse;
assert.deepEqual(p("jan 01, 1990"), utc(1990, 0, 1));
assert.deepEqual(p("feb 2, 2010"), utc(2010, 1, 2));
assert.deepEqual(p("jan 01, 1990"), local(1990, 0, 1));
assert.deepEqual(p("feb 2, 2010"), local(2010, 1, 2));
assert.isNull(p("jan. 1, 1990"));
},
"parses month, date and year": function(format) {
var p = format("%B %d, %Y").parse;
assert.deepEqual(p("january 01, 1990"), utc(1990, 0, 1));
assert.deepEqual(p("February 2, 2010"), utc(2010, 1, 2));
assert.deepEqual(p("january 01, 1990"), local(1990, 0, 1));
assert.deepEqual(p("February 2, 2010"), local(2010, 1, 2));
assert.isNull(p("jan 1, 1990"));
},
"parses locale date and time": function(format) {
var p = format("%c").parse;
assert.deepEqual(p("Mon Jan 1 00:00:00 1990"), utc(1990, 0, 1));
assert.deepEqual(p("Sun Jan 1 00:00:00 1990"), utc(1990, 0, 1));
assert.deepEqual(p("Mon Jan 01 00:00:00 1990"), utc(1990, 0, 1));
assert.deepEqual(p("Mon Jan 1 00:00:00 1990"), utc(1990, 0, 1));
assert.deepEqual(p("Mon Jan 1 0:0:0 1990"), utc(1990, 0, 1));
assert.deepEqual(p("Mon Jan 1 00:00:00 1990"), local(1990, 0, 1));
assert.deepEqual(p("Sun Jan 1 00:00:00 1990"), local(1990, 0, 1));
assert.deepEqual(p("Mon Jan 01 00:00:00 1990"), local(1990, 0, 1));
assert.deepEqual(p("Mon Jan 1 00:00:00 1990"), local(1990, 0, 1));
assert.deepEqual(p("Mon Jan 1 0:0:0 1990"), local(1990, 0, 1));
},
"parses twenty-four hour, minute and second": function(format) {
var p = format("%H:%M:%S").parse;
assert.deepEqual(p("00:00:00"), utc(1900, 0, 1, 0, 0, 0));
assert.deepEqual(p("11:59:59"), utc(1900, 0, 1, 11, 59, 59));
assert.deepEqual(p("12:00:00"), utc(1900, 0, 1, 12, 0, 0));
assert.deepEqual(p("12:00:01"), utc(1900, 0, 1, 12, 0, 1));
assert.deepEqual(p("23:59:59"), utc(1900, 0, 1, 23, 59, 59));
assert.deepEqual(p("00:00:00"), local(1900, 0, 1, 0, 0, 0));
assert.deepEqual(p("11:59:59"), local(1900, 0, 1, 11, 59, 59));
assert.deepEqual(p("12:00:00"), local(1900, 0, 1, 12, 0, 0));
assert.deepEqual(p("12:00:01"), local(1900, 0, 1, 12, 0, 1));
assert.deepEqual(p("23:59:59"), local(1900, 0, 1, 23, 59, 59));
},
"parses locale time": function(format) {
var p = format("%X").parse;
assert.deepEqual(p("00:00:00"), utc(1900, 0, 1, 0, 0, 0));
assert.deepEqual(p("11:59:59"), utc(1900, 0, 1, 11, 59, 59));
assert.deepEqual(p("12:00:00"), utc(1900, 0, 1, 12, 0, 0));
assert.deepEqual(p("12:00:01"), utc(1900, 0, 1, 12, 0, 1));
assert.deepEqual(p("23:59:59"), utc(1900, 0, 1, 23, 59, 59));
assert.deepEqual(p("00:00:00"), local(1900, 0, 1, 0, 0, 0));
assert.deepEqual(p("11:59:59"), local(1900, 0, 1, 11, 59, 59));
assert.deepEqual(p("12:00:00"), local(1900, 0, 1, 12, 0, 0));
assert.deepEqual(p("12:00:01"), local(1900, 0, 1, 12, 0, 1));
assert.deepEqual(p("23:59:59"), local(1900, 0, 1, 23, 59, 59));
},
"parses twelve hour, minute and second": function(format) {
var p = format("%I:%M:%S %p").parse;
assert.deepEqual(p("12:00:00 am"), utc(1900, 0, 1, 0, 0, 0));
assert.deepEqual(p("11:59:59 AM"), utc(1900, 0, 1, 11, 59, 59));
assert.deepEqual(p("12:00:00 pm"), utc(1900, 0, 1, 12, 0, 0));
assert.deepEqual(p("12:00:01 pm"), utc(1900, 0, 1, 12, 0, 1));
assert.deepEqual(p("11:59:59 PM"), utc(1900, 0, 1, 23, 59, 59));
}
},
"ISO": {
topic: function(format) {
return format.iso;
},
"parses as ISO 8601": function(format) {
var p = format.parse;
assert.deepEqual(p("1990-01-01T00:00:00.000Z"), utc(1990, 0, 1, 0, 0, 0));
assert.deepEqual(p("2011-12-31T23:59:59.000Z"), utc(2011, 11, 31, 23, 59, 59));
assert.isNull(p("1990-01-01T00:00:00.000X"));
assert.deepEqual(p("12:00:00 am"), local(1900, 0, 1, 0, 0, 0));
assert.deepEqual(p("11:59:59 AM"), local(1900, 0, 1, 11, 59, 59));
assert.deepEqual(p("12:00:00 pm"), local(1900, 0, 1, 12, 0, 0));
assert.deepEqual(p("12:00:01 pm"), local(1900, 0, 1, 12, 0, 1));
assert.deepEqual(p("11:59:59 PM"), local(1900, 0, 1, 23, 59, 59));
},
"doesn't crash when given weird strings": function(format) {
try {
Object.prototype.foo = 10;
var p = format("%b %d, %Y").parse;
assert.isNull(p("foo 1, 1990"));
} finally {
delete Object.prototype.foo;
}
}
}
}
......
var vows = require("vows"),
load = require("../load"),
assert = require("../assert"),
time = require("./time"),
utc = time.utc;
var suite = vows.describe("d3.time.format");
suite.addBatch({
"format.utc": {