From d7f01c7e1d63eea2e50269e25f6ae5fc86185842 Mon Sep 17 00:00:00 2001 From: Francois Gelinas Date: Wed, 21 Sep 2011 19:48:19 -0400 Subject: [PATCH] fix #20 , parse time for hours only or minutes only timepicker --- index.html | 3 ++- jquery.ui.timepicker.js | 42 +++++++++++++++++++++++++++-------------- releases.txt | 1 + 3 files changed, 31 insertions(+), 15 deletions(-) diff --git a/index.html b/index.html index 2872379..dd5359b 100644 --- a/index.html +++ b/index.html @@ -726,7 +726,8 @@

Releases :

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 input ID have more then one special char. (Thanks Jacqueline Krijnen)
+
Fixed a bug when parsing hours only or minutes only time. (Thanks protron, github issue #20)
0.2.5 - September 13, 2011
Added support for disable and enable. (Suggested by danielrex, github issue #17)
diff --git a/jquery.ui.timepicker.js b/jquery.ui.timepicker.js index 283fdcf..0a17a7b 100644 --- a/jquery.ui.timepicker.js +++ b/jquery.ui.timepicker.js @@ -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; }, diff --git a/releases.txt b/releases.txt index f6dc1ec..aaba4a6 100644 --- a/releases.txt +++ b/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, github issue #20) Release 0.2.5 - September 13, 2011 Added support for disable and enable. (Suggested by danielrex, github issue #17)