tablesorter/dist/js/parsers/parser-date-two-digit-year.min.js

19 lines
1.6 KiB
JavaScript
Raw Normal View History

/*! Parser: two digit year - updated 10/26/2014 (v2.18.0) */
2015-10-31 15:08:21 +00:00
/* Demo: http://mottie.github.io/tablesorter/docs/example-parsers-dates.html */
/*jshint jquery:true */
!function(a){"use strict";
// 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.
var b=50,
// no need to change any of the code below
c=a.tablesorter,d=(new Date).getFullYear();c.dates=a.extend({},c.dates,{regxxxxyy:/(\d{1,2})[\/\s](\d{1,2})[\/\s](\d{2})/,regyyxxxx:/(\d{2})[\/\s](\d{1,2})[\/\s](\d{1,2})/}),c.formatDate=function(a,c,e,f){if(a){var g,h,i=a.replace(/\s+/g," ").replace(/[-.,]/g,"/").replace(c,e),j=new Date(i);if(j instanceof Date&&isFinite(j)){
// if date > 50 years old (set range), add 100 years
// this will work when people start using '50' and mean '2050'
for(g=j.getFullYear(),h=f&&f.config.dateRange||b;d-g>h;)g+=100;return j.setFullYear(g)}}return a},a.tablesorter.addParser({id:"ddmmyy",is:function(){return!1},format:function(a,b){
// reformat dd/mm/yy to mm/dd/19yy;
return c.formatDate(a,c.dates.regxxxxyy,"$2/$1/19$3",b)},type:"numeric"}),a.tablesorter.addParser({id:"mmddyy",is:function(){return!1},format:function(a,b){
// reformat mm/dd/yy to mm/dd/19yy
return c.formatDate(a,c.dates.regxxxxyy,"$1/$2/19$3",b)},type:"numeric"}),a.tablesorter.addParser({id:"yymmdd",is:function(){return!1},format:function(a,b){
// reformat yy/mm/dd to mm/dd/19yy
return c.formatDate(a,c.dates.regyyxxxx,"$2/$3/19$1",b)},type:"numeric"})}(jQuery);