diff --git a/docs/example-parsers-dates.html b/docs/example-parsers-dates.html
index 5327e2a4..029db7c6 100644
--- a/docs/example-parsers-dates.html
+++ b/docs/example-parsers-dates.html
@@ -33,7 +33,9 @@
// call the tablesorter plugin
$("table").tablesorter({
theme : 'blue',
- widgets : ["zebra"]
+ widgets : ["zebra"],
+ // date range used by the two-digit year parser (added v2.14.0)
+ dateRange : 30
});
});
@@ -62,6 +64,7 @@
So if the current year is 2020
, and the listed two digit year is 80
(2080 - 2020 > 50
), it becomes 1980
.
If the listed two digit year is 50
(2050 - 2020 < 50
), then it becomes 2050
. I hope that makes it clearer.
Try out the two digit year calculator below the table.
+ In v2.14.0, the range can be set using the dateRange
option (see the initialization code below).
The "Time" column is using the built-in time parser which has been always been included with tablesorter .
diff --git a/js/parsers/parser-date-two-digit-year.js b/js/parsers/parser-date-two-digit-year.js
index 95fe8e49..932a32ff 100644
--- a/js/parsers/parser-date-two-digit-year.js
+++ b/js/parsers/parser-date-two-digit-year.js
@@ -17,7 +17,7 @@
regyyxxxx: /(\d{2})[\/\s](\d{1,2})[\/\s](\d{1,2})/
});
- ts.formatDate = function(s, regex, format){
+ ts.formatDate = function(s, regex, format, table){
s = s
// replace separators
.replace(/\s+/g," ").replace(/[-.,]/g, "/")
@@ -25,10 +25,11 @@
.replace(regex, format);
var d = new Date(s),
y = d.getFullYear(),
+ rng = table && table.config.dateRange || range,
now = new Date().getFullYear();
// if date > 50 years old (set range), add 100 years
// this will work when people start using "50" and mean "2050"
- while (now - y > range) {
+ while (now - y > rng) {
y += 100;
}
return d.setFullYear(y);
@@ -39,9 +40,9 @@
is: function() {
return false;
},
- format: function(s) {
+ format: function(s, table) {
// reformat dd/mm/yy to mm/dd/19yy;
- return ts.formatDate(s, ts.dates.regxxxxyy, "$2/$1/19$3");
+ return ts.formatDate(s, ts.dates.regxxxxyy, "$2/$1/19$3", table);
},
type: "numeric"
});
@@ -51,9 +52,9 @@
is: function() {
return false;
},
- format: function(s) {
+ format: function(s, table) {
// reformat mm/dd/yy to mm/dd/19yy
- return ts.formatDate(s, ts.dates.regxxxxyy, "$1/$2/19$3");
+ return ts.formatDate(s, ts.dates.regxxxxyy, "$1/$2/19$3", table);
},
type: "numeric"
});
@@ -63,9 +64,9 @@
is: function() {
return false;
},
- format: function(s) {
+ format: function(s, table) {
// reformat yy/mm/dd to mm/dd/19yy
- return ts.formatDate(s, ts.dates.regyyxxxx, "$2/$3/19$1");
+ return ts.formatDate(s, ts.dates.regyyxxxx, "$2/$3/19$1", table);
},
type: "numeric"
});