Skip to content

Commit

Permalink
Merge branch 'time-format-locale' into 2.10.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mbostock committed Aug 9, 2012
2 parents 6dd9939 + fbcc82b commit 609ab91
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 96 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ NODE_PATH ?= ./node_modules
JS_COMPILER = $(NODE_PATH)/uglify-js/bin/uglifyjs
JS_BEAUTIFIER = $(NODE_PATH)/uglify-js/bin/uglifyjs -b -i 2 -nm -ns
JS_TESTER = $(NODE_PATH)/vows/bin/vows
LOCALE ?= en_US

all: \
d3.v2.js \
Expand Down Expand Up @@ -195,6 +196,7 @@ d3.csv.js: \

d3.time.js: \
src/time/time.js \
src/time/format-$(LOCALE).js \
src/time/format.js \
src/time/format-utc.js \
src/time/format-iso.js \
Expand Down
55 changes: 19 additions & 36 deletions d3.v2.js
Original file line number Diff line number Diff line change
Expand Up @@ -6271,7 +6271,7 @@
};
}
d3.time = {};
var d3_time = Date;
var d3_time = Date, d3_time_weekdaySymbols = [ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" ];
function d3_time_utc() {
this._ = new Date(arguments.length > 1 ? Date.UTC.apply(this, arguments) : arguments[0]);
}
Expand Down Expand Up @@ -6338,6 +6338,8 @@
}
};
var d3_time_prototype = Date.prototype;
var d3_time_formatDateTime = "%a %b %e %H:%M:%S %Y", d3_time_formatDate = "%m/%d/%y", d3_time_formatTime = "%H:%M:%S";
var d3_time_weekdays = d3_time_weekdaySymbols, d3_time_months = [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ];
d3.time.format = function(template) {
var n = template.length;
function format(date) {
Expand Down Expand Up @@ -6387,7 +6389,19 @@
}
return j;
}
function d3_time_formatAbbrev(s) {
return s.substring(0, 3);
}
function d3_time_formatRe(names) {
return new RegExp("^(?:" + names.map(d3.requote).join("|") + ")", "i");
}
function d3_time_formatLookup(names) {
var map = new d3_Map, i = -1, n = names.length;
while (++i < n) map.set(names[i].toLowerCase(), i);
return map;
}
var d3_time_zfill2 = d3.format("02d"), d3_time_zfill3 = d3.format("03d"), d3_time_zfill4 = d3.format("04d"), d3_time_sfill2 = d3.format("2d");
var d3_time_weekdayRe = d3_time_formatRe(d3_time_weekdays), d3_time_weekdayAbbrevRe = d3_time_formatRe(d3_time_weekdays.map(d3_time_formatAbbrev)), d3_time_monthRe = d3_time_formatRe(d3_time_months), d3_time_monthLookup = d3_time_formatLookup(d3_time_months), d3_time_monthAbbrevLookup = d3_time_formatLookup(d3_time_months.map(d3_time_formatAbbrev));
var d3_time_formats = {
a: function(d) {
return d3_time_weekdays[d.getDay()].substring(0, 3);
Expand All @@ -6401,7 +6415,7 @@
B: function(d) {
return d3_time_months[d.getMonth()];
},
c: d3.time.format("%a %b %e %H:%M:%S %Y"),
c: d3.time.format(d3_time_formatDateTime),
d: function(d) {
return d3_time_zfill2(d.getDate());
},
Expand Down Expand Up @@ -6441,8 +6455,8 @@
W: function(d) {
return d3_time_zfill2(d3.time.mondayOfYear(d));
},
x: d3.time.format("%m/%d/%y"),
X: d3.time.format("%H:%M:%S"),
x: d3.time.format(d3_time_formatDate),
X: d3.time.format(d3_time_formatTime),
y: function(d) {
return d3_time_zfill2(d.getFullYear() % 100);
},
Expand Down Expand Up @@ -6482,46 +6496,15 @@
var n = d3_time_weekdayRe.exec(string.substring(i, i + 10));
return n ? i += n[0].length : -1;
}
var d3_time_weekdayAbbrevRe = /^(?:sun|mon|tue|wed|thu|fri|sat)/i, d3_time_weekdayRe = /^(?:Sunday|Monday|Tuesday|Wednesday|Thursday|Friday|Saturday)/i, d3_time_weekdays = [ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" ];
function d3_time_parseMonthAbbrev(date, string, i) {
var n = d3_time_monthAbbrevLookup.get(string.substring(i, i += 3).toLowerCase());
return n == null ? -1 : (date.m = n, i);
}
var d3_time_monthAbbrevLookup = d3.map({
jan: 0,
feb: 1,
mar: 2,
apr: 3,
may: 4,
jun: 5,
jul: 6,
aug: 7,
sep: 8,
oct: 9,
nov: 10,
dec: 11
});
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.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;
var d3_time_monthLookup = d3.map({
january: 0,
february: 1,
march: 2,
april: 3,
may: 4,
june: 5,
july: 6,
august: 7,
september: 8,
october: 9,
november: 10,
december: 11
});
var d3_time_months = [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ];
function d3_time_parseLocaleFull(date, string, i) {
return d3_time_parse(date, d3_time_formats.c.toString(), string, i);
}
Expand Down Expand Up @@ -6724,7 +6707,7 @@
var year = d3.time.year(date);
return Math.floor((date - year - (date.getTimezoneOffset() - year.getTimezoneOffset()) * 6e4) / 864e5);
};
d3_time_weekdays.forEach(function(day, i) {
d3_time_weekdaySymbols.forEach(function(day, i) {
day = day.toLowerCase();
i = 7 - i;
var interval = d3.time[day] = d3_time_interval(function(date) {
Expand Down
8 changes: 4 additions & 4 deletions d3.v2.min.js

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions src/time/format-en_US.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// The date and time format (%c), date format (%x) and time format (%X).
var d3_time_formatDateTime = "%a %b %e %H:%M:%S %Y",
d3_time_formatDate = "%m/%d/%y",
d3_time_formatTime = "%H:%M:%S";

// The weekday and month names.
var d3_time_weekdays = d3_time_weekdaySymbols,
d3_time_months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
8 changes: 8 additions & 0 deletions src/time/format-fr_FR.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// The date and time format (%c), date format (%x) and time format (%X).
var d3_time_formatDateTime = "%a %e %b %H:%M:%S %Y",
d3_time_formatDate = "%d.%m.%y",
d3_time_formatTime = "%H:%M:%S";

// The weekday and month names.
var d3_time_weekdays = ["dimanche", "lundi", "mardi", "mercredi", "jeudi", "vendredi", "samedi"],
d3_time_months = ["janvier", "février", "mars", "avril", "mai", "juin", "juillet", "août", "septembre", "octobre", "novembre", "décembre"];
77 changes: 23 additions & 54 deletions src/time/format.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,37 @@ function d3_time_parse(date, template, string, j) {
return j;
}

function d3_time_formatAbbrev(s) {
return s.substring(0, 3);
}

function d3_time_formatRe(names) {
return new RegExp("^(?:" + names.map(d3.requote).join("|") + ")", "i");
}

function d3_time_formatLookup(names) {
var map = new d3_Map, i = -1, n = names.length;
while (++i < n) map.set(names[i].toLowerCase(), i);
return map;
}

var d3_time_zfill2 = d3.format("02d"),
d3_time_zfill3 = d3.format("03d"),
d3_time_zfill4 = d3.format("04d"),
d3_time_sfill2 = d3.format("2d");

var d3_time_weekdayRe = d3_time_formatRe(d3_time_weekdays),
d3_time_weekdayAbbrevRe = d3_time_formatRe(d3_time_weekdays.map(d3_time_formatAbbrev)),
d3_time_monthRe = d3_time_formatRe(d3_time_months),
d3_time_monthLookup = d3_time_formatLookup(d3_time_months),
d3_time_monthAbbrevLookup = d3_time_formatLookup(d3_time_months.map(d3_time_formatAbbrev));

var d3_time_formats = {
a: function(d) { return d3_time_weekdays[d.getDay()].substring(0, 3); },
A: function(d) { return d3_time_weekdays[d.getDay()]; },
b: function(d) { return d3_time_months[d.getMonth()].substring(0, 3); },
B: function(d) { return d3_time_months[d.getMonth()]; },
c: d3.time.format("%a %b %e %H:%M:%S %Y"),
c: d3.time.format(d3_time_formatDateTime),
d: function(d) { return d3_time_zfill2(d.getDate()); },
e: function(d) { return d3_time_sfill2(d.getDate()); },
H: function(d) { return d3_time_zfill2(d.getHours()); },
Expand All @@ -84,8 +104,8 @@ var d3_time_formats = {
U: function(d) { return d3_time_zfill2(d3.time.sundayOfYear(d)); },
w: function(d) { return d.getDay(); },
W: function(d) { return d3_time_zfill2(d3.time.mondayOfYear(d)); },
x: d3.time.format("%m/%d/%y"),
X: d3.time.format("%H:%M:%S"),
x: d3.time.format(d3_time_formatDate),
X: d3.time.format(d3_time_formatTime),
y: function(d) { return d3_time_zfill2(d.getFullYear() % 100); },
Y: function(d) { return d3_time_zfill4(d.getFullYear() % 10000); },
Z: d3_time_zone,
Expand Down Expand Up @@ -132,68 +152,17 @@ function d3_time_parseWeekday(date, string, i) {
return n ? i += n[0].length : -1;
}

var d3_time_weekdayAbbrevRe = /^(?:sun|mon|tue|wed|thu|fri|sat)/i,
d3_time_weekdayRe = /^(?:Sunday|Monday|Tuesday|Wednesday|Thursday|Friday|Saturday)/i,
d3_time_weekdays = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];

function d3_time_parseMonthAbbrev(date, string, i) {
var n = d3_time_monthAbbrevLookup.get(string.substring(i, i += 3).toLowerCase());
return n == null ? -1 : (date.m = n, i);
}

var d3_time_monthAbbrevLookup = d3.map({
jan: 0,
feb: 1,
mar: 2,
apr: 3,
may: 4,
jun: 5,
jul: 6,
aug: 7,
sep: 8,
oct: 9,
nov: 10,
dec: 11
});

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.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;

var d3_time_monthLookup = d3.map({
january: 0,
february: 1,
march: 2,
april: 3,
may: 4,
june: 5,
july: 6,
august: 7,
september: 8,
october: 9,
november: 10,
december: 11
});

var d3_time_months = [
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"
];

function d3_time_parseLocaleFull(date, string, i) {
return d3_time_parse(date, d3_time_formats.c.toString(), string, i);
}
Expand Down
3 changes: 2 additions & 1 deletion src/time/time.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
d3.time = {};

var d3_time = Date;
var d3_time = Date,
d3_time_weekdaySymbols = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];

function d3_time_utc() {
this._ = new Date(arguments.length > 1
Expand Down
2 changes: 1 addition & 1 deletion src/time/week.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
d3_time_weekdays.forEach(function(day, i) {
d3_time_weekdaySymbols.forEach(function(day, i) {
day = day.toLowerCase();
i = 7 - i;

Expand Down

0 comments on commit 609ab91

Please sign in to comment.