1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
| var sortEnglishDateTime = fdTableSort.sortNumeric;
function sortEnglishDateTimePrepareData(tdNode, innerText) {
// You can localise the function here
var months = ['january','february','march','april','may','june','july','august','september','october','november','december','jan','feb','mar','apr','may','jun','jul','aug','sep','oct','nov','dec'];
// Lowercase the text
var aa = innerText.toLowerCase();
// Replace the longhand and shorthand months with an integer equivalent
for(var i = 0; i < months.length; i++) {
aa = aa.replace(new RegExp(months[i] + '([\\s|,]{1})'), (i+13)%12 + " ");
};
// Replace multiple spaces and anything that is not valid in the parsing of the date, then trim
aa = aa.replace(/\s+/g, " ").replace(/([^\d\s\/-:.])/g, "").replace(/^\s\s*/, '').replace(/\s\s*$/, '');
// REMOVED: No timestamp at the end, then return -1
//if(aa.search(/(\d){2} [decu]\d){2}( [decu]\d){2})?$/) == -1) { return -1; };
// No timestamp at the end, then create a false one
if(aa.search(/(\d){2} [decu]\d){2}( [decu]\d){2})?$/) == -1) { aa += " 00:00:00"; };
// Grab the timestamp
var timestamp = aa.match(/(\d){2} [decu]\d){2}( [decu]\d){2})?$/)[0].replace(/:/g, "");
// Make the timestamp 6 characters by default
if(timestamp.length == 4) { timestamp += "00"; };
// Remove it from the string to assist the date parser, then trim
aa = aa.replace(/(\d){2} [decu]\d){2}( [decu]\d){2})?$/, "").replace(/\s\s*$/, '');
// If you want the parser to favour the parsing of European dd/mm/yyyy dates then leave this set to "true"
// If you want the parser to favour the parsing of American mm/dd/yyyy dates then set to "false"
var favourDMY = true;
// If you have a regular expression you wish to add, add the Object to the end of the array
var dateTest = [
{ regExp:/^(0?[1-9]|1[012])([- \/.])(0?[1-9]|[12][0-9]|3[01])([- \/.])((\d\d)?\d\d)$/, d:3, m:1, y:5 }, // mdy
{ regExp:/^(0?[1-9]|[12][0-9]|3[01])([- \/.])(0?[1-9]|1[012])([- \/.])((\d\d)?\d\d)$/, d:1, m:3, y:5 }, // dmy
{ regExp:/^(\d\d\d\d)([- \/.])(0?[1-9]|1[012])([- \/.])(0?[1-9]|[12][0-9]|3[01])$/, d:5, m:3, y:1 } // ymd
];
var start,y,m,d;
var cnt = 0;
var numFormats = dateTest.length;
while(cnt < numFormats) {
start = (cnt + (favourDMY ? numFormats + 1 : numFormats)) % numFormats;
if(aa.match(dateTest[start].regExp)) {
res = aa.match(dateTest[start].regExp);
y = res[dateTest[start].y];
m = res[dateTest[start].m];
d = res[dateTest[start].d];
if(m.length == 1) m = "0" + String(m);
if(d.length == 1) d = "0" + String(d);
if(y.length != 4) y = (parseInt(y) < 50) ? "20" + String(y) : "19" + String(y);
return y+String(m)+d+String(timestamp);
};
cnt++;
};
return -1;
}; |
Partager