Skip to content

Commit 6adc077

Browse files
committed
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 4496926. Refactored to splitDateTime() in e7c7d40. Happy path implementation replaced in b838a21.
1 parent ea7babe commit 6adc077

File tree

2 files changed

+15
-41
lines changed

2 files changed

+15
-41
lines changed

jquery-ui-timepicker-addon.js

Lines changed: 15 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1833,46 +1833,22 @@
18331833
* Returns {dateString: dateString, timeString: timeString}
18341834
*/
18351835
var splitDateTime = function(dateFormat, dateTimeString, dateSettings, timeSettings) {
1836-
try {
1837-
// The idea is to get the number separator occurrences in datetime and the time format requested (since time has
1838-
// fewer unknowns, mostly numbers and am/pm). We will use the time pattern to split.
1839-
var separator = computeEffectiveSetting(timeSettings, 'separator'),
1840-
format = computeEffectiveSetting(timeSettings, 'timeFormat'),
1841-
timeParts = format.split(separator), // how many occurrences of separator may be in our format?
1842-
timePartsLen = timeParts.length,
1843-
allParts = dateTimeString.split(separator),
1844-
allPartsLen = allParts.length;
1845-
1846-
if (allPartsLen > 1) {
1847-
return {
1848-
dateString: allParts.splice(0,allPartsLen-timePartsLen).join(separator),
1849-
timeString: allParts.splice(0,timePartsLen).join(separator)
1850-
};
1851-
}
1852-
1853-
} catch (err) {
1854-
$.timepicker.log('Could not split the date from the time. Please check the following datetimepicker options' +
1855-
"\nthrown error: " + err +
1856-
"\ndateTimeString" + dateTimeString +
1857-
"\ndateFormat = " + dateFormat +
1858-
"\nseparator = " + timeSettings.separator +
1859-
"\ntimeFormat = " + timeSettings.timeFormat);
1860-
1861-
if (err.indexOf(":") >= 0) {
1862-
// Hack! The error message ends with a colon, a space, and
1863-
// the "extra" characters. We rely on that instead of
1864-
// attempting to perfectly reproduce the parsing algorithm.
1865-
var dateStringLength = dateTimeString.length - (err.length - err.indexOf(':') - 2);
1866-
1867-
return {
1868-
dateString: $.trim(dateTimeString.substring(0, dateStringLength)),
1869-
timeString: $.trim(dateTimeString.substring(dateStringLength))
1870-
};
1871-
1872-
} else {
1873-
throw err;
1874-
}
1836+
// The idea is to get the number separator occurrences in datetime and the time format requested (since time has
1837+
// fewer unknowns, mostly numbers and am/pm). We will use the time pattern to split.
1838+
var separator = computeEffectiveSetting(timeSettings, 'separator'),
1839+
format = computeEffectiveSetting(timeSettings, 'timeFormat'),
1840+
timeParts = format.split(separator), // how many occurrences of separator may be in our format?
1841+
timePartsLen = timeParts.length,
1842+
allParts = dateTimeString.split(separator),
1843+
allPartsLen = allParts.length;
1844+
1845+
if (allPartsLen > 1) {
1846+
return {
1847+
dateString: allParts.splice(0,allPartsLen-timePartsLen).join(separator),
1848+
timeString: allParts.splice(0,timePartsLen).join(separator)
1849+
};
18751850
}
1851+
18761852
return {
18771853
dateString: dateTimeString,
18781854
timeString: ''

test/jquery-ui-timepicker-addon_spec.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,6 @@ describe('datetimepicker', function() {
263263

264264
expect(result).toEqual({dateString: expectedDateString, timeString: ''});
265265
});
266-
267-
// TODO: Should test the error path, but not sure what throws the error or what the message looks like.
268266
});
269267

270268
describe('parseDateTimeInternal', function() {

0 commit comments

Comments
 (0)