Skip to content

Commit

Permalink
Tweaked maxTime option to prevent maxTime being less than minTime.
Browse files Browse the repository at this point in the history
  • Loading branch information
jonthornton committed Feb 7, 2012
1 parent 433607d commit e1984e9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
5 changes: 3 additions & 2 deletions index.html
Expand Up @@ -104,16 +104,17 @@ <h3>Scroll Default Example</h3>
<div class="example">
<script>
$(function() {
$('#durationExample').timepicker({ 'minTime': '2:00pm', 'showDuration': true });
$('#durationExample').timepicker({ 'minTime': '2:00pm', 'maxTime': '11:30pm', 'showDuration': true });
});
</script>

<h3>Duration Example</h3>
<p>Set a starting time and see duration from that starting time.</p>
<p>Set a starting time and see duration from that starting time. You can optionally set an maxTime as well.</p>
<p><input id="durationExample" type="text" class="time" /></p>

<pre class="code">$('#durationExample').timepicker({
'minTime': '2:00pm',
'maxTime': '11:30pm',
'showDuration': true
});</pre>
</div>
Expand Down
13 changes: 10 additions & 3 deletions jquery.timepicker.js
Expand Up @@ -52,7 +52,7 @@ requires jQuery 1.6+
if (settings.minTime) {
settings.minTime = _time2int(settings.minTime);
}

if (settings.maxTime) {
settings.maxTime = _time2int(settings.maxTime);
}
Expand Down Expand Up @@ -127,6 +127,8 @@ requires jQuery 1.6+
if (selected && selected.length) {
var topOffset = list.scrollTop() + selected.position().top - selected.outerHeight();
list.scrollTop(topOffset);
} else {
list.scrollTop(0);
}
},

Expand Down Expand Up @@ -160,7 +162,7 @@ requires jQuery 1.6+
if (settings.minTime) {
settings.minTime = _time2int(settings.minTime);
}

if (settings.maxTime) {
settings.maxTime = _time2int(settings.maxTime);
}
Expand Down Expand Up @@ -210,7 +212,12 @@ requires jQuery 1.6+
}

var start = (settings.minTime !== null) ? settings.minTime : 0;
var end = (settings.maxTime !== null) ? settings.maxTime : start+86340;
var end = (settings.maxTime !== null) ? settings.maxTime : start+84600;

if (end <= start) {
// make sure the end time is greater than start time, otherwise there will be no list to show
end += 86400;
}

for (var i=start; i <= end; i += settings.step*60) {
var timeInt = i%86400;
Expand Down
2 changes: 1 addition & 1 deletion jquery.timepicker.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e1984e9

Please sign in to comment.