Skip to content

Commit dcd217f

Browse files
author
Mike Patnode
committed
The current implementation of splitDateTime seems to rely upon _base_parseDate() throwing an exception, and then parsing
the results of that exception. This seems rather error prone since an exception is being used for a non-exceptional (expected) condition and the code is subject to breakage if the format of the exception message changes. But my problem was that the dateTimeString parsed just fine (even though the default date format did not include the time) so no exception was thrown, and the code would always cut off the time segment. So I added code that handles the case where _base_parseDate() doesn't throw, and just split the dateTimeString on the separator. I'd be interested to hear if I was doing something wrong which was causing parseDate() not to fail, but once again depending upon the exception to be thrown seems like trouble to me...
1 parent 428a215 commit dcd217f

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

jquery-ui-timepicker-addon.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1495,10 +1495,17 @@ function extendRemove(target, props) {
14951495
// Throws exception when date can't be parsed
14961496
// If only date is present, time substring eill be ''
14971497
//#######################################################################################
1498-
var splitDateTime = function(dateFormat, dateTimeString, dateSettings)
1498+
var splitDateTime = function(dateFormat, dateTimeString, dateSettings, timeSettings)
14991499
{
15001500
try {
15011501
var date = $.datepicker._base_parseDate(dateFormat, dateTimeString, dateSettings);
1502+
var separator = timeSettings && timeSettings.separator ? timeSettings.separator : $.timepicker._defaults.separator;
1503+
if (dateTimeString.indexOf(separator) > 0) {
1504+
var dta = dateTimeString.split(separator);
1505+
if (dta.length == 2) {
1506+
return dta;
1507+
}
1508+
}
15021509
} catch (err) {
15031510
if (err.indexOf(":") >= 0) {
15041511
// Hack! The error message ends with a colon, a space, and
@@ -1525,16 +1532,11 @@ var splitDateTime = function(dateFormat, dateTimeString, dateSettings)
15251532
var parseDateTimeInternal = function(dateFormat, timeFormat, dateTimeString, dateSettings, timeSettings)
15261533
{
15271534
var date;
1528-
var splitRes = splitDateTime(dateFormat, dateTimeString, dateSettings);
1535+
var splitRes = splitDateTime(dateFormat, dateTimeString, dateSettings, timeSettings);
15291536
date = $.datepicker._base_parseDate(dateFormat, splitRes[0], dateSettings);
15301537
if (splitRes[1] !== '')
15311538
{
15321539
var timeString = splitRes[1];
1533-
var separator = timeSettings && timeSettings.separator ? timeSettings.separator : $.timepicker._defaults.separator;
1534-
if ( timeString.indexOf(separator) !== 0) {
1535-
throw 'Missing time separator';
1536-
}
1537-
timeString = timeString.substring(separator.length);
15381540
var parsedTime = $.datepicker.parseTime(timeFormat, timeString, timeSettings);
15391541
if (parsedTime === null) {
15401542
throw 'Wrong time format';

0 commit comments

Comments
 (0)