Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

minHour and maxHour #2327

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion daterangepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
// Browser globals
root.daterangepicker = factory(root.moment, root.jQuery);
}
}(typeof window !== 'undefined' ? window : this, function(moment, $) {
}(this, function(moment, $) {
var DateRangePicker = function(element, options, cb) {

//default settings for options
Expand All @@ -54,6 +54,8 @@
this.linkedCalendars = true;
this.autoUpdateInput = true;
this.alwaysShowCalendars = false;
this.minHour = null;
this.maxHour = null;
this.ranges = {};

this.opens = 'right';
Expand Down Expand Up @@ -260,6 +262,12 @@
if (typeof options.timePicker24Hour === 'boolean')
this.timePicker24Hour = options.timePicker24Hour;

if (typeof options.minHour === 'number')
this.minHour = options.minHour;

if (typeof options.maxHour === 'number')
this.maxHour = options.maxHour;

if (typeof options.autoApply === 'boolean')
this.autoApply = options.autoApply;

Expand Down Expand Up @@ -902,6 +910,7 @@

var start = this.timePicker24Hour ? 0 : 1;
var end = this.timePicker24Hour ? 23 : 12;
var limitHour = ((this.minHour || this.maxHour) && this.timePicker24Hour) || false;

for (var i = start; i <= end; i++) {
var i_in_24 = i;
Expand All @@ -910,6 +919,15 @@

var time = selected.clone().hour(i_in_24);
var disabled = false;

if (limitHour) {
if (this.minHour && i_in_24 < this.minHour)
disabled = true;

if (this.maxHour && i_in_24 > this.maxHour)
disabled = true;
}

if (minDate && time.minute(59).isBefore(minDate))
disabled = true;
if (maxDate && time.minute(0).isAfter(maxDate))
Expand Down