diff options
author | Stephen Vance <steve@vance.com> | 2013-07-14 19:26:05 -0400 |
---|---|---|
committer | Stephen Vance <steve@vance.com> | 2013-07-14 19:26:05 -0400 |
commit | 6adc0778c6b6105186886e1d75d606aa79ea6ca1 (patch) | |
tree | 34f49d455423d0b238cfe4ff02b902fbca8f28a1 | |
parent | ea7babe23eda7cfdca25fa076caaefb8bd3aee6b (diff) | |
download | jQuery-Timepicker-Addon-6adc0778c6b6105186886e1d75d606aa79ea6ca1.zip jQuery-Timepicker-Addon-6adc0778c6b6105186886e1d75d606aa79ea6ca1.tar.gz jQuery-Timepicker-Addon-6adc0778c6b6105186886e1d75d606aa79ea6ca1.tar.bz2 |
I dug into the project history to figure out how to test the error path of splitDateTime() and discovered that the code that motivated the error path was replaced but the error handling it required was not removed. Error handling added to parseDate() override in commit 4496926c00b6b2caebfa93603bdcaff438294c19. Refactored to splitDateTime() in e7c7d4024db3e331003db105036667702c8e4bd8. Happy path implementation replaced in b838a211e32022f942b359c7835cd3fadb024759.
-rw-r--r-- | jquery-ui-timepicker-addon.js | 54 | ||||
-rw-r--r-- | test/jquery-ui-timepicker-addon_spec.js | 2 |
2 files changed, 15 insertions, 41 deletions
diff --git a/jquery-ui-timepicker-addon.js b/jquery-ui-timepicker-addon.js index 0e0467d..26ddf73 100644 --- a/jquery-ui-timepicker-addon.js +++ b/jquery-ui-timepicker-addon.js @@ -1833,46 +1833,22 @@ * Returns {dateString: dateString, timeString: timeString} */ var splitDateTime = function(dateFormat, dateTimeString, dateSettings, timeSettings) { - try { - // The idea is to get the number separator occurrences in datetime and the time format requested (since time has - // fewer unknowns, mostly numbers and am/pm). We will use the time pattern to split. - var separator = computeEffectiveSetting(timeSettings, 'separator'), - format = computeEffectiveSetting(timeSettings, 'timeFormat'), - timeParts = format.split(separator), // how many occurrences of separator may be in our format? - timePartsLen = timeParts.length, - allParts = dateTimeString.split(separator), - allPartsLen = allParts.length; - - if (allPartsLen > 1) { - return { - dateString: allParts.splice(0,allPartsLen-timePartsLen).join(separator), - timeString: allParts.splice(0,timePartsLen).join(separator) - }; - } - - } catch (err) { - $.timepicker.log('Could not split the date from the time. Please check the following datetimepicker options' + - "\nthrown error: " + err + - "\ndateTimeString" + dateTimeString + - "\ndateFormat = " + dateFormat + - "\nseparator = " + timeSettings.separator + - "\ntimeFormat = " + timeSettings.timeFormat); - - if (err.indexOf(":") >= 0) { - // Hack! The error message ends with a colon, a space, and - // the "extra" characters. We rely on that instead of - // attempting to perfectly reproduce the parsing algorithm. - var dateStringLength = dateTimeString.length - (err.length - err.indexOf(':') - 2); - - return { - dateString: $.trim(dateTimeString.substring(0, dateStringLength)), - timeString: $.trim(dateTimeString.substring(dateStringLength)) - }; - - } else { - throw err; - } + // The idea is to get the number separator occurrences in datetime and the time format requested (since time has + // fewer unknowns, mostly numbers and am/pm). We will use the time pattern to split. + var separator = computeEffectiveSetting(timeSettings, 'separator'), + format = computeEffectiveSetting(timeSettings, 'timeFormat'), + timeParts = format.split(separator), // how many occurrences of separator may be in our format? + timePartsLen = timeParts.length, + allParts = dateTimeString.split(separator), + allPartsLen = allParts.length; + + if (allPartsLen > 1) { + return { + dateString: allParts.splice(0,allPartsLen-timePartsLen).join(separator), + timeString: allParts.splice(0,timePartsLen).join(separator) + }; } + return { dateString: dateTimeString, timeString: '' diff --git a/test/jquery-ui-timepicker-addon_spec.js b/test/jquery-ui-timepicker-addon_spec.js index 3ddd7b6..125472d 100644 --- a/test/jquery-ui-timepicker-addon_spec.js +++ b/test/jquery-ui-timepicker-addon_spec.js @@ -263,8 +263,6 @@ describe('datetimepicker', function() { expect(result).toEqual({dateString: expectedDateString, timeString: ''}); }); - - // TODO: Should test the error path, but not sure what throws the error or what the message looks like. }); describe('parseDateTimeInternal', function() { |