| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
;(function($) { |
| 5 |
'use strict'; |
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
var range = 50, |
| 11 |
|
| 12 |
|
| 13 |
ts = $.tablesorter, |
| 14 |
now = new Date().getFullYear(); |
| 15 |
|
| 16 |
|
| 17 |
ts.defaults.dataRange = ''; |
| 18 |
|
| 19 |
if ( !ts.dates ) { ts.dates = {}; } |
| 20 |
ts.dates.regxxxxyy = /(\d{1,2})[\/\s](\d{1,2})[\/\s](\d{2})/; |
| 21 |
ts.dates.regyyxxxx = /(\d{2})[\/\s](\d{1,2})[\/\s](\d{1,2})/; |
| 22 |
|
| 23 |
ts.formatDate = function(s, regex, format, table) { |
| 24 |
if (s) { |
| 25 |
var y, rng, |
| 26 |
n = s |
| 27 |
|
| 28 |
.replace(/\s+/g, ' ').replace(/[-.,]/g, '/') |
| 29 |
|
| 30 |
.replace(regex, format), |
| 31 |
d = new Date(n); |
| 32 |
if ( d instanceof Date && isFinite(d) ) { |
| 33 |
y = d.getFullYear(); |
| 34 |
rng = table && table.config.dateRange || range; |
| 35 |
|
| 36 |
|
| 37 |
while (now - y > rng) { |
| 38 |
y += 100; |
| 39 |
} |
| 40 |
return d.setFullYear(y); |
| 41 |
} |
| 42 |
} |
| 43 |
return s; |
| 44 |
}; |
| 45 |
|
| 46 |
$.tablesorter.addParser({ |
| 47 |
id: 'ddmmyy', |
| 48 |
is: function() { |
| 49 |
return false; |
| 50 |
}, |
| 51 |
format: function(s, table) { |
| 52 |
|
| 53 |
return ts.formatDate(s, ts.dates.regxxxxyy, '$2/$1/19$3', table); |
| 54 |
}, |
| 55 |
type: 'numeric' |
| 56 |
}); |
| 57 |
|
| 58 |
$.tablesorter.addParser({ |
| 59 |
id: 'mmddyy', |
| 60 |
is: function() { |
| 61 |
return false; |
| 62 |
}, |
| 63 |
format: function(s, table) { |
| 64 |
|
| 65 |
return ts.formatDate(s, ts.dates.regxxxxyy, '$1/$2/19$3', table); |
| 66 |
}, |
| 67 |
type: 'numeric' |
| 68 |
}); |
| 69 |
|
| 70 |
$.tablesorter.addParser({ |
| 71 |
id: 'yymmdd', |
| 72 |
is: function() { |
| 73 |
return false; |
| 74 |
}, |
| 75 |
format: function(s, table) { |
| 76 |
|
| 77 |
return ts.formatDate(s, ts.dates.regyyxxxx, '$2/$3/19$1', table); |
| 78 |
}, |
| 79 |
type: 'numeric' |
| 80 |
}); |
| 81 |
|
| 82 |
})(jQuery); |