Subversion-Projekte lars-tiefland.cienc

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
8 lars 1
/*
2
 * Adds a new sorting option to dataTables called `datetime-us`.
3
 *
4
 * Also included is a type detection plug-in. Matches and sorts date / time
5
 * strings in the format: `(m)m/(d)d/(yy)yy (h)h/m(m) (am|pm)`. For example:
6
 *
7
 * * 1/1/13 1:4 pm
8
 * * 01/01/2013 01:04 PM
9
 * * 1/1/2013 1:04 Pm
10
 *
11
 * Please note that this plug-in is **deprecated*. The
12
 * [datetime](//datatables.net/blog/2014-12-18) plug-in provides enhanced
13
 * functionality and flexibility.
14
 *
15
 *  @name Date / time - US
16
 *  @summary Sort date / time in the format `m/d/yy h:m am|pm`
17
 *  @author [Kevin Gravier](http://mrkmg.com/)
18
 *  @deprecated
19
 *
20
 *  @example
21
 *    $('#example').dataTable( {
22
 *       columnDefs: [
23
 *         { type: 'datetime-us', targets: 0 }
24
 *       ]
25
 *    } );
26
*/
27
jQuery.extend(jQuery.fn.dataTableExt.oSort, {
28
    "datetime-us-pre": function (a) {
29
        var b = a.match(/(\d{1,2})\/(\d{1,2})\/(\d{2,4}) (\d{1,2}):(\d{1,2}) (am|pm|AM|PM|Am|Pm)/),
30
            month = b[1],
31
            day = b[2],
32
            year = b[3],
33
            hour = b[4],
34
            min = b[5],
35
            ap = b[6].toLowerCase();
36
 
37
        if (hour == '12') {
38
            hour = '0';
39
            if (ap == 'pm') {
40
                hour = parseInt(hour, 10) + 12;
41
            }
42
 
43
            if (year.length == 2) {
44
                if (parseInt(year, 10) < 70) {
45
                    year = '20' + year;
46
                }
47
                else {
48
                    year = '19' + year;
49
                }
50
            }
51
            if (month.length == 1) {
52
                month = '0' + month;
53
            }
54
            if (day.length == 1) {
55
                day = '0' + day;
56
            }
57
            if (hour.length == 1) {
58
                hour = '0' + hour;
59
            }
60
            if (min.length == 1) {
61
                min = '0' + min;
62
            }
63
 
64
            var tt = year + month + day + hour + min;
65
            return tt;
66
        }
67
    },
68
 
69
    "datetime-us-asc": function (a, b) {
70
            return a - b;
71
    },
72
 
73
    "datetime-us-desc": function (a, b) {
74
        return b - a;
75
    }
76
});
77
 
78
jQuery.fn.dataTableExt.aTypes.unshift(
79
    function (sData) {
80
        if (sData !== null && sData.match(/\d{1,2}\/\d{1,2}\/\d{2,4} \d{1,2}:\d{1,2} (am|pm|AM|PM|Am|Pm)/)) {
81
 
82
            return 'datetime-us';
83
        }
84
        return null;
85
    }
86
);