3 var timeParsePatterns = [
7 handler: function(bits) {
8 if (bits[0].length === 1) {
9 return '0' + bits[0] + ':00';
11 return bits[0] + ':00';
17 re: /^\d{2}[:.]\d{2}$/i,
18 handler: function(bits) {
19 return bits[0].replace('.', ':');
25 handler: function(bits) {
26 return '0' + bits[0].replace('.', ':');
29 // 3 am / 3 a.m. / 3am
31 re: /^(\d+)\s*([ap])(?:.?m.?)?$/i,
32 handler: function(bits) {
33 var hour = parseInt(bits[1]);
37 if (bits[2].toLowerCase() === 'p') {
41 return (hour + 12) + ':00';
44 return '0' + hour + ':00';
51 // 3.30 am / 3:15 a.m. / 3.00am
53 re: /^(\d+)[.:](\d{2})\s*([ap]).?m.?$/i,
54 handler: function(bits) {
55 var hour = parseInt(bits[1]);
56 var mins = parseInt(bits[2]);
63 if (bits[3].toLowerCase() === 'p') {
67 return (hour + 12) + ':' + mins;
70 return '0' + hour + ':' + mins;
72 return hour + ':' + mins;
80 handler: function(bits) {
87 handler: function(bits) {
93 function parseTimeString(s) {
94 for (var i = 0; i < timeParsePatterns.length; i++) {
95 var re = timeParsePatterns[i].re;
96 var handler = timeParsePatterns[i].handler;
97 var bits = re.exec(s);
105 window.parseTimeString = parseTimeString;