Skip to content

Commit 3d4d679

Browse files
committed
Fix for locale-specific abbreviations.
1 parent 15ba641 commit 3d4d679

8 files changed

Lines changed: 69 additions & 44 deletions

File tree

d3.v2.js

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6289,7 +6289,7 @@
62896289
};
62906290
}
62916291
d3.time = {};
6292-
var d3_time = Date, d3_time_weekdaySymbols = [ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" ];
6292+
var d3_time = Date, d3_time_daySymbols = [ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" ];
62936293
function d3_time_utc() {
62946294
this._ = new Date(arguments.length > 1 ? Date.UTC.apply(this, arguments) : arguments[0]);
62956295
}
@@ -6357,7 +6357,10 @@
63576357
};
63586358
var d3_time_prototype = Date.prototype;
63596359
var d3_time_formatDateTime = "%a %b %e %H:%M:%S %Y", d3_time_formatDate = "%m/%d/%y", d3_time_formatTime = "%H:%M:%S";
6360-
var d3_time_weekdays = d3_time_weekdaySymbols, d3_time_months = [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ];
6360+
var d3_time_days = d3_time_daySymbols, d3_time_dayAbbreviations = d3_time_days.map(d3_time_formatAbbreviate), d3_time_months = [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ], d3_time_monthAbbreviations = d3_time_months.map(d3_time_formatAbbreviate);
6361+
function d3_time_formatAbbreviate(name) {
6362+
return name.substring(0, 3);
6363+
}
63616364
d3.time.format = function(template) {
63626365
var n = template.length;
63636366
function format(date) {
@@ -6407,9 +6410,6 @@
64076410
}
64086411
return j;
64096412
}
6410-
function d3_time_formatAbbrev(s) {
6411-
return s.substring(0, 3);
6412-
}
64136413
function d3_time_formatRe(names) {
64146414
return new RegExp("^(?:" + names.map(d3.requote).join("|") + ")", "i");
64156415
}
@@ -6419,16 +6419,16 @@
64196419
return map;
64206420
}
64216421
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");
6422-
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));
6422+
var d3_time_dayRe = d3_time_formatRe(d3_time_days), d3_time_dayAbbrevRe = d3_time_formatRe(d3_time_dayAbbreviations), d3_time_monthRe = d3_time_formatRe(d3_time_months), d3_time_monthLookup = d3_time_formatLookup(d3_time_months), d3_time_monthAbbrevRe = d3_time_formatRe(d3_time_monthAbbreviations), d3_time_monthAbbrevLookup = d3_time_formatLookup(d3_time_monthAbbreviations);
64236423
var d3_time_formats = {
64246424
a: function(d) {
6425-
return d3_time_weekdays[d.getDay()].substring(0, 3);
6425+
return d3_time_dayAbbreviations[d.getDay()];
64266426
},
64276427
A: function(d) {
6428-
return d3_time_weekdays[d.getDay()];
6428+
return d3_time_days[d.getDay()];
64296429
},
64306430
b: function(d) {
6431-
return d3_time_months[d.getMonth()].substring(0, 3);
6431+
return d3_time_monthAbbreviations[d.getMonth()];
64326432
},
64336433
B: function(d) {
64346434
return d3_time_months[d.getMonth()];
@@ -6507,20 +6507,23 @@
65076507
Y: d3_time_parseFullYear
65086508
};
65096509
function d3_time_parseWeekdayAbbrev(date, string, i) {
6510-
return d3_time_weekdayAbbrevRe.test(string.substring(i, i += 3)) ? i : -1;
6510+
d3_time_dayAbbrevRe.lastIndex = 0;
6511+
var n = d3_time_dayAbbrevRe.exec(string.substring(i));
6512+
return n ? i += n[0].length : -1;
65116513
}
65126514
function d3_time_parseWeekday(date, string, i) {
6513-
d3_time_weekdayRe.lastIndex = 0;
6514-
var n = d3_time_weekdayRe.exec(string.substring(i, i + 10));
6515+
d3_time_dayRe.lastIndex = 0;
6516+
var n = d3_time_dayRe.exec(string.substring(i));
65156517
return n ? i += n[0].length : -1;
65166518
}
65176519
function d3_time_parseMonthAbbrev(date, string, i) {
6518-
var n = d3_time_monthAbbrevLookup.get(string.substring(i, i += 3).toLowerCase());
6519-
return n == null ? -1 : (date.m = n, i);
6520+
d3_time_monthAbbrevRe.lastIndex = 0;
6521+
var n = d3_time_monthAbbrevRe.exec(string.substring(i));
6522+
return n ? (date.m = d3_time_monthAbbrevLookup.get(n[0].toLowerCase()), i += n[0].length) : -1;
65206523
}
65216524
function d3_time_parseMonth(date, string, i) {
65226525
d3_time_monthRe.lastIndex = 0;
6523-
var n = d3_time_monthRe.exec(string.substring(i, i + 12));
6526+
var n = d3_time_monthRe.exec(string.substring(i));
65246527
return n ? (date.m = d3_time_monthLookup.get(n[0].toLowerCase()), i += n[0].length) : -1;
65256528
}
65266529
function d3_time_parseLocaleFull(date, string, i) {
@@ -6575,7 +6578,7 @@
65756578
var n = d3_time_numberRe.exec(string.substring(i, i + 3));
65766579
return n ? (date.L = +n[0], i += n[0].length) : -1;
65776580
}
6578-
var d3_time_numberRe = /\s*\d+/;
6581+
var d3_time_numberRe = /^\s*\d+/;
65796582
function d3_time_parseAmPm(date, string, i) {
65806583
var n = d3_time_amPmLookup.get(string.substring(i, i += 2).toLowerCase());
65816584
return n == null ? -1 : (date.p = n, i);
@@ -6725,7 +6728,7 @@
67256728
var year = d3.time.year(date);
67266729
return Math.floor((date - year - (date.getTimezoneOffset() - year.getTimezoneOffset()) * 6e4) / 864e5);
67276730
};
6728-
d3_time_weekdaySymbols.forEach(function(day, i) {
6731+
d3_time_daySymbols.forEach(function(day, i) {
67296732
day = day.toLowerCase();
67306733
i = 7 - i;
67316734
var interval = d3.time[day] = d3_time_interval(function(date) {

d3.v2.min.js

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/time/format-en_US.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,11 @@ var d3_time_formatDateTime = "%a %b %e %H:%M:%S %Y",
44
d3_time_formatTime = "%H:%M:%S";
55

66
// The weekday and month names.
7-
var d3_time_weekdays = d3_time_weekdaySymbols,
8-
d3_time_months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
7+
var d3_time_days = d3_time_daySymbols,
8+
d3_time_dayAbbreviations = d3_time_days.map(d3_time_formatAbbreviate),
9+
d3_time_months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
10+
d3_time_monthAbbreviations = d3_time_months.map(d3_time_formatAbbreviate);
11+
12+
function d3_time_formatAbbreviate(name) {
13+
return name.substring(0, 3);
14+
}

src/time/format-fr_FR.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,11 @@ var d3_time_formatDateTime = "%a %e %b %H:%M:%S %Y",
44
d3_time_formatTime = "%H:%M:%S";
55

66
// The weekday and month names.
7-
var d3_time_weekdays = ["dimanche", "lundi", "mardi", "mercredi", "jeudi", "vendredi", "samedi"],
8-
d3_time_months = ["janvier", "février", "mars", "avril", "mai", "juin", "juillet", "août", "septembre", "octobre", "novembre", "décembre"];
7+
var d3_time_days = ["dimanche", "lundi", "mardi", "mercredi", "jeudi", "vendredi", "samedi"],
8+
d3_time_dayAbbreviations = d3_time_days.map(d3_time_formatAbbreviate),
9+
d3_time_months = ["janvier", "février", "mars", "avril", "mai", "juin", "juillet", "août", "septembre", "octobre", "novembre", "décembre"],
10+
d3_time_monthAbbreviations = d3_time_months.map(d3_time_formatAbbreviate);
11+
12+
function d3_time_formatAbbreviate(name) {
13+
return name.substring(0, 3);
14+
}

src/time/format-ru_RU.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// The date and time format (%c), date format (%x) and time format (%X).
2+
var d3_time_formatDateTime = "%a %e %b %H:%M:%S %Y",
3+
d3_time_formatDate = "%d.%m.%y",
4+
d3_time_formatTime = "%H:%M:%S";
5+
6+
// The weekday and month names.
7+
var d3_time_days = ["воскресенье", "понедельник", "вторник", "среда", "четверг", "пятница", "суббота"],
8+
d3_time_dayAbbreviations = ["Вс", "Пн", "Вт", "Ср", "Чт", "Пт", "Сб"],
9+
d3_time_months = ["январь", "февраль", "март", "апрель", "май", "июнь", "июль", "август", "сентябрь", "октябрь", "ноябрь", "декабрь"],
10+
d3_time_monthAbbreviations = ["янв", "фев", "мар", "апр", "май", "июн", "июл", "авг", "сен", "окт", "ноя", "дек"];

src/time/format.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,6 @@ function d3_time_parse(date, template, string, j) {
6060
return j;
6161
}
6262

63-
function d3_time_formatAbbrev(s) {
64-
return s.substring(0, 3);
65-
}
66-
6763
function d3_time_formatRe(names) {
6864
return new RegExp("^(?:" + names.map(d3.requote).join("|") + ")", "i");
6965
}
@@ -79,16 +75,17 @@ var d3_time_zfill2 = d3.format("02d"),
7975
d3_time_zfill4 = d3.format("04d"),
8076
d3_time_sfill2 = d3.format("2d");
8177

82-
var d3_time_weekdayRe = d3_time_formatRe(d3_time_weekdays),
83-
d3_time_weekdayAbbrevRe = d3_time_formatRe(d3_time_weekdays.map(d3_time_formatAbbrev)),
78+
var d3_time_dayRe = d3_time_formatRe(d3_time_days),
79+
d3_time_dayAbbrevRe = d3_time_formatRe(d3_time_dayAbbreviations),
8480
d3_time_monthRe = d3_time_formatRe(d3_time_months),
8581
d3_time_monthLookup = d3_time_formatLookup(d3_time_months),
86-
d3_time_monthAbbrevLookup = d3_time_formatLookup(d3_time_months.map(d3_time_formatAbbrev));
82+
d3_time_monthAbbrevRe = d3_time_formatRe(d3_time_monthAbbreviations),
83+
d3_time_monthAbbrevLookup = d3_time_formatLookup(d3_time_monthAbbreviations);
8784

8885
var d3_time_formats = {
89-
a: function(d) { return d3_time_weekdays[d.getDay()].substring(0, 3); },
90-
A: function(d) { return d3_time_weekdays[d.getDay()]; },
91-
b: function(d) { return d3_time_months[d.getMonth()].substring(0, 3); },
86+
a: function(d) { return d3_time_dayAbbreviations[d.getDay()]; },
87+
A: function(d) { return d3_time_days[d.getDay()]; },
88+
b: function(d) { return d3_time_monthAbbreviations[d.getMonth()]; },
9289
B: function(d) { return d3_time_months[d.getMonth()]; },
9390
c: d3.time.format(d3_time_formatDateTime),
9491
d: function(d) { return d3_time_zfill2(d.getDate()); },
@@ -142,24 +139,27 @@ var d3_time_parsers = {
142139

143140
// Note: weekday is validated, but does not set the date.
144141
function d3_time_parseWeekdayAbbrev(date, string, i) {
145-
return d3_time_weekdayAbbrevRe.test(string.substring(i, i += 3)) ? i : -1;
142+
d3_time_dayAbbrevRe.lastIndex = 0;
143+
var n = d3_time_dayAbbrevRe.exec(string.substring(i));
144+
return n ? i += n[0].length : -1;
146145
}
147146

148147
// Note: weekday is validated, but does not set the date.
149148
function d3_time_parseWeekday(date, string, i) {
150-
d3_time_weekdayRe.lastIndex = 0;
151-
var n = d3_time_weekdayRe.exec(string.substring(i, i + 10));
149+
d3_time_dayRe.lastIndex = 0;
150+
var n = d3_time_dayRe.exec(string.substring(i));
152151
return n ? i += n[0].length : -1;
153152
}
154153

155154
function d3_time_parseMonthAbbrev(date, string, i) {
156-
var n = d3_time_monthAbbrevLookup.get(string.substring(i, i += 3).toLowerCase());
157-
return n == null ? -1 : (date.m = n, i);
155+
d3_time_monthAbbrevRe.lastIndex = 0;
156+
var n = d3_time_monthAbbrevRe.exec(string.substring(i));
157+
return n ? (date.m = d3_time_monthAbbrevLookup.get(n[0].toLowerCase()), i += n[0].length) : -1;
158158
}
159159

160160
function d3_time_parseMonth(date, string, i) {
161161
d3_time_monthRe.lastIndex = 0;
162-
var n = d3_time_monthRe.exec(string.substring(i, i + 12));
162+
var n = d3_time_monthRe.exec(string.substring(i));
163163
return n ? (date.m = d3_time_monthLookup.get(n[0].toLowerCase()), i += n[0].length) : -1;
164164
}
165165

@@ -229,7 +229,7 @@ function d3_time_parseMilliseconds(date, string, i) {
229229
}
230230

231231
// Note: we don't look at the next directive.
232-
var d3_time_numberRe = /\s*\d+/;
232+
var d3_time_numberRe = /^\s*\d+/;
233233

234234
function d3_time_parseAmPm(date, string, i) {
235235
var n = d3_time_amPmLookup.get(string.substring(i, i += 2).toLowerCase());

src/time/time.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
d3.time = {};
22

33
var d3_time = Date,
4-
d3_time_weekdaySymbols = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
4+
d3_time_daySymbols = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
55

66
function d3_time_utc() {
77
this._ = new Date(arguments.length > 1

src/time/week.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
d3_time_weekdaySymbols.forEach(function(day, i) {
1+
d3_time_daySymbols.forEach(function(day, i) {
22
day = day.toLowerCase();
33
i = 7 - i;
44

0 commit comments

Comments
 (0)