Skip to content

Commit 4ecca3c

Browse files
Fix parse issue
1 parent bb58ecf commit 4ecca3c

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

index.html

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -599,8 +599,8 @@ <h3 id="alt_examples">Alternate Fields</h3>
599599
<div class="example-container">
600600
<p>Alt field in the simplest form:</p>
601601
<div>
602-
<input type="text" name="alt_example_1" id="alt_example_1" value="" />
603-
<input type="text" name="alt_example_1_alt" id="alt_example_1_alt" value="" />
602+
<input type="text" name="alt_example_1" id="alt_example_1" value="09/15/2012" />
603+
<input type="text" name="alt_example_1_alt" id="alt_example_1_alt" value="10:15" />
604604
</div>
605605
<pre>
606606
$('#alt_example_1').datetimepicker({
@@ -736,11 +736,12 @@ <h3 id="rest_examples">Time Restraints</h3>
736736

737737

738738
<h3 id="utility_examples">Utilities</h3>
739+
739740
<!-- ============= example -->
740741
<div class="example-container">
741742
<p>Get and Set Datetime:</p>
742743
<div>
743-
<input type="text" name="utility_example_1" id="utility_example_1" value="08/25/2012 08:41 pm" />
744+
<input type="text" name="utility_example_1" id="utility_example_1" value="" />
744745
<button id="utility_example_1_setdt" value="1">Set Datetime</button>
745746
<button id="utility_example_1_getdt" value="1">Get Datetime</button>
746747
</div>
@@ -749,6 +750,8 @@ <h3 id="utility_examples">Utilities</h3>
749750
var ex13 = $('#utility_example_1');
750751

751752
ex13.datetimepicker({
753+
dateFormat: "D MM d, yy",
754+
separator: ' @ ',
752755
ampm: true
753756
});
754757

jquery-ui-timepicker-addon.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1426,7 +1426,7 @@
14261426
var tp_inst = this._get(inst, 'timepicker');
14271427

14281428
if (tp_inst) {
1429-
this._setDateFromField(inst, noDefault);
1429+
//this._setDateFromField(inst, noDefault); // This keeps setting to today when it shouldn't
14301430
var date = this._getDate(inst);
14311431
if (date && tp_inst._parseTime($(target).val(), tp_inst.timeOnly)) {
14321432
date.setHours(tp_inst.hour, tp_inst.minute, tp_inst.second, tp_inst.millisec);
@@ -1548,17 +1548,26 @@
15481548
/*
15491549
* Splits datetime string into date ans time substrings.
15501550
* Throws exception when date can't be parsed
1551-
* If only date is present, time substring eill be ''
1551+
* Returns [dateString, timeString]
15521552
*/
15531553
var splitDateTime = function(dateFormat, dateTimeString, dateSettings, timeSettings) {
15541554
try {
1555+
// The idea is to get the number separator occurances in datetime and the time format requested (since time has
1556+
// fewer unknowns, mostly numbers and am/pm). We will use the time pattern to split.
15551557
var separator = timeSettings && timeSettings.separator ? timeSettings.separator : $.timepicker._defaults.separator,
15561558
format = timeSettings && timeSettings.timeFormat ? timeSettings.timeFormat : $.timepicker._defaults.timeFormat,
1559+
ampm = timeSettings && timeSettings.ampm ? timeSettings.ampm : $.timepicker._defaults.ampm,
15571560
timeParts = format.split(separator), // how many occurances of separator may be in our format?
15581561
timePartsLen = timeParts.length,
15591562
allParts = dateTimeString.split(separator),
15601563
allPartsLen = allParts.length;
15611564

1565+
// because our default ampm=false, but our default format has tt, we need to filter this out
1566+
if(!ampm){
1567+
timeParts = $.trim(format.replace(/t/gi,'')).split(separator);
1568+
timePartsLen = timeParts.length;
1569+
}
1570+
15621571
if (allPartsLen > 0) {
15631572
return [
15641573
allParts.splice(0,allPartsLen-timePartsLen).join(separator),

0 commit comments

Comments
 (0)