Debian Codegraph @

js/parsers/parser-date-extract.js

raw symbols SCIP
1 /*! Parser: Extract out date - updated 10/26/2014 (v2.18.0) */
2 /*jshint jquery:true */
3 ;(function($) {
4 'use strict';
5
6 var regex = {
7 usLong : /[A-Z]{3,10}\.?\s+\d{1,2},?\s+(?:\d{4})(?:\s+\d{1,2}:\d{2}(?::\d{2})?(?:\s+[AP]M)?)?/i,
8 mdy : /(\d{1,2}[\/\s]\d{1,2}[\/\s]\d{4}(\s+\d{1,2}:\d{2}(:\d{2})?(\s+[AP]M)?)?)/i,
9
10 dmy : /(\d{1,2}[\/\s]\d{1,2}[\/\s]\d{4}(\s+\d{1,2}:\d{2}(:\d{2})?(\s+[AP]M)?)?)/i,
11 dmyreplace : /(\d{1,2})[\/\s](\d{1,2})[\/\s](\d{4})/,
12
13 ymd : /(\d{4}[\/\s]\d{1,2}[\/\s]\d{1,2}(\s+\d{1,2}:\d{2}(:\d{2})?(\s+[AP]M)?)?)/i,
14 ymdreplace : /(\d{4})[\/\s](\d{1,2})[\/\s](\d{1,2})/
15 };
16
17 /*! extract US Long Date *//* (ignore any other text)
18 * e.g. 'Sue's Birthday! Jun 26, 2004 7:22 AM (8# 2oz)'
19 * demo: http://jsfiddle.net/Mottie/abkNM/4165/ */
20 $.tablesorter.addParser({
21 id: 'extractUSLongDate',
22 is: function () {
23 // don't auto detect this parser
24 return false;
25 },
26 format: function (s) {
27 var date,
28 str = s ? s.match(regex.usLong) : s;
29 if (str) {
30 date = new Date( str[0] );
31 return date instanceof Date && isFinite(date) ? date.getTime() : s;
32 }
33 return s;
34 },
35 type: 'numeric'
36 });
37
38 /*! extract MMDDYYYY *//* (ignore any other text)
39 * demo: http://jsfiddle.net/Mottie/abkNM/4166/ */
40 $.tablesorter.addParser({
41 id: 'extractMMDDYYYY',
42 is: function () {
43 // don't auto detect this parser
44 return false;
45 },
46 format: function (s) {
47 var date,
48 str = s ? s.replace(/\s+/g, ' ').replace(/[\-.,]/g, '/').match(regex.mdy) : s;
49 if (str) {
50 date = new Date( str[0] );
51 return date instanceof Date && isFinite(date) ? date.getTime() : s;
52 }
53 return s;
54 },
55 type: 'numeric'
56 });
57
58 /*! extract DDMMYYYY *//* (ignore any other text)
59 * demo: http://jsfiddle.net/Mottie/abkNM/4167/ */
60 $.tablesorter.addParser({
61 id: 'extractDDMMYYYY',
62 is: function () {
63 // don't auto detect this parser
64 return false;
65 },
66 format: function (s) {
67 var date,
68 str = s ? s.replace(/\s+/g, ' ').replace(/[\-.,]/g, '/').match(regex.dmy) : s;
69 if (str) {
70 date = new Date( str[0].replace(regex.dmyreplace, '$2/$1/$3') );
71 return date instanceof Date && isFinite(date) ? date.getTime() : s;
72 }
73 return s;
74 },
75 type: 'numeric'
76 });
77
78 /*! extract YYYYMMDD *//* (ignore any other text)
79 * demo: http://jsfiddle.net/Mottie/abkNM/4168/ */
80 $.tablesorter.addParser({
81 id: 'extractYYYYMMDD',
82 is: function () {
83 // don't auto detect this parser
84 return false;
85 },
86 format: function (s) {
87 var date,
88 str = s ? s.replace(/\s+/g, ' ').replace(/[\-.,]/g, '/').match(regex.ymd) : s;
89 if (str) {
90 date = new Date( str[0].replace(regex.ymdreplace, '$2/$3/$1') );
91 return date instanceof Date && isFinite(date) ? date.getTime() : s;
92 }
93 return s;
94 },
95 type: 'numeric'
96 });
97
98 })(jQuery);