diff options
-rw-r--r-- | index.html | 7 | ||||
-rw-r--r-- | jquery-ui-timepicker-addon.js | 16 |
2 files changed, 17 insertions, 6 deletions
@@ -361,8 +361,8 @@ <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: <pre>{ hour: 19, - minutes: 10, - seconds: 23, + minute: 10, + second: 23, millisec: 45, timezone: '-0400' }</pre> @@ -525,7 +525,8 @@ $('#basic_example_2').timepicker(); </div> <pre> $('#basic_example_3').datetimepicker({ - timeFormat: "hh:mm tt" + timeFormat: "hh:mm tt", + parse: 'loose' }); </pre> </div> diff --git a/jquery-ui-timepicker-addon.js b/jquery-ui-timepicker-addon.js index 5916431..648af36 100644 --- a/jquery-ui-timepicker-addon.js +++ b/jquery-ui-timepicker-addon.js @@ -1132,11 +1132,21 @@ // First try JS Date, if that fails, use strictParse var looseParse = function(f,s,o){ try{ - var d = new Date('2012-01-01T'+ s); + var d = new Date('2012-01-01 '+ s); + if(isNaN(d.getTime())){ + d = new Date('2012-01-01T'+ s); + if(isNaN(d.getTime())){ + d = new Date('01/01/2012 '+ s); + if(isNaN(d.getTime())){ + throw "Unable to parse time with native Date: "+ s; + } + } + } + return { hour: d.getHours(), - minutes: d.getMinutes(), - seconds: d.getSeconds(), + minute: d.getMinutes(), + second: d.getSeconds(), millisec: d.getMilliseconds(), timezone: $.timepicker.timeZoneOffsetString(d) }; |