summaryrefslogtreecommitdiffstats
path: root/jquery-ui-timepicker-addon.js
diff options
context:
space:
mode:
authorTrent Richardson <trentdrichardson@gmail.com>2012-03-16 14:11:14 -0400
committerTrent Richardson <trentdrichardson@gmail.com>2012-03-16 14:11:14 -0400
commitca698f389f782927122144b8a4e3070ed78ec1aa (patch)
tree78b0ad983f1ec10b5ff4ed61238d51c126351501 /jquery-ui-timepicker-addon.js
parent5302e3e876f6c9fbba2b7c1c2121a4056c2ea690 (diff)
downloadjQuery-Timepicker-Addon-ca698f389f782927122144b8a4e3070ed78ec1aa.zip
jQuery-Timepicker-Addon-ca698f389f782927122144b8a4e3070ed78ec1aa.tar.gz
jQuery-Timepicker-Addon-ca698f389f782927122144b8a4e3070ed78ec1aa.tar.bz2
Fix time only issue within _parseTime
Diffstat (limited to 'jquery-ui-timepicker-addon.js')
-rw-r--r--jquery-ui-timepicker-addon.js192
1 files changed, 98 insertions, 94 deletions
diff --git a/jquery-ui-timepicker-addon.js b/jquery-ui-timepicker-addon.js
index d6fd250..42d1dc5 100644
--- a/jquery-ui-timepicker-addon.js
+++ b/jquery-ui-timepicker-addon.js
@@ -233,9 +233,11 @@ $.extend(Timepicker.prototype, {
// parse the time string from input value or _setTime
//########################################################################
_parseTime: function(timeString, withDate) {
+ if (!this.inst)
+ this.inst = $.datepicker._getInst(this.$input[0]);
+
if (withDate || !this._defaults.timeOnly)
{
- if (!this.inst) this.inst = $.datepicker._getInst(this.$input[0]);
var dp_dateFormat = $.datepicker._get(this.inst, 'dateFormat');
try {
var parseRes = parseDateTimeInternal(dp_dateFormat, this._defaults.timeFormat, timeString, $.datepicker._getFormatConfig(this.inst), this._defaults);
@@ -250,7 +252,8 @@ $.extend(Timepicker.prototype, {
else
{
var timeObj = $.datepicker.parseTime(this._defaults.timeFormat, timeString, this._defaults);
- $.extend(this, parseRes.timeObj);
+ if(!timeObj) return false;
+ $.extend(this, timeObj);
return true;
}
},
@@ -851,114 +854,115 @@ $.fn.extend({
});
$.datepicker.parseDateTime = function(dateFormat, timeFormat, dateTimeString, dateSettings, timeSettings) {
- var parseRes = parseDateTimeInternal(dateFormat, timeFormat, dateTimeString, dateSettings, timeSettings);
- if (parseRes.timeObj)
- {
- var t = parseRes.timeObj;
- parseRes.date.setHours(t.hour, t.minute, t.second, t.millisec);
- }
-
+ var parseRes = parseDateTimeInternal(dateFormat, timeFormat, dateTimeString, dateSettings, timeSettings);
+ if (parseRes.timeObj)
+ {
+ var t = parseRes.timeObj;
+ parseRes.date.setHours(t.hour, t.minute, t.second, t.millisec);
+ }
+
return parseRes.date;
}
$.datepicker.parseTime = function(timeFormat, timeString, options) {
-
- //########################################################################
+
+ //########################################################################
// pattern for standard and localized AM/PM markers
//########################################################################
- var getPatternAmpm = function(amNames, pmNames) {
- var markers = [];
- if (amNames)
- $.merge(markers, amNames);
- if (pmNames)
- $.merge(markers, pmNames);
- markers = $.map(markers, function(val) { return val.replace(/[.*+?|()\[\]{}\\]/g, '\\$&'); });
- return '(' + markers.join('|') + ')?';
- }
-
- //########################################################################
+ var getPatternAmpm = function(amNames, pmNames) {
+ var markers = [];
+ if (amNames)
+ $.merge(markers, amNames);
+ if (pmNames)
+ $.merge(markers, pmNames);
+ markers = $.map(markers, function(val) { return val.replace(/[.*+?|()\[\]{}\\]/g, '\\$&'); });
+ return '(' + markers.join('|') + ')?';
+ }
+
+ //########################################################################
// figure out position of time elements.. cause js cant do named captures
//########################################################################
- var getFormatPositions = function( timeFormat ) {
- var finds = timeFormat.toLowerCase().match(/(h{1,2}|m{1,2}|s{1,2}|l{1}|t{1,2}|z)/g),
- orders = { h: -1, m: -1, s: -1, l: -1, t: -1, z: -1 };
+ var getFormatPositions = function( timeFormat ) {
+ var finds = timeFormat.toLowerCase().match(/(h{1,2}|m{1,2}|s{1,2}|l{1}|t{1,2}|z)/g),
+ orders = { h: -1, m: -1, s: -1, l: -1, t: -1, z: -1 };
- if (finds)
- for (var i = 0; i < finds.length; i++)
- if (orders[finds[i].toString().charAt(0)] == -1)
- orders[finds[i].toString().charAt(0)] = i + 1;
+ if (finds)
+ for (var i = 0; i < finds.length; i++)
+ if (orders[finds[i].toString().charAt(0)] == -1)
+ orders[finds[i].toString().charAt(0)] = i + 1;
- return orders;
- }
+ return orders;
+ }
- var o = extendRemove(extendRemove({}, $.timepicker._defaults), options || {});
+ var o = extendRemove(extendRemove({}, $.timepicker._defaults), options || {});
- var regstr = '^' + timeFormat.toString()
- .replace(/h{1,2}/ig, '(\\d?\\d)')
- .replace(/m{1,2}/ig, '(\\d?\\d)')
- .replace(/s{1,2}/ig, '(\\d?\\d)')
- .replace(/l{1}/ig, '(\\d?\\d?\\d)')
- .replace(/t{1,2}/ig, getPatternAmpm(o.amNames, o.pmNames))
- .replace(/z{1}/ig, '(z|[-+]\\d\\d:?\\d\\d)?')
- .replace(/\s/g, '\\s?') + o.timeSuffix + '$',
- order = getFormatPositions(timeFormat),
- ampm = '',
- treg;
-
- treg = timeString.match(new RegExp(regstr, 'i'));
-
- var resTime = {hour: 0, minute: 0, second: 0, millisec: 0};
+ var regstr = '^' + timeFormat.toString()
+ .replace(/h{1,2}/ig, '(\\d?\\d)')
+ .replace(/m{1,2}/ig, '(\\d?\\d)')
+ .replace(/s{1,2}/ig, '(\\d?\\d)')
+ .replace(/l{1}/ig, '(\\d?\\d?\\d)')
+ .replace(/t{1,2}/ig, getPatternAmpm(o.amNames, o.pmNames))
+ .replace(/z{1}/ig, '(z|[-+]\\d\\d:?\\d\\d)?')
+ .replace(/\s/g, '\\s?') + o.timeSuffix + '$',
+ order = getFormatPositions(timeFormat),
+ ampm = '',
+ treg;
+
+ treg = timeString.match(new RegExp(regstr, 'i'));
+
+ var resTime = {hour: 0, minute: 0, second: 0, millisec: 0};
- if (treg) {
- if (order.t !== -1) {
- if (treg[order.t] === undefined || treg[order.t].length === 0) {
- ampm = '';
- resTime.ampm = '';
- } else {
- ampm = $.inArray(treg[order.t], o.amNames) !== -1 ? 'AM' : 'PM';
- resTime.ampm = o[ampm == 'AM' ? 'amNames' : 'pmNames'][0];
- }
- }
+ if (treg) {
+ if (order.t !== -1) {
+ if (treg[order.t] === undefined || treg[order.t].length === 0) {
+ ampm = '';
+ resTime.ampm = '';
+ } else {
+ ampm = $.inArray(treg[order.t], o.amNames) !== -1 ? 'AM' : 'PM';
+ resTime.ampm = o[ampm == 'AM' ? 'amNames' : 'pmNames'][0];
+ }
+ }
- if (order.h !== -1) {
- if (ampm == 'AM' && treg[order.h] == '12')
- resTime.hour = 0; // 12am = 0 hour
- else if (ampm == 'PM' && treg[order.h] != '12')
- resTime.hour = parseInt(treg[order.h],10) + 12; // 12pm = 12 hour, any other pm = hour + 12
- else resTime.hour = Number(treg[order.h]);
- }
+ if (order.h !== -1) {
+ if (ampm == 'AM' && treg[order.h] == '12')
+ resTime.hour = 0; // 12am = 0 hour
+ else if (ampm == 'PM' && treg[order.h] != '12')
+ resTime.hour = parseInt(treg[order.h],10) + 12; // 12pm = 12 hour, any other pm = hour + 12
+ else resTime.hour = Number(treg[order.h]);
+ }
- if (order.m !== -1) resTime.minute = Number(treg[order.m]);
- if (order.s !== -1) resTime.second = Number(treg[order.s]);
- if (order.l !== -1) resTime.millisec = Number(treg[order.l]);
- if (order.z !== -1 && treg[order.z] !== undefined) {
- var tz = treg[order.z].toUpperCase();
- switch (tz.length) {
- case 1: // Z
- tz = o.timezoneIso8601 ? 'Z' : '+0000';
- break;
- case 5: // +hhmm
- if (o.timezoneIso8601)
- tz = tz.substring(1) == '0000'
- ? 'Z'
- : tz.substring(0, 3) + ':' + tz.substring(3);
- break;
- case 6: // +hh:mm
- if (!o.timezoneIso8601)
- tz = tz == 'Z' || tz.substring(1) == '00:00'
- ? '+0000'
- : tz.replace(/:/, '');
- else if (tz.substring(1) == '00:00')
- tz = 'Z';
- break;
- }
- resTime.timezone = tz;
- }
+ if (order.m !== -1) resTime.minute = Number(treg[order.m]);
+ if (order.s !== -1) resTime.second = Number(treg[order.s]);
+ if (order.l !== -1) resTime.millisec = Number(treg[order.l]);
+ if (order.z !== -1 && treg[order.z] !== undefined) {
+ var tz = treg[order.z].toUpperCase();
+ switch (tz.length) {
+ case 1: // Z
+ tz = o.timezoneIso8601 ? 'Z' : '+0000';
+ break;
+ case 5: // +hhmm
+ if (o.timezoneIso8601)
+ tz = tz.substring(1) == '0000'
+ ? 'Z'
+ : tz.substring(0, 3) + ':' + tz.substring(3);
+ break;
+ case 6: // +hh:mm
+ if (!o.timezoneIso8601)
+ tz = tz == 'Z' || tz.substring(1) == '00:00'
+ ? '+0000'
+ : tz.replace(/:/, '');
+ else if (tz.substring(1) == '00:00')
+ tz = 'Z';
+ break;
+ }
+ resTime.timezone = tz;
+ }
- return resTime;
- }
- return null;
+ return resTime;
+ }
+
+ return false;
},
//########################################################################
@@ -1402,4 +1406,4 @@ var parseDateTimeInternal = function(dateFormat, timeFormat, dateTimeString, dat
$.timepicker = new Timepicker(); // singleton instance
$.timepicker.version = "1.0.1";
-})(jQuery); \ No newline at end of file
+})(jQuery);