summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--index.html9
-rw-r--r--jquery-ui-timepicker-addon.js13
2 files changed, 17 insertions, 5 deletions
diff --git a/index.html b/index.html
index 71c7da1..9d49bfb 100644
--- a/index.html
+++ b/index.html
@@ -599,8 +599,8 @@ $('#slider_example_3').datetimepicker({
<div class="example-container">
<p>Alt field in the simplest form:</p>
<div>
- <input type="text" name="alt_example_1" id="alt_example_1" value="" />
- <input type="text" name="alt_example_1_alt" id="alt_example_1_alt" value="" />
+ <input type="text" name="alt_example_1" id="alt_example_1" value="09/15/2012" />
+ <input type="text" name="alt_example_1_alt" id="alt_example_1_alt" value="10:15" />
</div>
<pre>
$('#alt_example_1').datetimepicker({
@@ -736,11 +736,12 @@ endDateTextBox.datetimepicker({
<h3 id="utility_examples">Utilities</h3>
+
<!-- ============= example -->
<div class="example-container">
<p>Get and Set Datetime:</p>
<div>
- <input type="text" name="utility_example_1" id="utility_example_1" value="08/25/2012 08:41 pm" />
+ <input type="text" name="utility_example_1" id="utility_example_1" value="" />
<button id="utility_example_1_setdt" value="1">Set Datetime</button>
<button id="utility_example_1_getdt" value="1">Get Datetime</button>
</div>
@@ -749,6 +750,8 @@ endDateTextBox.datetimepicker({
var ex13 = $('#utility_example_1');
ex13.datetimepicker({
+ dateFormat: "D MM d, yy",
+ separator: ' @ ',
ampm: true
});
diff --git a/jquery-ui-timepicker-addon.js b/jquery-ui-timepicker-addon.js
index 9c2855d..fef220e 100644
--- a/jquery-ui-timepicker-addon.js
+++ b/jquery-ui-timepicker-addon.js
@@ -1426,7 +1426,7 @@
var tp_inst = this._get(inst, 'timepicker');
if (tp_inst) {
- this._setDateFromField(inst, noDefault);
+ //this._setDateFromField(inst, noDefault); // This keeps setting to today when it shouldn't
var date = this._getDate(inst);
if (date && tp_inst._parseTime($(target).val(), tp_inst.timeOnly)) {
date.setHours(tp_inst.hour, tp_inst.minute, tp_inst.second, tp_inst.millisec);
@@ -1548,17 +1548,26 @@
/*
* Splits datetime string into date ans time substrings.
* Throws exception when date can't be parsed
- * If only date is present, time substring eill be ''
+ * Returns [dateString, timeString]
*/
var splitDateTime = function(dateFormat, dateTimeString, dateSettings, timeSettings) {
try {
+ // The idea is to get the number separator occurances 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 = timeSettings && timeSettings.separator ? timeSettings.separator : $.timepicker._defaults.separator,
format = timeSettings && timeSettings.timeFormat ? timeSettings.timeFormat : $.timepicker._defaults.timeFormat,
+ ampm = timeSettings && timeSettings.ampm ? timeSettings.ampm : $.timepicker._defaults.ampm,
timeParts = format.split(separator), // how many occurances of separator may be in our format?
timePartsLen = timeParts.length,
allParts = dateTimeString.split(separator),
allPartsLen = allParts.length;
+ // because our default ampm=false, but our default format has tt, we need to filter this out
+ if(!ampm){
+ timeParts = $.trim(format.replace(/t/gi,'')).split(separator);
+ timePartsLen = timeParts.length;
+ }
+
if (allPartsLen > 0) {
return [
allParts.splice(0,allPartsLen-timePartsLen).join(separator),