2013-03-26 21:16:13 +00:00
|
|
|
/*! Two digit year parser
|
2013-03-26 21:05:21 +00:00
|
|
|
* Demo: http://jsfiddle.net/Mottie/abkNM/427/
|
|
|
|
*/
|
|
|
|
/*jshint jquery:true */
|
|
|
|
;(function($){
|
|
|
|
"use strict";
|
|
|
|
|
2013-09-29 19:37:03 +00:00
|
|
|
var ts = $.tablesorter,
|
|
|
|
|
2013-03-26 21:05:21 +00:00
|
|
|
// Make the date be within +/- range of the 2 digit year
|
|
|
|
// so if the current year is 2020, and the 2 digit year is 80 (2080 - 2020 > 50), it becomes 1980
|
|
|
|
// if the 2 digit year is 50 (2050 - 2020 < 50), then it becomes 2050.
|
2013-09-29 19:37:03 +00:00
|
|
|
range = 50;
|
|
|
|
|
|
|
|
ts.dates = $.extend({}, ts.dates, {
|
|
|
|
regxxxxyy: /(\d{1,2})[\/\s](\d{1,2})[\/\s](\d{2})/,
|
|
|
|
regyyxxxx: /(\d{2})[\/\s](\d{1,2})[\/\s](\d{1,2})/
|
|
|
|
});
|
2013-03-26 21:05:21 +00:00
|
|
|
|
2013-11-14 02:31:26 +00:00
|
|
|
ts.formatDate = function(s, regex, format, table){
|
2014-03-05 18:50:46 +00:00
|
|
|
var n = s
|
|
|
|
// replace separators
|
|
|
|
.replace(/\s+/g," ").replace(/[-.,]/g, "/")
|
|
|
|
// reformat xx/xx/xx to mm/dd/19yy;
|
2014-03-07 18:53:21 +00:00
|
|
|
.replace(regex, format),
|
2014-03-05 18:50:46 +00:00
|
|
|
d = new Date(n),
|
2013-09-29 19:37:03 +00:00
|
|
|
y = d.getFullYear(),
|
2013-11-14 02:31:26 +00:00
|
|
|
rng = table && table.config.dateRange || range,
|
2013-09-29 19:37:03 +00:00
|
|
|
now = new Date().getFullYear();
|
2013-03-26 21:05:21 +00:00
|
|
|
// if date > 50 years old (set range), add 100 years
|
|
|
|
// this will work when people start using "50" and mean "2050"
|
2013-11-14 02:31:26 +00:00
|
|
|
while (now - y > rng) {
|
2013-03-26 21:05:21 +00:00
|
|
|
y += 100;
|
|
|
|
}
|
2014-03-05 18:50:46 +00:00
|
|
|
return d.setFullYear(y) || s;
|
2013-03-26 21:05:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
$.tablesorter.addParser({
|
|
|
|
id: "ddmmyy",
|
|
|
|
is: function() {
|
|
|
|
return false;
|
|
|
|
},
|
2013-11-14 02:31:26 +00:00
|
|
|
format: function(s, table) {
|
2013-03-26 21:05:21 +00:00
|
|
|
// reformat dd/mm/yy to mm/dd/19yy;
|
2013-11-14 02:31:26 +00:00
|
|
|
return ts.formatDate(s, ts.dates.regxxxxyy, "$2/$1/19$3", table);
|
2013-03-26 21:05:21 +00:00
|
|
|
},
|
|
|
|
type: "numeric"
|
|
|
|
});
|
|
|
|
|
|
|
|
$.tablesorter.addParser({
|
|
|
|
id: "mmddyy",
|
|
|
|
is: function() {
|
|
|
|
return false;
|
|
|
|
},
|
2013-11-14 02:31:26 +00:00
|
|
|
format: function(s, table) {
|
2013-03-26 21:05:21 +00:00
|
|
|
// reformat mm/dd/yy to mm/dd/19yy
|
2013-11-14 02:31:26 +00:00
|
|
|
return ts.formatDate(s, ts.dates.regxxxxyy, "$1/$2/19$3", table);
|
2013-03-26 21:05:21 +00:00
|
|
|
},
|
|
|
|
type: "numeric"
|
|
|
|
});
|
|
|
|
|
|
|
|
$.tablesorter.addParser({
|
|
|
|
id: "yymmdd",
|
|
|
|
is: function() {
|
|
|
|
return false;
|
|
|
|
},
|
2013-11-14 02:31:26 +00:00
|
|
|
format: function(s, table) {
|
2013-03-26 21:05:21 +00:00
|
|
|
// reformat yy/mm/dd to mm/dd/19yy
|
2013-11-14 02:31:26 +00:00
|
|
|
return ts.formatDate(s, ts.dates.regyyxxxx, "$2/$3/19$1", table);
|
2013-03-26 21:05:21 +00:00
|
|
|
},
|
|
|
|
type: "numeric"
|
|
|
|
});
|
|
|
|
|
|
|
|
})(jQuery);
|