tablesorter/js/parsers/parser-date.js

39 lines
1014 B
JavaScript
Raw Normal View History

2016-08-22 15:41:07 +00:00
/*! Parser: dates - updated 8/22/2016 (v2.27.5) */
/* Extract dates using popular natural language date parsers */
2013-03-26 21:05:21 +00:00
/*jshint jquery:true */
2016-08-21 14:50:50 +00:00
/*global Sugar*/
2013-03-26 21:05:21 +00:00
;(function($){
'use strict';
2013-03-26 21:05:21 +00:00
/*! Sugar (https://sugarjs.com/docs/#/DateParsing) */
/* demo: http://jsfiddle.net/Mottie/abkNM/4163/ */
2013-03-26 21:05:21 +00:00
$.tablesorter.addParser({
id: 'sugar',
2013-03-26 21:05:21 +00:00
is: function() {
return false;
},
format: function(s) {
// Add support for sugar v2.0+
var create = Date.create || Sugar.Date.create,
date = create ? create(s) : s ? new Date(s) : s;
return date instanceof Date && isFinite(date) ? date.getTime() : s;
2013-03-26 21:05:21 +00:00
},
type: 'numeric'
2013-03-26 21:05:21 +00:00
});
/*! Datejs (http://www.datejs.com/) */
/* demo: http://jsfiddle.net/Mottie/abkNM/4164/ */
2013-03-26 21:05:21 +00:00
$.tablesorter.addParser({
id: 'datejs',
2013-03-26 21:05:21 +00:00
is: function() {
return false;
},
format: function(s) {
var date = Date.parse ? Date.parse(s) : s ? new Date(s) : s;
return date instanceof Date && isFinite(date) ? date.getTime() : s;
2013-03-26 21:05:21 +00:00
},
type: 'numeric'
2013-03-26 21:05:21 +00:00
});
})(jQuery);