tablesorter/dist/js/parsers/parser-date-extract.min.js

18 lines
2.0 KiB
JavaScript
Raw Normal View History

/*!
* Extract out date parsers
* 10/26/2014 (v2.18.0)
*/
!function(a){"use strict";var b={usLong:/[A-Z]{3,10}\.?\s+\d{1,2},?\s+(?:\d{4})(?:\s+\d{1,2}:\d{2}(?::\d{2})?(?:\s+[AP]M)?)?/i,mdy:/(\d{1,2}[\/\s]\d{1,2}[\/\s]\d{4}(\s+\d{1,2}:\d{2}(:\d{2})?(\s+[AP]M)?)?)/i,dmy:/(\d{1,2}[\/\s]\d{1,2}[\/\s]\d{4}(\s+\d{1,2}:\d{2}(:\d{2})?(\s+[AP]M)?)?)/i,dmyreplace:/(\d{1,2})[\/\s](\d{1,2})[\/\s](\d{4})/,ymd:/(\d{4}[\/\s]\d{1,2}[\/\s]\d{1,2}(\s+\d{1,2}:\d{2}(:\d{2})?(\s+[AP]M)?)?)/i,ymdreplace:/(\d{4})[\/\s](\d{1,2})[\/\s](\d{1,2})/};/*! extract US Long Date (ignore any other text)
* e.g. "Sue's Birthday! Jun 26, 2004 7:22 AM (8# 2oz)"
* demo: http://jsfiddle.net/Mottie/abkNM/4165/
*/
a.tablesorter.addParser({id:"extractUSLongDate",is:function(){return!1},format:function(a){var c,d=a?a.match(b.usLong):a;return d?(c=new Date(d[0]),c instanceof Date&&isFinite(c)?c.getTime():a):a},type:"numeric"}),/*! extract MMDDYYYY (ignore any other text)
* demo: http://jsfiddle.net/Mottie/abkNM/4166/
*/
a.tablesorter.addParser({id:"extractMMDDYYYY",is:function(){return!1},format:function(a){var c,d=a?a.replace(/\s+/g," ").replace(/[\-.,]/g,"/").match(b.mdy):a;return d?(c=new Date(d[0]),c instanceof Date&&isFinite(c)?c.getTime():a):a},type:"numeric"}),/*! extract DDMMYYYY (ignore any other text)
* demo: http://jsfiddle.net/Mottie/abkNM/4167/
*/
a.tablesorter.addParser({id:"extractDDMMYYYY",is:function(){return!1},format:function(a){var c,d=a?a.replace(/\s+/g," ").replace(/[\-.,]/g,"/").match(b.dmy):a;return d?(c=new Date(d[0].replace(b.dmyreplace,"$2/$1/$3")),c instanceof Date&&isFinite(c)?c.getTime():a):a},type:"numeric"}),/*! extract YYYYMMDD (ignore any other text)
* demo: http://jsfiddle.net/Mottie/abkNM/4168/
*/
a.tablesorter.addParser({id:"extractYYYYMMDD",is:function(){return!1},format:function(a){var c,d=a?a.replace(/\s+/g," ").replace(/[\-.,]/g,"/").match(b.ymd):a;return d?(c=new Date(d[0].replace(b.ymdreplace,"$2/$3/$1")),c instanceof Date&&isFinite(c)?c.getTime():a):a},type:"numeric"})}(jQuery);