Skip to content

Commit

Permalink
fix fgelinas#20 , parse time for hours only or minutes only timepicker
Browse files Browse the repository at this point in the history
  • Loading branch information
fgelinas committed Sep 21, 2011
1 parent 9079cd5 commit d7f01c7
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 15 deletions.
3 changes: 2 additions & 1 deletion index.html
Expand Up @@ -726,7 +726,8 @@ <h2>Releases :</h2>
<dl>

<dt>0.2.6 - not released yet</dt>
<dd>Fixed a bug when input ID have more then one special char. (Thamks Jacqueline Krijnen)</dd>
<dd>Fixed a bug when input ID have more then one special char. (Thanks Jacqueline Krijnen)</dd>
<dd>Fixed a bug when parsing hours only or minutes only time. (Thanks protron, <a href="https://github.com/fgelinas/timepicker/issues/20">github issue #20</a>)</dd>

<dt>0.2.5 - September 13, 2011</dt>
<dd>Added support for disable and enable. (Suggested by danielrex, github issue #17)</dd>
Expand Down
42 changes: 28 additions & 14 deletions jquery.ui.timepicker.js
Expand Up @@ -974,24 +974,38 @@
retVal.hours = -1;
retVal.minutes = -1;

var timeSeparator = this._get(inst, 'timeSeparator');
var amPmText = this._get(inst, 'amPmText');
var p = timeVal.indexOf(timeSeparator);
if (p == -1) { return retVal; }

retVal.hours = parseInt(timeVal.substr(0, p), 10);
retVal.minutes = parseInt(timeVal.substr(p + 1), 10);
var timeSeparator = this._get(inst, 'timeSeparator'),
amPmText = this._get(inst, 'amPmText'),
showHours = this._get(inst, 'showHours'),
showMinutes = this._get(inst, 'showMinutes'),
showPeriod = (this._get(inst, 'showPeriod') == true),
p = timeVal.indexOf(timeSeparator);

var showPeriod = (this._get(inst, 'showPeriod') == true);
var timeValUpper = timeVal.toUpperCase();
if ((retVal.hours < 12) && (showPeriod) && (timeValUpper.indexOf(amPmText[1].toUpperCase()) != -1)) {
retVal.hours += 12;
// check if time separator found
if (p != -1) {
retVal.hours = parseInt(timeVal.substr(0, p), 10);
retVal.minutes = parseInt(timeVal.substr(p + 1), 10);
}
// check for hours only
else if ( (showHours) && ( ! showMinutes) ) {
retVal.hours = parseInt(timeVal, 10);
}
// fix for 12 AM
if ((retVal.hours == 12) && (showPeriod) && (timeValUpper.indexOf(amPmText[0].toUpperCase()) != -1)) {
retVal.hours = 0;
// check for minutes only
else if ( ( ! showHours) && (showMinutes) ) {
retVal.minutes = parseInt(timeVal, 10);
}

if (showHours) {
var timeValUpper = timeVal.toUpperCase();
if ((retVal.hours < 12) && (showPeriod) && (timeValUpper.indexOf(amPmText[1].toUpperCase()) != -1)) {
retVal.hours += 12;
}
// fix for 12 AM
if ((retVal.hours == 12) && (showPeriod) && (timeValUpper.indexOf(amPmText[0].toUpperCase()) != -1)) {
retVal.hours = 0;
}
}

return retVal;
},

Expand Down
1 change: 1 addition & 0 deletions releases.txt
@@ -1,5 +1,6 @@
Release 0.2.6 - Not released yet
Fixed a bug when input ID have more then one special char. (Thamks Jacqueline Krijnen)
Fixed a bug when parsing hours only or minutes only time. (Thanks protron, <a href="https://github.com/fgelinas/timepicker/issues/20">github issue #20</a>)

Release 0.2.5 - September 13, 2011
Added support for disable and enable. (Suggested by danielrex, github issue #17)
Expand Down

0 comments on commit d7f01c7

Please sign in to comment.