Skip to content

Commit dddb3c3

Browse files
Issue trentrichardson#466 - Bernosek, imporoves literal support
1 parent f00868a commit dddb3c3

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

index.html

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,7 @@ <h2>Formatting Your Time</h2>
368368
<dt>tt</dt><dd>am or pm for AM/PM</dd>
369369
<dt>TT</dt><dd>AM or PM for AM/PM</dd>
370370
<dt>z</dt><dd>Timezone as defined by timezoneList</dd>
371+
<dt>'...'</dt><dd>Literal text (Uses single quotes)</dd>
371372
</dl>
372373

373374
<p>Formats are used in the following ways:</p>
@@ -377,6 +378,8 @@ <h2>Formatting Your Time</h2>
377378
<li>$.datepicker.formatTime(format, timeObj, options) utility method</li>
378379
<li>$.datepicker.parseTime(format, timeStr, options) utility method</li>
379380
</ul>
381+
382+
<p>For help with formatting the date portion, visit the datepicker documentation for <a href="http://docs.jquery.com/UI/Datepicker/formatDate" title="jQuery UI Datepicker Formatting">formatting dates</a>.</p>
380383
</div>
381384

382385
<!-- ############################################################################# -->
@@ -437,7 +440,8 @@ <h2>Working with Localizations</h2>
437440
timeFormat: 'hh:mm tt',
438441
amNames: ['AM', 'A'],
439442
pmNames: ['PM', 'P'],
440-
ampm: false
443+
ampm: false,
444+
isRTL: false
441445
};
442446
$.timepicker.setDefaults($.timepicker.regional['ru']);
443447
</pre>
@@ -493,7 +497,7 @@ <h3 id="basic_examples">Basic Initializations</h3>
493497
</div>
494498
<pre>
495499
$('#basic_example_3').datetimepicker({
496-
timeFormat: "h:m",
500+
timeFormat: "h:m t",
497501
ampm: true
498502
});
499503
</pre>

jquery-ui-timepicker-addon.js

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -997,7 +997,7 @@
997997

998998
// figure out position of time elements.. cause js cant do named captures
999999
var getFormatPositions = function(timeFormat) {
1000-
var finds = timeFormat.toLowerCase().match(/(h{1,2}|m{1,2}|s{1,2}|l{1}|t{1,2}|z)/g),
1000+
var finds = timeFormat.toLowerCase().match(/(h{1,2}|m{1,2}|s{1,2}|l{1}|t{1,2}|z|'.*?')/g),
10011001
orders = {
10021002
h: -1,
10031003
m: -1,
@@ -1020,14 +1020,20 @@
10201020
var o = extendRemove(extendRemove({}, $.timepicker._defaults), options || {});
10211021

10221022
var regstr = '^' + timeFormat.toString()
1023-
.replace(/h{1,2}/ig, '(\\d?\\d)')
1024-
.replace(/m{1,2}/ig, '(\\d?\\d)')
1025-
.replace(/s{1,2}/ig, '(\\d?\\d)')
1026-
.replace(/l{1}/ig, '(\\d?\\d?\\d)')
1027-
.replace(/t{1,2}/ig, getPatternAmpm(o.amNames, o.pmNames))
1028-
.replace(/z{1}/ig, '(z|[-+]\\d\\d:?\\d\\d|\\S+)?')
1029-
.replace(/\s/g, '\\s?') +
1030-
o.timeSuffix + '$',
1023+
.replace(/(hh?|mm?|ss?|[tT]{1,2}|[lz]|'.*?')/g, function (match) {
1024+
switch (match.charAt(0).toLowerCase()) {
1025+
case 'h': return '(\\d?\\d)';
1026+
case 'm': return '(\\d?\\d)';
1027+
case 's': return '(\\d?\\d)';
1028+
case 'l': return '(\\d?\\d?\\d)';
1029+
case 'z': return '(z|[-+]\\d\\d:?\\d\\d|\\S+)?';
1030+
case 't': return getPatternAmpm(o.amNames, o.pmNames);
1031+
default: // literal escaped in quotes
1032+
return '(' + match.replace(/\'/g, "").replace(/(\.|\$|\^|\\|\/|\(|\)|\[|\]|\?|\+|\*)/g, function (m) { return "\\" + m; }) + ')?';
1033+
}
1034+
})
1035+
.replace(/\s/g, '\\s?') +
1036+
o.timeSuffix + '$',
10311037
order = getFormatPositions(timeFormat),
10321038
ampm = '',
10331039
treg;

0 commit comments

Comments
 (0)