| 8 |
lars |
1 |
/**
|
|
|
2 |
* This plug-in provides the ability to sort columns that contains time
|
|
|
3 |
* information in the most common formats used. It will automatically detect
|
|
|
4 |
* those date types.
|
|
|
5 |
*
|
|
|
6 |
* Please note that this plug-in is **deprecated*. The
|
|
|
7 |
* [datetime](//datatables.net/blog/2014-12-18) plug-in provides enhanced
|
|
|
8 |
* functionality and flexibility.
|
|
|
9 |
*
|
|
|
10 |
* @name Time (dd/mm/YY)
|
|
|
11 |
* @summary Sort Times in the formats: `hh:mm, hh:mm:ss, hh:mm tt, hh:mm:ss tt`
|
|
|
12 |
* e.g. '22:50, 22:50:40, 10:50 pm, 10:50:40 pm'
|
|
|
13 |
* am and pm are not case sensitive. white space is not compulsory
|
|
|
14 |
* @author David Stoneham
|
|
|
15 |
* @deprecated
|
|
|
16 |
*
|
|
|
17 |
* @example
|
|
|
18 |
* $('#example').dataTable( {
|
|
|
19 |
* columnDefs: [
|
|
|
20 |
* { type: 'time-uni', targets: 0 }
|
|
|
21 |
* ]
|
|
|
22 |
* } );
|
|
|
23 |
*/
|
|
|
24 |
|
|
|
25 |
jQuery.extend(jQuery.fn.dataTableExt.oSort, {
|
|
|
26 |
"time-uni-pre": function (a) {
|
|
|
27 |
var uniTime;
|
|
|
28 |
|
|
|
29 |
if (a.toLowerCase().indexOf("am") > -1 || (a.toLowerCase().indexOf("pm") > -1 && Number(a.split(":")[0]) === 12)) {
|
|
|
30 |
uniTime = a.toLowerCase().split("pm")[0].split("am")[0];
|
|
|
31 |
while (uniTime.indexOf(":") > -1) {
|
|
|
32 |
uniTime = uniTime.replace(":", "");
|
|
|
33 |
}
|
|
|
34 |
} else if (a.toLowerCase().indexOf("pm") > -1 || (a.toLowerCase().indexOf("am") > -1 && Number(a.split(":")[0]) === 12)) {
|
|
|
35 |
uniTime = Number(a.split(":")[0]) + 12;
|
|
|
36 |
var leftTime = a.toLowerCase().split("pm")[0].split("am")[0].split(":");
|
|
|
37 |
for (var i = 1; i < leftTime.length; i++) {
|
|
|
38 |
uniTime = uniTime + leftTime[i].trim().toString();
|
|
|
39 |
}
|
|
|
40 |
} else {
|
|
|
41 |
uniTime = a.replace(":", "");
|
|
|
42 |
while (uniTime.indexOf(":") > -1) {
|
|
|
43 |
uniTime = uniTime.replace(":", "");
|
|
|
44 |
}
|
|
|
45 |
}
|
|
|
46 |
return Number(uniTime);
|
|
|
47 |
},
|
|
|
48 |
|
|
|
49 |
"time-uni-asc": function (a, b) {
|
|
|
50 |
return ((a < b) ? -1 : ((a > b) ? 1 : 0));
|
|
|
51 |
},
|
|
|
52 |
|
|
|
53 |
"time-uni-desc": function (a, b) {
|
|
|
54 |
return ((a < b) ? 1 : ((a > b) ? -1 : 0));
|
|
|
55 |
}
|
|
|
56 |
});
|