Bugfixes for _parseDate()

This commit is contained in:
doublerebel 2010-12-05 13:54:32 -08:00
parent 27815082b5
commit e97d06e554

View file

@ -1,8 +1,8 @@
/* /*
* jQuery timepicker addon * jQuery timepicker addon
* By: Trent Richardson [http://trentrichardson.com] * By: Trent Richardson [http://trentrichardson.com]
* Version 0.9.1 * Version 0.9.1-dev
* Last Modified: 12/2/2010 * Last Modified: 12/5/2010 by Charles Phillips
* *
* Copyright 2010 Trent Richardson * Copyright 2010 Trent Richardson
* Dual licensed under the MIT and GPL licenses. * Dual licensed under the MIT and GPL licenses.
@ -148,10 +148,9 @@ $.extend(Timepicker.prototype, {
_addTimePicker: function() { _addTimePicker: function() {
var currDT = (this.$altInput) ? var currDT = (this.$altInput) ?
this.$input.val() + ' ' + this.$altInput.val() : this.$input.val() + ' ' + this.$altInput.val() :
this.$input.val(), this.$input.val();
parsedDT = this._parseTime(currDT);
this.timeDefined = (parsedDT) ? true : false; this.timeDefined = this._parseTime(currDT);
this._injectTimePicker(); this._injectTimePicker();
}, },
@ -165,9 +164,8 @@ $.extend(Timepicker.prototype, {
.replace(/s{1,2}/ig, '(\\d?\\d)') .replace(/s{1,2}/ig, '(\\d?\\d)')
.replace(/t{1,2}/ig, '(am|pm|a|p)?') .replace(/t{1,2}/ig, '(am|pm|a|p)?')
.replace(/\s/g, '\\s?') + '$', .replace(/\s/g, '\\s?') + '$',
order = this._getFormatPositions(),
treg = timeString.match(new RegExp(regstr, 'i')), treg;
order = this._getFormatPositions();
if (withDate || !this._defaults.timeOnly) { if (withDate || !this._defaults.timeOnly) {
// the time should come after x number of characters and a space. // the time should come after x number of characters and a space.
@ -176,6 +174,8 @@ $.extend(Timepicker.prototype, {
regstr = '.{' + dp_dateFormat.length + ',}\\s+' + regstr; regstr = '.{' + dp_dateFormat.length + ',}\\s+' + regstr;
} }
treg = timeString.match(new RegExp(regstr, 'i'));
if (treg) { if (treg) {
if (order.t !== -1) if (order.t !== -1)
this.ampm = ((treg[order.t] === undefined || treg[order.t].length === 0) ? this.ampm = ((treg[order.t] === undefined || treg[order.t].length === 0) ?
@ -187,12 +187,15 @@ $.extend(Timepicker.prototype, {
this.hour = 0; // 12am = 0 hour this.hour = 0; // 12am = 0 hour
else if (this.ampm == 'PM' && treg[order.h] != '12') else if (this.ampm == 'PM' && treg[order.h] != '12')
this.hour = (parseFloat(treg[order.h]) + 12).toFixed(0); // 12pm = 12 hour, any other pm = hour + 12 this.hour = (parseFloat(treg[order.h]) + 12).toFixed(0); // 12pm = 12 hour, any other pm = hour + 12
else this.hour = treg[order.h]; else this.hour = Number(treg[order.h]);
} }
if (order.m !== -1) this.minute = treg[order.m]; if (order.m !== -1) this.minute = Number(treg[order.m]);
if (order.s !== -1) this.second = treg[order.s]; if (order.s !== -1) this.second = Number(treg[order.s]);
}
return true;
} else return false;
}, },
//######################################################################## //########################################################################