Fixes #576: leap year bug in d3.time.format.

We need to set the date fields from year down, rather than in arbitrary order.
This commit is contained in:
Mike Bostock 2012-02-29 11:27:30 -08:00
Родитель e46b1615a1
Коммит 41371adc98
21 изменённых файлов: 179 добавлений и 234 удалений

69
d3.v2.js поставляемый
Просмотреть файл

@ -8640,16 +8640,18 @@ d3_time_utc.prototype = {
getTime: function() { return this._.getTime(); },
getTimezoneOffset: function() { return 0; },
valueOf: function() { return this._.valueOf(); },
setDate: function(x) { this._.setUTCDate(x); },
setDay: function(x) { this._.setUTCDay(x); },
setFullYear: function(x) { this._.setUTCFullYear(x); },
setHours: function(x) { this._.setUTCHours(x); },
setMilliseconds: function(x) { this._.setUTCMilliseconds(x); },
setMinutes: function(x) { this._.setUTCMinutes(x); },
setMonth: function(x) { this._.setUTCMonth(x); },
setSeconds: function(x) { this._.setUTCSeconds(x); },
setTime: function(x) { this._.setTime(x); }
setDate: function() { d3_time_prototype.setUTCDate.apply(this._, arguments); },
setDay: function() { d3_time_prototype.setUTCDay.apply(this._, arguments); },
setFullYear: function() { d3_time_prototype.setUTCFullYear.apply(this._, arguments); },
setHours: function() { d3_time_prototype.setUTCHours.apply(this._, arguments); },
setMilliseconds: function() { d3_time_prototype.setUTCMilliseconds.apply(this._, arguments); },
setMinutes: function() { d3_time_prototype.setUTCMinutes.apply(this._, arguments); },
setMonth: function() { d3_time_prototype.setUTCMonth.apply(this._, arguments); },
setSeconds: function() { d3_time_prototype.setUTCSeconds.apply(this._, arguments); },
setTime: function() { d3_time_prototype.setTime.apply(this._, arguments); }
};
var d3_time_prototype = Date.prototype;
d3.time.format = function(template) {
var n = template.length;
@ -8673,15 +8675,16 @@ d3.time.format = function(template) {
}
format.parse = function(string) {
var date = new d3_time(1900, 0, 1),
i = d3_time_parse(date, template, string, 0);
var d = {y: 1900, m: 0, d: 1, H: 0, M: 0, S: 0, L: 0},
i = d3_time_parse(d, template, string, 0);
if (i != string.length) return null;
if (date.hour12) {
var hours = date.getHours() % 12;
date.setHours(date.hour12pm ? hours + 12 : hours);
}
delete date.hour12;
delete date.hour12pm;
// The am-pm flag is 0 for AM, and 1 for PM.
if ("p" in d) d.H = d.H % 12 + d.p * 12;
var date = new d3_time();
date.setFullYear(d.y, d.m, d.d);
date.setHours(d.H, d.M, d.S, d.L);
return date;
};
@ -8752,7 +8755,7 @@ var d3_time_parsers = {
d: d3_time_parseDay,
e: d3_time_parseDay,
H: d3_time_parseHour24,
I: d3_time_parseHour12,
I: d3_time_parseHour24,
// j: function(d, s, i) { /*TODO day of year [001,366] */ return i; },
L: d3_time_parseMilliseconds,
m: d3_time_parseMonthNumber,
@ -8789,7 +8792,7 @@ var d3_time_weekdayAbbrevRe = /^(?:sun|mon|tue|wed|thu|fri|sat)/i,
function d3_time_parseMonthAbbrev(date, string, i) {
var n = d3_time_monthAbbrevLookup.get(string.substring(i, i += 3).toLowerCase());
return n == null ? -1 : (date.setMonth(n), i);
return n == null ? -1 : (date.m = n, i);
}
var d3_time_monthAbbrevLookup = d3.map({
@ -8810,7 +8813,7 @@ var d3_time_monthAbbrevLookup = d3.map({
function d3_time_parseMonth(date, string, i) {
d3_time_monthRe.lastIndex = 0;
var n = d3_time_monthRe.exec(string.substring(i, i + 12));
return n ? (date.setMonth(d3_time_monthLookup.get(n[0].toLowerCase())), i += n[0].length) : -1;
return n ? (date.m = d3_time_monthLookup.get(n[0].toLowerCase()), i += n[0].length) : -1;
}
var d3_time_monthRe = /^(?:January|February|March|April|May|June|July|August|September|October|November|December)/ig;
@ -8860,13 +8863,13 @@ function d3_time_parseLocaleTime(date, string, i) {
function d3_time_parseFullYear(date, string, i) {
d3_time_numberRe.lastIndex = 0;
var n = d3_time_numberRe.exec(string.substring(i, i + 4));
return n ? (date.setFullYear(n[0]), i += n[0].length) : -1;
return n ? (date.y = +n[0], i += n[0].length) : -1;
}
function d3_time_parseYear(date, string, i) {
d3_time_numberRe.lastIndex = 0;
var n = d3_time_numberRe.exec(string.substring(i, i + 2));
return n ? (date.setFullYear(d3_time_century() + +n[0]), i += n[0].length) : -1;
return n ? (date.y = d3_time_century() + +n[0], i += n[0].length) : -1;
}
function d3_time_century() {
@ -8876,44 +8879,38 @@ function d3_time_century() {
function d3_time_parseMonthNumber(date, string, i) {
d3_time_numberRe.lastIndex = 0;
var n = d3_time_numberRe.exec(string.substring(i, i + 2));
return n ? (date.setMonth(n[0] - 1), i += n[0].length) : -1;
return n ? (date.m = n[0] - 1, i += n[0].length) : -1;
}
function d3_time_parseDay(date, string, i) {
d3_time_numberRe.lastIndex = 0;
var n = d3_time_numberRe.exec(string.substring(i, i + 2));
return n ? (date.setDate(+n[0]), i += n[0].length) : -1;
return n ? (date.d = +n[0], i += n[0].length) : -1;
}
// Note: we don't validate that the hour is in the range [0,23].
// Note: we don't validate that the hour is in the range [0,23] or [1,12].
function d3_time_parseHour24(date, string, i) {
d3_time_numberRe.lastIndex = 0;
var n = d3_time_numberRe.exec(string.substring(i, i + 2));
return n ? (date.setHours(+n[0]), i += n[0].length) : -1;
}
// Note: we don't validate that the hour is in the range [1,12].
function d3_time_parseHour12(date, string, i) {
date.hour12 = true;
return d3_time_parseHour24(date, string, i);
return n ? (date.H = +n[0], i += n[0].length) : -1;
}
function d3_time_parseMinutes(date, string, i) {
d3_time_numberRe.lastIndex = 0;
var n = d3_time_numberRe.exec(string.substring(i, i + 2));
return n ? (date.setMinutes(+n[0]), i += n[0].length) : -1;
return n ? (date.M = +n[0], i += n[0].length) : -1;
}
function d3_time_parseSeconds(date, string, i) {
d3_time_numberRe.lastIndex = 0;
var n = d3_time_numberRe.exec(string.substring(i, i + 2));
return n ? (date.setSeconds(+n[0]), i += n[0].length) : -1;
return n ? (date.S = +n[0], i += n[0].length) : -1;
}
function d3_time_parseMilliseconds(date, string, i) {
d3_time_numberRe.lastIndex = 0;
var n = d3_time_numberRe.exec(string.substring(i, i + 3));
return n ? (date.setMilliseconds(+n[0]), i += n[0].length) : -1;
return n ? (date.L = +n[0], i += n[0].length) : -1;
}
// Note: we don't look at the next directive.
@ -8921,7 +8918,7 @@ var d3_time_numberRe = /\s*\d+/;
function d3_time_parseAmPm(date, string, i) {
var n = d3_time_amPmLookup.get(string.substring(i, i += 2).toLowerCase());
return n == null ? -1 : (date.hour12pm = n, i);
return n == null ? -1 : (date.p = n, i);
}
var d3_time_amPmLookup = d3.map({

8
d3.v2.min.js поставляемый

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

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

@ -21,15 +21,16 @@ d3.time.format = function(template) {
}
format.parse = function(string) {
var date = new d3_time(1900, 0, 1),
i = d3_time_parse(date, template, string, 0);
var d = {y: 1900, m: 0, d: 1, H: 0, M: 0, S: 0, L: 0},
i = d3_time_parse(d, template, string, 0);
if (i != string.length) return null;
if (date.hour12) {
var hours = date.getHours() % 12;
date.setHours(date.hour12pm ? hours + 12 : hours);
}
delete date.hour12;
delete date.hour12pm;
// The am-pm flag is 0 for AM, and 1 for PM.
if ("p" in d) d.H = d.H % 12 + d.p * 12;
var date = new d3_time();
date.setFullYear(d.y, d.m, d.d);
date.setHours(d.H, d.M, d.S, d.L);
return date;
};
@ -100,7 +101,7 @@ var d3_time_parsers = {
d: d3_time_parseDay,
e: d3_time_parseDay,
H: d3_time_parseHour24,
I: d3_time_parseHour12,
I: d3_time_parseHour24,
// j: function(d, s, i) { /*TODO day of year [001,366] */ return i; },
L: d3_time_parseMilliseconds,
m: d3_time_parseMonthNumber,
@ -137,7 +138,7 @@ var d3_time_weekdayAbbrevRe = /^(?:sun|mon|tue|wed|thu|fri|sat)/i,
function d3_time_parseMonthAbbrev(date, string, i) {
var n = d3_time_monthAbbrevLookup.get(string.substring(i, i += 3).toLowerCase());
return n == null ? -1 : (date.setMonth(n), i);
return n == null ? -1 : (date.m = n, i);
}
var d3_time_monthAbbrevLookup = d3.map({
@ -158,7 +159,7 @@ var d3_time_monthAbbrevLookup = d3.map({
function d3_time_parseMonth(date, string, i) {
d3_time_monthRe.lastIndex = 0;
var n = d3_time_monthRe.exec(string.substring(i, i + 12));
return n ? (date.setMonth(d3_time_monthLookup.get(n[0].toLowerCase())), i += n[0].length) : -1;
return n ? (date.m = d3_time_monthLookup.get(n[0].toLowerCase()), i += n[0].length) : -1;
}
var d3_time_monthRe = /^(?:January|February|March|April|May|June|July|August|September|October|November|December)/ig;
@ -208,13 +209,13 @@ function d3_time_parseLocaleTime(date, string, i) {
function d3_time_parseFullYear(date, string, i) {
d3_time_numberRe.lastIndex = 0;
var n = d3_time_numberRe.exec(string.substring(i, i + 4));
return n ? (date.setFullYear(n[0]), i += n[0].length) : -1;
return n ? (date.y = +n[0], i += n[0].length) : -1;
}
function d3_time_parseYear(date, string, i) {
d3_time_numberRe.lastIndex = 0;
var n = d3_time_numberRe.exec(string.substring(i, i + 2));
return n ? (date.setFullYear(d3_time_century() + +n[0]), i += n[0].length) : -1;
return n ? (date.y = d3_time_century() + +n[0], i += n[0].length) : -1;
}
function d3_time_century() {
@ -224,44 +225,38 @@ function d3_time_century() {
function d3_time_parseMonthNumber(date, string, i) {
d3_time_numberRe.lastIndex = 0;
var n = d3_time_numberRe.exec(string.substring(i, i + 2));
return n ? (date.setMonth(n[0] - 1), i += n[0].length) : -1;
return n ? (date.m = n[0] - 1, i += n[0].length) : -1;
}
function d3_time_parseDay(date, string, i) {
d3_time_numberRe.lastIndex = 0;
var n = d3_time_numberRe.exec(string.substring(i, i + 2));
return n ? (date.setDate(+n[0]), i += n[0].length) : -1;
return n ? (date.d = +n[0], i += n[0].length) : -1;
}
// Note: we don't validate that the hour is in the range [0,23].
// Note: we don't validate that the hour is in the range [0,23] or [1,12].
function d3_time_parseHour24(date, string, i) {
d3_time_numberRe.lastIndex = 0;
var n = d3_time_numberRe.exec(string.substring(i, i + 2));
return n ? (date.setHours(+n[0]), i += n[0].length) : -1;
}
// Note: we don't validate that the hour is in the range [1,12].
function d3_time_parseHour12(date, string, i) {
date.hour12 = true;
return d3_time_parseHour24(date, string, i);
return n ? (date.H = +n[0], i += n[0].length) : -1;
}
function d3_time_parseMinutes(date, string, i) {
d3_time_numberRe.lastIndex = 0;
var n = d3_time_numberRe.exec(string.substring(i, i + 2));
return n ? (date.setMinutes(+n[0]), i += n[0].length) : -1;
return n ? (date.M = +n[0], i += n[0].length) : -1;
}
function d3_time_parseSeconds(date, string, i) {
d3_time_numberRe.lastIndex = 0;
var n = d3_time_numberRe.exec(string.substring(i, i + 2));
return n ? (date.setSeconds(+n[0]), i += n[0].length) : -1;
return n ? (date.S = +n[0], i += n[0].length) : -1;
}
function d3_time_parseMilliseconds(date, string, i) {
d3_time_numberRe.lastIndex = 0;
var n = d3_time_numberRe.exec(string.substring(i, i + 3));
return n ? (date.setMilliseconds(+n[0]), i += n[0].length) : -1;
return n ? (date.L = +n[0], i += n[0].length) : -1;
}
// Note: we don't look at the next directive.
@ -269,7 +264,7 @@ var d3_time_numberRe = /\s*\d+/;
function d3_time_parseAmPm(date, string, i) {
var n = d3_time_amPmLookup.get(string.substring(i, i += 2).toLowerCase());
return n == null ? -1 : (date.hour12pm = n, i);
return n == null ? -1 : (date.p = n, i);
}
var d3_time_amPmLookup = d3.map({

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

@ -20,13 +20,15 @@ d3_time_utc.prototype = {
getTime: function() { return this._.getTime(); },
getTimezoneOffset: function() { return 0; },
valueOf: function() { return this._.valueOf(); },
setDate: function(x) { this._.setUTCDate(x); },
setDay: function(x) { this._.setUTCDay(x); },
setFullYear: function(x) { this._.setUTCFullYear(x); },
setHours: function(x) { this._.setUTCHours(x); },
setMilliseconds: function(x) { this._.setUTCMilliseconds(x); },
setMinutes: function(x) { this._.setUTCMinutes(x); },
setMonth: function(x) { this._.setUTCMonth(x); },
setSeconds: function(x) { this._.setUTCSeconds(x); },
setTime: function(x) { this._.setTime(x); }
setDate: function() { d3_time_prototype.setUTCDate.apply(this._, arguments); },
setDay: function() { d3_time_prototype.setUTCDay.apply(this._, arguments); },
setFullYear: function() { d3_time_prototype.setUTCFullYear.apply(this._, arguments); },
setHours: function() { d3_time_prototype.setUTCHours.apply(this._, arguments); },
setMilliseconds: function() { d3_time_prototype.setUTCMilliseconds.apply(this._, arguments); },
setMinutes: function() { d3_time_prototype.setUTCMinutes.apply(this._, arguments); },
setMonth: function() { d3_time_prototype.setUTCMonth.apply(this._, arguments); },
setSeconds: function() { d3_time_prototype.setUTCSeconds.apply(this._, arguments); },
setTime: function() { d3_time_prototype.setTime.apply(this._, arguments); }
};
var d3_time_prototype = Date.prototype;

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

@ -1,7 +1,10 @@
require("../env");
var vows = require("vows"),
assert = require("assert");
assert = require("assert"),
time = require("./time"),
local = time.local,
utc = time.utc;
var suite = vows.describe("d3.time.day");
@ -168,12 +171,4 @@ suite.addBatch({
}
});
function local(year, month, day, hours, minutes, seconds) {
return new Date(year, month, day, hours || 00, minutes || 00, seconds || 00);
}
function utc(year, month, day, hours, minutes, seconds) {
return new Date(Date.UTC(year, month, day, hours || 00, minutes || 00, seconds || 00));
}
suite.export(module);

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

@ -1,7 +1,10 @@
require("../env");
var vows = require("vows"),
assert = require("assert");
assert = require("assert"),
time = require("./time"),
local = time.local,
utc = time.utc;
var suite = vows.describe("d3.time.days");
@ -92,12 +95,4 @@ suite.addBatch({
}
});
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,7 +1,10 @@
require("../env");
var vows = require("vows"),
assert = require("assert");
assert = require("assert"),
time = require("./time"),
local = time.local,
utc = time.utc;
var suite = vows.describe("d3.time.format");
@ -463,12 +466,4 @@ suite.addBatch({
}
});
function local(year, month, day, hours, minutes, seconds, milliseconds) {
return new Date(year, month, day, hours || 0, minutes || 0, seconds || 0, milliseconds || 0);
}
function utc(year, month, day, hours, minutes, seconds, milliseconds) {
return new Date(Date.UTC(year, month, day, hours || 0, minutes || 0, seconds || 0, milliseconds || 0));
}
suite.export(module);

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

@ -1,7 +1,10 @@
require("../env");
var vows = require("vows"),
assert = require("assert");
assert = require("assert"),
time = require("./time"),
local = time.local,
utc = time.utc;
var suite = vows.describe("d3.time.hour");
@ -39,14 +42,14 @@ suite.addBatch({
assert.deepEqual(floor(utc(2011, 10, 06, 09, 01)), utc(2011, 10, 06, 09));
},
"NPT": {
"observes 15-minute offset": tz("Asia/Kathmandu", function(floor) {
"observes 15-minute offset": time.zone("Asia/Kathmandu", function(floor) {
assert.deepEqual(floor(local(2010, 11, 31, 23, 59, 59)), utc(2010, 11, 31, 17, 15));
assert.deepEqual(floor(local(2011, 00, 01, 00, 00, 00)), utc(2010, 11, 31, 18, 15));
assert.deepEqual(floor(local(2011, 00, 01, 00, 00, 01)), utc(2010, 11, 31, 18, 15));
})
},
"IST": {
"observes 30-minute offset": tz("Asia/Calcutta", function(floor) {
"observes 30-minute offset": time.zone("Asia/Calcutta", function(floor) {
assert.deepEqual(floor(local(2010, 11, 31, 23, 59, 59)), utc(2010, 11, 31, 17, 30));
assert.deepEqual(floor(local(2011, 00, 01, 00, 00, 00)), utc(2010, 11, 31, 18, 30));
assert.deepEqual(floor(local(2011, 00, 01, 00, 00, 01)), utc(2010, 11, 31, 18, 30));
@ -79,14 +82,14 @@ suite.addBatch({
assert.deepEqual(ceil(utc(2011, 10, 06, 09, 01)), utc(2011, 10, 06, 10));
},
"NPT": {
"observes 15-minute offset": tz("Asia/Kathmandu", function(ceil) {
"observes 15-minute offset": time.zone("Asia/Kathmandu", function(ceil) {
assert.deepEqual(ceil(local(2010, 11, 31, 23, 59, 59)), utc(2010, 11, 31, 18, 15));
assert.deepEqual(ceil(local(2011, 00, 01, 00, 00, 00)), utc(2010, 11, 31, 18, 15));
assert.deepEqual(ceil(local(2011, 00, 01, 00, 00, 01)), utc(2010, 11, 31, 19, 15));
})
},
"IST": {
"observes 30-minute offset": tz("Asia/Calcutta", function(ceil) {
"observes 30-minute offset": time.zone("Asia/Calcutta", function(ceil) {
assert.deepEqual(ceil(local(2010, 11, 31, 23, 59, 59)), utc(2010, 11, 31, 18, 30));
assert.deepEqual(ceil(local(2011, 00, 01, 00, 00, 00)), utc(2010, 11, 31, 18, 30));
assert.deepEqual(ceil(local(2011, 00, 01, 00, 00, 01)), utc(2010, 11, 31, 19, 30));
@ -212,28 +215,4 @@ suite.addBatch({
}
});
function local(year, month, day, hours, minutes, seconds) {
return new Date(year, month, day, hours || 00, minutes || 00, seconds || 00);
}
function utc(year, month, day, hours, minutes, seconds) {
return new Date(Date.UTC(year, month, day, hours || 00, minutes || 00, seconds || 00));
}
function tz(tz, scope) {
return function() {
var o = process.env.TZ;
try {
process.env.TZ = tz;
new Date(0).toString(); // invalidate node's dst cache
new Date().toString();
scope.apply(this, arguments);
} finally {
process.env.TZ = o;
new Date(0).toString(); // invalidate node's dst cache
new Date().toString();
}
};
}
suite.export(module);

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

@ -1,7 +1,10 @@
require("../env");
var vows = require("vows"),
assert = require("assert");
assert = require("assert"),
time = require("./time"),
local = time.local,
utc = time.utc;
var suite = vows.describe("d3.time.hours");
@ -106,14 +109,6 @@ suite.addBatch({
}
});
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));
}
function tz(tz, scope) {
return function() {
var o = process.env.TZ;

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

@ -1,7 +1,10 @@
require("../env");
var vows = require("vows"),
assert = require("assert");
assert = require("assert"),
time = require("./time"),
local = time.local,
utc = time.utc;
var suite = vows.describe("d3.time.minute");
@ -124,12 +127,4 @@ suite.addBatch({
}
});
function local(year, month, day, hours, minutes, seconds) {
return new Date(year, month, day, hours || 00, minutes || 00, seconds || 00);
}
function utc(year, month, day, hours, minutes, seconds) {
return new Date(Date.UTC(year, month, day, hours || 00, minutes || 00, seconds || 00));
}
suite.export(module);

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

@ -1,7 +1,10 @@
require("../env");
var vows = require("vows"),
assert = require("assert");
assert = require("assert"),
time = require("./time"),
local = time.local,
utc = time.utc;
var suite = vows.describe("d3.time.minutes");
@ -88,12 +91,4 @@ suite.addBatch({
}
});
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,7 +1,10 @@
require("../env");
var vows = require("vows"),
assert = require("assert");
assert = require("assert"),
time = require("./time"),
local = time.local,
utc = time.utc;
var suite = vows.describe("d3.time.month");
@ -144,12 +147,4 @@ suite.addBatch({
}
});
function local(year, month, day, hours, minutes, seconds) {
return new Date(year, month, day, hours || 00, minutes || 00, seconds || 00);
}
function utc(year, month, day, hours, minutes, seconds) {
return new Date(Date.UTC(year, month, day, hours || 00, minutes || 00, seconds || 00));
}
suite.export(module);

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

@ -1,7 +1,10 @@
require("../env");
var vows = require("vows"),
assert = require("assert");
assert = require("assert"),
time = require("./time"),
local = time.local,
utc = time.utc;
var suite = vows.describe("d3.time.months");
@ -92,12 +95,4 @@ suite.addBatch({
}
});
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,7 +1,10 @@
require("../env");
var vows = require("vows"),
assert = require("assert");
assert = require("assert"),
time = require("./time"),
local = time.local,
utc = time.utc;
var suite = vows.describe("d3.time.scale");
@ -561,16 +564,4 @@ suite.addBatch({
}
});
function local(year, month, day, hours, minutes, seconds, milliseconds) {
var date = new Date(year, month, day, hours || 0, minutes || 0, seconds || 0, milliseconds || 0);
date.setFullYear(year); // Y2K fail
return date;
}
function utc(year, month, day, hours, minutes, seconds, milliseconds) {
var date = new Date(Date.UTC(year, month, day, hours || 0, minutes || 0, seconds || 0, milliseconds || 0));
date.setUTCFullYear(year); // Y2K fail
return date;
}
suite.export(module);

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

@ -1,7 +1,10 @@
require("../env");
var vows = require("vows"),
assert = require("assert");
assert = require("assert"),
time = require("./time"),
local = time.local,
utc = time.utc;
var suite = vows.describe("d3.time.second");
@ -140,12 +143,4 @@ suite.addBatch({
}
});
function local(year, month, day, hours, minutes, seconds, milliseconds) {
return new Date(year, month, day, hours || 00, minutes || 00, seconds || 00, milliseconds || 00);
}
function utc(year, month, day, hours, minutes, seconds, milliseconds) {
return new Date(Date.UTC(year, month, day, hours || 00, minutes || 00, seconds || 00, milliseconds || 00));
}
suite.export(module);

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

@ -1,7 +1,10 @@
require("../env");
var vows = require("vows"),
assert = require("assert");
assert = require("assert"),
time = require("./time"),
local = time.local,
utc = time.utc;
var suite = vows.describe("d3.time.seconds");
@ -88,12 +91,4 @@ suite.addBatch({
}
});
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);

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

@ -0,0 +1,29 @@
exports.local = function(year, month, day, hours, minutes, seconds, milliseconds) {
var date = new Date();
date.setFullYear(year, month, day);
date.setHours(hours || 0, minutes || 0, seconds || 0, milliseconds || 0);
return date;
};
exports.utc = function(year, month, day, hours, minutes, seconds, milliseconds) {
var date = new Date();
date.setUTCFullYear(year, month, day);
date.setUTCHours(hours || 0, minutes || 0, seconds || 0, milliseconds || 0);
return date;
};
exports.zone = function(tz, scope) {
return function() {
var o = process.env.TZ;
try {
process.env.TZ = tz;
new Date(0).toString(); // invalidate node's dst cache
new Date().toString();
scope.apply(this, arguments);
} finally {
process.env.TZ = o;
new Date(0).toString(); // invalidate node's dst cache
new Date().toString();
}
};
};

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

@ -1,7 +1,10 @@
require("../env");
var vows = require("vows"),
assert = require("assert");
assert = require("assert"),
time = require("./time"),
local = time.local,
utc = time.utc;
var suite = vows.describe("d3.time.week");
@ -156,12 +159,4 @@ suite.addBatch({
}
});
function local(year, month, day, hours, minutes, seconds) {
return new Date(year, month, day, hours || 00, minutes || 00, seconds || 00);
}
function utc(year, month, day, hours, minutes, seconds) {
return new Date(Date.UTC(year, month, day, hours || 00, minutes || 00, seconds || 00));
}
suite.export(module);

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

@ -1,7 +1,10 @@
require("../env");
var vows = require("vows"),
assert = require("assert");
assert = require("assert"),
time = require("./time"),
local = time.local,
utc = time.utc;
var suite = vows.describe("d3.time.weeks");
@ -92,12 +95,4 @@ suite.addBatch({
}
});
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);

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

@ -120,12 +120,18 @@ suite.addBatch({
}
});
function local(year, month, day, hours, minutes, seconds) {
return new Date(year, month, day, hours || 00, minutes || 00, seconds || 00);
function local(year, month, day, hours, minutes, seconds, milliseconds) {
var date = new Date();
date.setFullYear(year, month, day);
date.setHours(hours || 0, minutes || 0, seconds || 0, milliseconds || 0);
return date;
}
function utc(year, month, day, hours, minutes, seconds) {
return new Date(Date.UTC(year, month, day, hours || 00, minutes || 00, seconds || 00));
function utc(year, month, day, hours, minutes, seconds, milliseconds) {
var date = new Date();
date.setUTCFullYear(year, month, day);
date.setUTCHours(hours || 0, minutes || 0, seconds || 0, milliseconds || 0);
return date;
}
suite.export(module);

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

@ -60,12 +60,18 @@ suite.addBatch({
}
});
function local(year, month, day, hours, minutes, seconds) {
return new Date(year, month, day, hours || 0, minutes || 0, seconds || 0);
function local(year, month, day, hours, minutes, seconds, milliseconds) {
var date = new Date();
date.setFullYear(year, month, day);
date.setHours(hours || 0, minutes || 0, seconds || 0, milliseconds || 0);
return date;
}
function utc(year, month, day, hours, minutes, seconds) {
return new Date(Date.UTC(year, month, day, hours || 0, minutes || 0, seconds || 0));
function utc(year, month, day, hours, minutes, seconds, milliseconds) {
var date = new Date();
date.setUTCFullYear(year, month, day);
date.setUTCHours(hours || 0, minutes || 0, seconds || 0, milliseconds || 0);
return date;
}
suite.export(module);