when timeFormat does not have minutes #21

Closed
balint-nagy opened this Issue Mar 14, 2012 · 2 comments

Projects

None yet

2 participants

@balint-nagy

The interval shouldn't be below 60 when the timeFormat does not have minutes in it.

My patch simply checks if the timeFormat has 'mm' somewhere in it, and if not, sets the interval to 60. Could be further refined by checking if the interval is multiple of 60, then it can stay as it is, but if not then we can set it to the nearest multiple of 60.

Without this if the format has no 'mm' in it and the interval lets say is 15, then the list will contain each hour 4 times.

diff --git a/jquery.timepicker.js b/jquery.timepicker.js
old mode 100644
new mode 100755
index e969a01..68b7125
--- a/jquery.timepicker.js
+++ b/jquery.timepicker.js
@@ -627,6 +627,11 @@ if(typeof jQuery != 'undefined') {
             }

             var globals = $.extend({}, $.TimePicker.defaults, options);
+
+            // the interval should not be smaller than 60 if the timeFormat
+            // does not include minutes
+            if (!/mm/.test(globals.timeFormat))
+              globals.interval = 60;

             return this.each(function() {
                 $.TimePicker.instance().register(this, globals);
@wvega
Owner
wvega commented Mar 15, 2012

Hi @balint-nagy thank you for taking the time to send the patch. It is a nice catch and a nice fix, I like the idea. Unfortunately, I'm having a difficult time in my life right now so it may be a while before I got the time to include this in the plugin, but I will include it in the next release. Thank you.

@wvega wvega added a commit that closed this issue May 6, 2012
@wvega Set interval to the nearest multiple of 60 when time format does not …
…includes m or mm modifiers (Fixes #21)
6ccb558
@wvega wvega closed this in 6ccb558 May 6, 2012
@wvega
Owner
wvega commented May 6, 2012

Hi @balint-nagy, I just fixed the issue using your suggestions. I decided to add the code to the _items function instead of overwriting the globals object, because it is possible to change both the interval and the timeFormat after the timepickers have been initialized. Then I need to check the interval everytime the items are generated (please note the items are not generated everytime they are displayed).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment