2015-03-28 20:03:50 +00:00
|
|
|
/*! Parser: Extract out date - updated 10/26/2014 (v2.18.0) */
|
2014-03-27 03:18:10 +00:00
|
|
|
/*jshint jquery:true */
|
2018-03-17 20:30:25 +00:00
|
|
|
;(function($) {
|
2015-07-23 04:29:51 +00:00
|
|
|
'use strict';
|
2014-03-27 03:18:10 +00:00
|
|
|
|
2014-09-30 21:20:04 +00:00
|
|
|
var regex = {
|
|
|
|
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})/
|
|
|
|
};
|
|
|
|
|
2015-03-28 20:03:50 +00:00
|
|
|
/*! extract US Long Date *//* (ignore any other text)
|
2015-07-23 04:29:51 +00:00
|
|
|
* e.g. 'Sue's Birthday! Jun 26, 2004 7:22 AM (8# 2oz)'
|
2015-03-28 20:03:50 +00:00
|
|
|
* demo: http://jsfiddle.net/Mottie/abkNM/4165/ */
|
2014-03-27 03:18:10 +00:00
|
|
|
$.tablesorter.addParser({
|
2015-07-23 04:29:51 +00:00
|
|
|
id: 'extractUSLongDate',
|
2014-10-27 00:11:12 +00:00
|
|
|
is: function () {
|
2014-03-27 03:18:10 +00:00
|
|
|
// don't auto detect this parser
|
|
|
|
return false;
|
|
|
|
},
|
2014-10-27 00:11:12 +00:00
|
|
|
format: function (s) {
|
2014-09-30 21:20:04 +00:00
|
|
|
var date,
|
|
|
|
str = s ? s.match(regex.usLong) : s;
|
|
|
|
if (str) {
|
|
|
|
date = new Date( str[0] );
|
|
|
|
return date instanceof Date && isFinite(date) ? date.getTime() : s;
|
|
|
|
}
|
|
|
|
return s;
|
2014-03-27 03:18:10 +00:00
|
|
|
},
|
2015-07-23 04:29:51 +00:00
|
|
|
type: 'numeric'
|
2014-03-27 03:18:10 +00:00
|
|
|
});
|
|
|
|
|
2015-03-28 20:03:50 +00:00
|
|
|
/*! extract MMDDYYYY *//* (ignore any other text)
|
|
|
|
* demo: http://jsfiddle.net/Mottie/abkNM/4166/ */
|
2014-03-27 03:18:10 +00:00
|
|
|
$.tablesorter.addParser({
|
2015-07-23 04:29:51 +00:00
|
|
|
id: 'extractMMDDYYYY',
|
2014-10-27 00:11:12 +00:00
|
|
|
is: function () {
|
2014-03-27 03:18:10 +00:00
|
|
|
// don't auto detect this parser
|
|
|
|
return false;
|
|
|
|
},
|
2014-10-27 00:11:12 +00:00
|
|
|
format: function (s) {
|
2014-09-30 21:20:04 +00:00
|
|
|
var date,
|
2015-07-23 04:29:51 +00:00
|
|
|
str = s ? s.replace(/\s+/g, ' ').replace(/[\-.,]/g, '/').match(regex.mdy) : s;
|
2014-09-30 21:20:04 +00:00
|
|
|
if (str) {
|
|
|
|
date = new Date( str[0] );
|
|
|
|
return date instanceof Date && isFinite(date) ? date.getTime() : s;
|
|
|
|
}
|
|
|
|
return s;
|
2014-03-27 03:18:10 +00:00
|
|
|
},
|
2015-07-23 04:29:51 +00:00
|
|
|
type: 'numeric'
|
2014-03-27 03:18:10 +00:00
|
|
|
});
|
|
|
|
|
2015-03-28 20:03:50 +00:00
|
|
|
/*! extract DDMMYYYY *//* (ignore any other text)
|
|
|
|
* demo: http://jsfiddle.net/Mottie/abkNM/4167/ */
|
2014-03-27 03:18:10 +00:00
|
|
|
$.tablesorter.addParser({
|
2015-07-23 04:29:51 +00:00
|
|
|
id: 'extractDDMMYYYY',
|
2014-10-27 00:11:12 +00:00
|
|
|
is: function () {
|
2014-03-27 03:18:10 +00:00
|
|
|
// don't auto detect this parser
|
|
|
|
return false;
|
|
|
|
},
|
2014-10-27 00:11:12 +00:00
|
|
|
format: function (s) {
|
2014-09-30 21:20:04 +00:00
|
|
|
var date,
|
2015-07-23 04:29:51 +00:00
|
|
|
str = s ? s.replace(/\s+/g, ' ').replace(/[\-.,]/g, '/').match(regex.dmy) : s;
|
2014-09-30 21:20:04 +00:00
|
|
|
if (str) {
|
2015-07-23 04:29:51 +00:00
|
|
|
date = new Date( str[0].replace(regex.dmyreplace, '$2/$1/$3') );
|
2014-09-30 21:20:04 +00:00
|
|
|
return date instanceof Date && isFinite(date) ? date.getTime() : s;
|
2014-03-27 03:18:10 +00:00
|
|
|
}
|
|
|
|
return s;
|
|
|
|
},
|
2015-07-23 04:29:51 +00:00
|
|
|
type: 'numeric'
|
2014-03-27 03:18:10 +00:00
|
|
|
});
|
|
|
|
|
2015-03-28 20:03:50 +00:00
|
|
|
/*! extract YYYYMMDD *//* (ignore any other text)
|
|
|
|
* demo: http://jsfiddle.net/Mottie/abkNM/4168/ */
|
2014-03-27 03:18:10 +00:00
|
|
|
$.tablesorter.addParser({
|
2015-07-23 04:29:51 +00:00
|
|
|
id: 'extractYYYYMMDD',
|
2014-10-27 00:11:12 +00:00
|
|
|
is: function () {
|
2014-03-27 03:18:10 +00:00
|
|
|
// don't auto detect this parser
|
|
|
|
return false;
|
|
|
|
},
|
2014-10-27 00:11:12 +00:00
|
|
|
format: function (s) {
|
2014-09-30 21:20:04 +00:00
|
|
|
var date,
|
2015-07-23 04:29:51 +00:00
|
|
|
str = s ? s.replace(/\s+/g, ' ').replace(/[\-.,]/g, '/').match(regex.ymd) : s;
|
2014-09-30 21:20:04 +00:00
|
|
|
if (str) {
|
2015-07-23 04:29:51 +00:00
|
|
|
date = new Date( str[0].replace(regex.ymdreplace, '$2/$3/$1') );
|
2014-09-30 21:20:04 +00:00
|
|
|
return date instanceof Date && isFinite(date) ? date.getTime() : s;
|
2014-03-27 03:18:10 +00:00
|
|
|
}
|
|
|
|
return s;
|
|
|
|
},
|
2015-07-23 04:29:51 +00:00
|
|
|
type: 'numeric'
|
2014-03-27 03:18:10 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
})(jQuery);
|