Permalink
Browse files

Fixed bug with 2-digit hours. "10:00 AM" was being parsed as "1:00 AM".

  • Loading branch information...
1 parent 281890a commit 9de20552cf7ad0a4548af2fef78c9eb46acda2bd @ndbroadbent ndbroadbent committed Nov 16, 2011
Showing with 5 additions and 5 deletions.
  1. +5 −5 public/javascripts/calendar_date_select/format_american.js
View
10 public/javascripts/calendar_date_select/format_american.js
@@ -15,20 +15,20 @@ Date.parseFormattedString = function (string) {
// 11/1/1111 01pm
// 1/1/1111 01:11pm
// 1/1/1111 1:11pm
- var regexp = "(([0-1]?[0-9])\/[0-3]?[0-9]\/[0-9]{4}) *([0-9]{1,2}(:[0-9]{2})? *(am|pm))?";
+ var regexp = "(([0-1]?[0-9])\/[0-3]?[0-9]\/[0-9]{4}) *(([0-9]{1,2})(:[0-9]{2})? *(am|pm))?";
string = string.strip();
var d = string.match(new RegExp(regexp, "i"));
if (d==null) {
return Date.parse(string); // Give javascript a chance to parse it.
}
-
+
mdy = d[1].split('/');
hrs = 0;
mts = 0;
if(d[3] != null && d[3].strip() != "") {
- hrs = parseInt(d[3].split('')[0], 10);
- if(d[5].toLowerCase() == 'pm') { hrs += 12; } // Add 12 more to hrs
- mts = d[4].split(':')[1];
+ hrs = parseInt(d[3], 10);
+ if(d[6].toLowerCase() == 'pm') { hrs += 12; } // Add 12 more to hrs
+ mts = d[5].split(':')[1];
}
return new Date(mdy[2], parseInt(mdy[0], 10)-1, mdy[1], hrs, mts, 0);

0 comments on commit 9de2055

Please sign in to comment.