|
2001 | 2001 | * @return jQuery
|
2002 | 2002 | */
|
2003 | 2003 | $.timepicker.handleRange = function(method, startTime, endTime, options) {
|
| 2004 | + options = $.extend({}, { |
| 2005 | + minInterval: 0, // min allowed interval in milliseconds |
| 2006 | + maxInterval: 0, // max allowed interval in milliseconds |
| 2007 | + start: {}, // options for start picker |
| 2008 | + end: {} // options for end picker |
| 2009 | + }, options); |
| 2010 | + |
2004 | 2011 | $.fn[method].call(startTime, $.extend({
|
2005 | 2012 | onClose: function(dateText, inst) {
|
2006 |
| - checkDates($(this), endTime, dateText); |
| 2013 | + checkDates($(this), endTime); |
2007 | 2014 | },
|
2008 | 2015 | onSelect: function(selectedDateTime) {
|
2009 | 2016 | selected($(this), endTime, 'minDate');
|
2010 | 2017 | }
|
2011 | 2018 | }, options, options.start));
|
2012 | 2019 | $.fn[method].call(endTime, $.extend({
|
2013 | 2020 | onClose: function(dateText, inst) {
|
2014 |
| - checkDates($(this), startTime, dateText); |
| 2021 | + checkDates($(this), startTime); |
2015 | 2022 | },
|
2016 | 2023 | onSelect: function(selectedDateTime) {
|
2017 | 2024 | selected($(this), startTime, 'maxDate');
|
2018 | 2025 | }
|
2019 | 2026 | }, options, options.end));
|
2020 |
| - // timepicker doesn't provide access to its 'timeFormat' option, |
2021 |
| - // nor could I get datepicker.formatTime() to behave with times, so I |
2022 |
| - // have disabled reformatting for timepicker |
2023 |
| - if (method != 'timepicker' && options.reformat) { |
2024 |
| - $([startTime, endTime]).each(function() { |
2025 |
| - var $t = $(this), |
2026 |
| - format = $t[method].call($t, 'option', 'dateFormat'), |
2027 |
| - date = new Date($t.val()); |
2028 |
| - if ($t.val() && date) { |
2029 |
| - $t.val($.datepicker.formatDate(format, date)); |
2030 |
| - } |
2031 |
| - }); |
2032 |
| - } |
2033 | 2027 |
|
2034 |
| - checkDates(startTime, endTime, startTime.val()); |
| 2028 | + checkDates(startTime, endTime); |
2035 | 2029 | selected(startTime, endTime, 'minDate');
|
2036 | 2030 | selected(endTime, startTime, 'maxDate');
|
2037 | 2031 |
|
2038 |
| - function checkDates(changed, other, dateText) { |
| 2032 | + function checkDates(changed, other) { |
2039 | 2033 | var startdt = startTime[method]('getDate'),
|
2040 |
| - enddt = endTime[method]('getDate'); |
2041 |
| - |
2042 |
| - if (other.val() && startdt > enddt) { |
2043 |
| - other.val(dateText); |
| 2034 | + enddt = endTime[method]('getDate'), |
| 2035 | + changeddt = changed[method]('getDate'); |
| 2036 | + |
| 2037 | + if(startdt !== null){ |
| 2038 | + var minDate = new Date(startdt.getTime()), |
| 2039 | + maxDate = new Date(startdt.getTime()); |
| 2040 | + |
| 2041 | + minDate.setMilliseconds(minDate.getMilliseconds() + options.minInterval); |
| 2042 | + maxDate.setMilliseconds(maxDate.getMilliseconds() + options.maxInterval); |
| 2043 | + |
| 2044 | + if(options.minInterval > 0 && minDate > enddt){ // minInterval check |
| 2045 | + endTime[method]('setDate',minDate); |
| 2046 | + } |
| 2047 | + else if(options.maxInterval > 0 && maxDate < enddt){ // max interval check |
| 2048 | + endTime[method]('setDate',maxDate); |
| 2049 | + } |
| 2050 | + else if (startdt > enddt) { |
| 2051 | + other[method]('setDate',changeddt); |
| 2052 | + } |
2044 | 2053 | }
|
2045 | 2054 | }
|
2046 | 2055 |
|
|
2049 | 2058 | return;
|
2050 | 2059 | }
|
2051 | 2060 | var date = changed[method].call(changed, 'getDate');
|
| 2061 | + if(date !== null && options.minInterval > 0){ |
| 2062 | + if(option == 'minDate'){ |
| 2063 | + date.setMilliseconds(date.getMilliseconds() + options.minInterval); |
| 2064 | + } |
| 2065 | + if(option == 'maxDate'){ |
| 2066 | + date.setMilliseconds(date.getMilliseconds() - options.minInterval); |
| 2067 | + } |
| 2068 | + } |
2052 | 2069 | if (date.getTime) {
|
2053 | 2070 | other[method].call(other, 'option', option, date);
|
2054 | 2071 | }
|
|
0 commit comments