Changed _formatTime method to optionally take arguments and return a formatted time string
This commit is contained in:
parent
749e97b72a
commit
c56e17047e
40
jquery-ui-timepicker-addon.js
vendored
40
jquery-ui-timepicker-addon.js
vendored
|
@ -466,36 +466,34 @@ $.extend(Timepicker.prototype, {
|
||||||
//########################################################################
|
//########################################################################
|
||||||
// format the time all pretty...
|
// format the time all pretty...
|
||||||
//########################################################################
|
//########################################################################
|
||||||
_formatTime: function() {
|
_formatTime: function(time, format, ampm) {
|
||||||
var tmptime = this._defaults.timeFormat.toString(),
|
if (ampm == undefined) ampm = this._defaults.ampm;
|
||||||
hour12 = ((this.ampm == 'AM') ? (this.hour) : (this.hour % 12));
|
time = time || { hour: this.hour, minute: this.minute, second: this.second, ampm: this.ampm };
|
||||||
hour12 = (Number(hour12) === 0) ? 12 : hour12;
|
var tmptime = format || this._defaults.timeFormat.toString();
|
||||||
|
|
||||||
if (this._defaults.ampm === true) {
|
if (ampm) {
|
||||||
|
var hour12 = ((time.ampm == 'AM') ? (time.hour) : (time.hour % 12));
|
||||||
|
hour12 = (Number(hour12) === 0) ? 12 : hour12;
|
||||||
tmptime = tmptime.toString()
|
tmptime = tmptime.toString()
|
||||||
.replace(/hh/g, ((hour12 < 10) ? '0' : '') + hour12)
|
.replace(/hh/g, ((hour12 < 10) ? '0' : '') + hour12)
|
||||||
.replace(/h/g, hour12)
|
.replace(/h/g, hour12)
|
||||||
.replace(/mm/g, ((this.minute < 10) ? '0' : '') + this.minute)
|
.replace(/TT/g, time.ampm.toUpperCase())
|
||||||
.replace(/m/g, this.minute)
|
.replace(/tt/g, time.ampm.toLowerCase())
|
||||||
.replace(/ss/g, ((this.second < 10) ? '0' : '') + this.second)
|
.replace(/T/g, time.ampm.charAt(0).toUpperCase())
|
||||||
.replace(/s/g, this.second)
|
.replace(/t/g, time.ampm.charAt(0).toLowerCase());
|
||||||
.replace(/TT/g, this.ampm.toUpperCase())
|
|
||||||
.replace(/tt/g, this.ampm.toLowerCase())
|
|
||||||
.replace(/T/g, this.ampm.charAt(0).toUpperCase())
|
|
||||||
.replace(/t/g, this.ampm.charAt(0).toLowerCase());
|
|
||||||
} else {
|
} else {
|
||||||
tmptime = tmptime.toString()
|
tmptime = tmptime.toString()
|
||||||
.replace(/hh/g, ((this.hour < 10) ? '0' : '') + this.hour)
|
.replace(/hh/g, ((time.hour < 10) ? '0' : '') + time.hour)
|
||||||
.replace(/h/g, this.hour)
|
.replace(/h/g, time.hour)
|
||||||
.replace(/mm/g, ((this.minute < 10) ? '0' : '') + this.minute)
|
|
||||||
.replace(/m/g, this.minute)
|
|
||||||
.replace(/ss/g, ((this.second < 10) ? '0' : '') + this.second)
|
|
||||||
.replace(/s/g, this.second);
|
|
||||||
tmptime = $.trim(tmptime.replace(/t/gi, ''));
|
tmptime = $.trim(tmptime.replace(/t/gi, ''));
|
||||||
}
|
}
|
||||||
|
tmptime = tmptime.replace(/mm/g, ((time.minute < 10) ? '0' : '') + time.minute)
|
||||||
|
.replace(/m/g, time.minute)
|
||||||
|
.replace(/ss/g, ((time.second < 10) ? '0' : '') + time.second)
|
||||||
|
.replace(/s/g, time.second);
|
||||||
|
|
||||||
this.formattedTime = tmptime;
|
if (arguments.length) return tmptime;
|
||||||
return this.formattedTime;
|
else this.formattedTime = tmptime;
|
||||||
},
|
},
|
||||||
|
|
||||||
//########################################################################
|
//########################################################################
|
||||||
|
|
Loading…
Reference in a new issue