2016-11-27 01:40:00 +00:00
|
|
|
/*! Parser: two digit year - updated 11/26/2016 (v2.28.0) */
|
2015-03-28 20:03:50 +00:00
|
|
|
/* Demo: http://mottie.github.io/tablesorter/docs/example-parsers-dates.html */
|
2013-03-26 21:05:21 +00:00
|
|
|
/*jshint jquery:true */
|
|
|
|
;(function($){
|
2015-07-23 04:29:51 +00:00
|
|
|
'use strict';
|
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.
|
2014-09-30 21:20:04 +00:00
|
|
|
var range = 50,
|
|
|
|
|
|
|
|
// no need to change any of the code below
|
|
|
|
ts = $.tablesorter,
|
|
|
|
now = new Date().getFullYear();
|
2013-09-29 19:37:03 +00:00
|
|
|
|
2016-11-26 16:39:31 +00:00
|
|
|
// add dateRange to defaults for validator; value must be falsy
|
|
|
|
ts.defaults.dataRange = '';
|
|
|
|
|
2015-11-23 03:21:50 +00:00
|
|
|
if ( !ts.dates ) { ts.dates = {}; }
|
|
|
|
ts.dates.regxxxxyy = /(\d{1,2})[\/\s](\d{1,2})[\/\s](\d{2})/;
|
|
|
|
ts.dates.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-09-30 21:20:04 +00:00
|
|
|
if (s) {
|
|
|
|
var y, rng,
|
|
|
|
n = s
|
|
|
|
// replace separators
|
2015-07-23 04:29:51 +00:00
|
|
|
.replace(/\s+/g, ' ').replace(/[-.,]/g, '/')
|
2014-09-30 21:20:04 +00:00
|
|
|
// reformat xx/xx/xx to mm/dd/19yy;
|
|
|
|
.replace(regex, format),
|
|
|
|
d = new Date(n);
|
|
|
|
if ( d instanceof Date && isFinite(d) ) {
|
|
|
|
y = d.getFullYear();
|
|
|
|
rng = table && table.config.dateRange || range;
|
|
|
|
// if date > 50 years old (set range), add 100 years
|
2015-07-23 04:29:51 +00:00
|
|
|
// this will work when people start using '50' and mean '2050'
|
2014-09-30 21:20:04 +00:00
|
|
|
while (now - y > rng) {
|
|
|
|
y += 100;
|
|
|
|
}
|
|
|
|
return d.setFullYear(y);
|
|
|
|
}
|
2013-03-26 21:05:21 +00:00
|
|
|
}
|
2014-09-30 21:20:04 +00:00
|
|
|
return s;
|
2013-03-26 21:05:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
$.tablesorter.addParser({
|
2015-07-23 04:29:51 +00:00
|
|
|
id: 'ddmmyy',
|
2013-03-26 21:05:21 +00:00
|
|
|
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;
|
2015-07-23 04:29:51 +00:00
|
|
|
return ts.formatDate(s, ts.dates.regxxxxyy, '$2/$1/19$3', table);
|
2013-03-26 21:05:21 +00:00
|
|
|
},
|
2015-07-23 04:29:51 +00:00
|
|
|
type: 'numeric'
|
2013-03-26 21:05:21 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
$.tablesorter.addParser({
|
2015-07-23 04:29:51 +00:00
|
|
|
id: 'mmddyy',
|
2013-03-26 21:05:21 +00:00
|
|
|
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
|
2015-07-23 04:29:51 +00:00
|
|
|
return ts.formatDate(s, ts.dates.regxxxxyy, '$1/$2/19$3', table);
|
2013-03-26 21:05:21 +00:00
|
|
|
},
|
2015-07-23 04:29:51 +00:00
|
|
|
type: 'numeric'
|
2013-03-26 21:05:21 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
$.tablesorter.addParser({
|
2015-07-23 04:29:51 +00:00
|
|
|
id: 'yymmdd',
|
2013-03-26 21:05:21 +00:00
|
|
|
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
|
2015-07-23 04:29:51 +00:00
|
|
|
return ts.formatDate(s, ts.dates.regyyxxxx, '$2/$3/19$1', table);
|
2013-03-26 21:05:21 +00:00
|
|
|
},
|
2015-07-23 04:29:51 +00:00
|
|
|
type: 'numeric'
|
2013-03-26 21:05:21 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
})(jQuery);
|