Skip to content

Commit e3f8fc3

Browse files
Update loose parse to try multiple formats
1 parent 113812e commit e3f8fc3

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

index.html

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -361,8 +361,8 @@ <h3>Other Options</h3>
361361
<dd><em>Default: 'strict'</em> - How to parse the time string. Two methods are provided: 'strict' which must match the timeFormat exactly, and 'loose' which uses javascript's new Date(timeString) to guess the time. You may also pass in a function(timeFormat, timeString, options) to handle the parsing yourself, returning a simple object:
362362
<pre>{
363363
hour: 19,
364-
minutes: 10,
365-
seconds: 23,
364+
minute: 10,
365+
second: 23,
366366
millisec: 45,
367367
timezone: '-0400'
368368
}</pre>
@@ -525,7 +525,8 @@ <h3 id="basic_examples">Basic Initializations</h3>
525525
</div>
526526
<pre>
527527
$('#basic_example_3').datetimepicker({
528-
timeFormat: "hh:mm tt"
528+
timeFormat: "hh:mm tt",
529+
parse: 'loose'
529530
});
530531
</pre>
531532
</div>

jquery-ui-timepicker-addon.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,11 +1132,21 @@
11321132
// First try JS Date, if that fails, use strictParse
11331133
var looseParse = function(f,s,o){
11341134
try{
1135-
var d = new Date('2012-01-01T'+ s);
1135+
var d = new Date('2012-01-01 '+ s);
1136+
if(isNaN(d.getTime())){
1137+
d = new Date('2012-01-01T'+ s);
1138+
if(isNaN(d.getTime())){
1139+
d = new Date('01/01/2012 '+ s);
1140+
if(isNaN(d.getTime())){
1141+
throw "Unable to parse time with native Date: "+ s;
1142+
}
1143+
}
1144+
}
1145+
11361146
return {
11371147
hour: d.getHours(),
1138-
minutes: d.getMinutes(),
1139-
seconds: d.getSeconds(),
1148+
minute: d.getMinutes(),
1149+
second: d.getSeconds(),
11401150
millisec: d.getMilliseconds(),
11411151
timezone: $.timepicker.timeZoneOffsetString(d)
11421152
};

0 commit comments

Comments
 (0)