Merge pull request #649 from HuBandiT/master

fix minTime/maxTime
This commit is contained in:
Valeriy 2018-03-21 19:23:48 +05:00 committed by GitHub
commit 7d945b6024
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 112 additions and 31 deletions

View File

@ -575,10 +575,8 @@ var datetimepickerFactory = function ($) {
maxDate: false,
minTime: false,
maxTime: false,
minDateTime: false,
disabledMinTime: false,
disabledMaxTime: false,
minDateTime: false,
maxDateTime: false,
allowTimes: [],
opened: false,
@ -1263,6 +1261,10 @@ var datetimepickerFactory = function ($) {
options.minDateTime = _xdsoft_datetime.strToDateTime(options.minDateTime).dateFormat(options.formatDate);
}
if (options.maxDateTime && /^\+(.*)$/.test(options.maxDateTime)) {
options.maxDateTime = _xdsoft_datetime.strToDateTime(options.maxDateTime).dateFormat(options.formatDate);
}
applyButton.toggle(options.showApplyButton);
month_picker
@ -1669,7 +1671,8 @@ var datetimepickerFactory = function ($) {
today = _xdsoft_datetime.now(),
maxDate = false,
minDate = false,
minDateTime = false,
minDateTime = false,
maxDateTime = false,
hDate,
day,
d,
@ -1716,6 +1719,16 @@ var datetimepickerFactory = function ($) {
minDateTime = new Date(minDateTime.getFullYear(), minDateTime.getMonth(), minDateTime.getDate(), minDateTime.getHours(), minDateTime.getMinutes(), minDateTime.getSeconds());
}
if (options.maxDateTime !== false) {
maxDateTime = _xdsoft_datetime.strToDate(options.maxDateTime);
maxDateTime = new Date(maxDateTime.getFullYear(), maxDateTime.getMonth(), maxDateTime.getDate(), maxDateTime.getHours(), maxDateTime.getMinutes(), maxDateTime.getSeconds());
}
var maxDateTimeDay;
if (maxDateTime !== false) {
maxDateTimeDay = ((maxDateTime.getFullYear() * 12) + maxDateTime.getMonth()) * 31 + maxDateTime.getDate();
}
while (i < _xdsoft_datetime.currentTime.countDaysInMonth() || start.getDay() !== options.dayOfWeekStart || _xdsoft_datetime.currentTime.getMonth() === start.getMonth()) {
classes = [];
i += 1;
@ -1747,7 +1760,8 @@ var datetimepickerFactory = function ($) {
}
}
if ((maxDate !== false && start > maxDate) || (minDateTime !== false && start < minDateTime) || (minDate !== false && start < minDate) || (customDateSettings && customDateSettings[0] === false)) {
var currentDay = ((start.getFullYear() * 12) + start.getMonth()) * 31 + start.getDate();
if ((maxDate !== false && start > maxDate) || (minDateTime !== false && start < minDateTime) || (minDate !== false && start < minDate) || (maxDateTime !== false && currentDay > maxDateTimeDay) || (customDateSettings && customDateSettings[0] === false)) {
classes.push('xdsoft_disabled');
}
@ -1824,22 +1838,45 @@ var datetimepickerFactory = function ($) {
h = '';
m = '';
var minTimeMinutesOfDay = 0;
if (options.minTime !== false) {
var t = _xdsoft_datetime.strtotime(options.minTime);
minTimeMinutesOfDay = 60 * t.getHours() + t.getMinutes();
}
var maxTimeMinutesOfDay = 24 * 60;
if (options.maxTime !== false) {
var t = _xdsoft_datetime.strtotime(options.maxTime);
maxTimeMinutesOfDay = 60 * t.getHours() + t.getMinutes();
}
if (options.minDateTime !== false) {
var t = _xdsoft_datetime.strToDateTime(options.minDateTime);
var currentDayIsMinDateTimeDay = dateHelper.formatDate(_xdsoft_datetime.currentTime, options.formatDate) === dateHelper.formatDate(t, options.formatDate);
if (currentDayIsMinDateTimeDay) {
var m = 60 * t.getHours() + t.getMinutes();
if (m > minTimeMinutesOfDay) minTimeMinutesOfDay = m;
}
}
if (options.maxDateTime !== false) {
var t = _xdsoft_datetime.strToDateTime(options.maxDateTime);
var currentDayIsMaxDateTimeDay = dateHelper.formatDate(_xdsoft_datetime.currentTime, options.formatDate) === dateHelper.formatDate(t, options.formatDate);
if (currentDayIsMaxDateTimeDay) {
var m = 60 * t.getHours() + t.getMinutes();
if (m < maxTimeMinutesOfDay) maxTimeMinutesOfDay = m;
}
}
line_time = function line_time(h, m) {
var now = _xdsoft_datetime.now(), optionDateTime, current_time,
var now = _xdsoft_datetime.now(), current_time,
isALlowTimesInit = options.allowTimes && $.isArray(options.allowTimes) && options.allowTimes.length;
now.setHours(h);
h = parseInt(now.getHours(), 10);
now.setMinutes(m);
m = parseInt(now.getMinutes(), 10);
optionDateTime = new Date(_xdsoft_datetime.currentTime);
optionDateTime.setHours(h);
optionDateTime.setMinutes(m);
classes = [];
if ((options.minDateTime !== false && options.minDateTime > optionDateTime) || (options.maxTime !== false && _xdsoft_datetime.strtotime(options.maxTime).getTime() < now.getTime()) || (options.minTime !== false && _xdsoft_datetime.strtotime(options.minTime).getTime() > now.getTime())) {
classes.push('xdsoft_disabled');
} else if ((options.minDateTime !== false && options.minDateTime > optionDateTime) || ((options.disabledMinTime !== false && now.getTime() > _xdsoft_datetime.strtotime(options.disabledMinTime).getTime()) && (options.disabledMaxTime !== false && now.getTime() < _xdsoft_datetime.strtotime(options.disabledMaxTime).getTime()))) {
classes.push('xdsoft_disabled');
} else if (input.is('[disabled]')) {
var currentMinutesOfDay = 60 * h + m;
if (input.is('[disabled]') || (currentMinutesOfDay >= maxTimeMinutesOfDay) || (currentMinutesOfDay < minTimeMinutesOfDay)) {
classes.push('xdsoft_disabled');
}
@ -1866,6 +1903,9 @@ var datetimepickerFactory = function ($) {
if (!options.allowTimes || !$.isArray(options.allowTimes) || !options.allowTimes.length) {
for (i = 0, j = 0; i < (options.hours12 ? 12 : 24); i += 1) {
for (j = 0; j < 60; j += options.step) {
var currentMinutesOfDay = i * 60 + j;
if (currentMinutesOfDay < minTimeMinutesOfDay) continue;
if (currentMinutesOfDay >= maxTimeMinutesOfDay) continue;
h = (i < 10 ? '0' : '') + i;
m = (j < 10 ? '0' : '') + j;
line_time(h, m);

File diff suppressed because one or more lines are too long

1
build/jquery.datetimepicker.min.js vendored Normal file

File diff suppressed because one or more lines are too long

View File

@ -565,10 +565,8 @@ var datetimepickerFactory = function ($) {
maxDate: false,
minTime: false,
maxTime: false,
minDateTime: false,
disabledMinTime: false,
disabledMaxTime: false,
minDateTime: false,
maxDateTime: false,
allowTimes: [],
opened: false,
@ -1255,6 +1253,10 @@ var datetimepickerFactory = function ($) {
options.minDateTime = _xdsoft_datetime.strToDateTime(options.minDateTime).dateFormat(options.formatDate);
}
if (options.maxDateTime && /^\+(.*)$/.test(options.maxDateTime)) {
options.maxDateTime = _xdsoft_datetime.strToDateTime(options.maxDateTime).dateFormat(options.formatDate);
}
applyButton.toggle(options.showApplyButton);
month_picker
@ -1661,7 +1663,8 @@ var datetimepickerFactory = function ($) {
today = _xdsoft_datetime.now(),
maxDate = false,
minDate = false,
minDateTime = false,
minDateTime = false,
maxDateTime = false,
hDate,
day,
d,
@ -1708,6 +1711,16 @@ var datetimepickerFactory = function ($) {
minDateTime = new Date(minDateTime.getFullYear(), minDateTime.getMonth(), minDateTime.getDate(), minDateTime.getHours(), minDateTime.getMinutes(), minDateTime.getSeconds());
}
if (options.maxDateTime !== false) {
maxDateTime = _xdsoft_datetime.strToDate(options.maxDateTime);
maxDateTime = new Date(maxDateTime.getFullYear(), maxDateTime.getMonth(), maxDateTime.getDate(), maxDateTime.getHours(), maxDateTime.getMinutes(), maxDateTime.getSeconds());
}
var maxDateTimeDay;
if (maxDateTime !== false) {
maxDateTimeDay = ((maxDateTime.getFullYear() * 12) + maxDateTime.getMonth()) * 31 + maxDateTime.getDate();
}
while (i < _xdsoft_datetime.currentTime.countDaysInMonth() || start.getDay() !== options.dayOfWeekStart || _xdsoft_datetime.currentTime.getMonth() === start.getMonth()) {
classes = [];
i += 1;
@ -1739,7 +1752,8 @@ var datetimepickerFactory = function ($) {
}
}
if ((maxDate !== false && start > maxDate) || (minDateTime !== false && start < minDateTime) || (minDate !== false && start < minDate) || (customDateSettings && customDateSettings[0] === false)) {
var currentDay = ((start.getFullYear() * 12) + start.getMonth()) * 31 + start.getDate();
if ((maxDate !== false && start > maxDate) || (minDateTime !== false && start < minDateTime) || (minDate !== false && start < minDate) || (maxDateTime !== false && currentDay > maxDateTimeDay) || (customDateSettings && customDateSettings[0] === false)) {
classes.push('xdsoft_disabled');
}
@ -1816,22 +1830,45 @@ var datetimepickerFactory = function ($) {
h = '';
m = '';
var minTimeMinutesOfDay = 0;
if (options.minTime !== false) {
var t = _xdsoft_datetime.strtotime(options.minTime);
minTimeMinutesOfDay = 60 * t.getHours() + t.getMinutes();
}
var maxTimeMinutesOfDay = 24 * 60;
if (options.maxTime !== false) {
var t = _xdsoft_datetime.strtotime(options.maxTime);
maxTimeMinutesOfDay = 60 * t.getHours() + t.getMinutes();
}
if (options.minDateTime !== false) {
var t = _xdsoft_datetime.strToDateTime(options.minDateTime);
var currentDayIsMinDateTimeDay = dateHelper.formatDate(_xdsoft_datetime.currentTime, options.formatDate) === dateHelper.formatDate(t, options.formatDate);
if (currentDayIsMinDateTimeDay) {
var m = 60 * t.getHours() + t.getMinutes();
if (m > minTimeMinutesOfDay) minTimeMinutesOfDay = m;
}
}
if (options.maxDateTime !== false) {
var t = _xdsoft_datetime.strToDateTime(options.maxDateTime);
var currentDayIsMaxDateTimeDay = dateHelper.formatDate(_xdsoft_datetime.currentTime, options.formatDate) === dateHelper.formatDate(t, options.formatDate);
if (currentDayIsMaxDateTimeDay) {
var m = 60 * t.getHours() + t.getMinutes();
if (m < maxTimeMinutesOfDay) maxTimeMinutesOfDay = m;
}
}
line_time = function line_time(h, m) {
var now = _xdsoft_datetime.now(), optionDateTime, current_time,
var now = _xdsoft_datetime.now(), current_time,
isALlowTimesInit = options.allowTimes && $.isArray(options.allowTimes) && options.allowTimes.length;
now.setHours(h);
h = parseInt(now.getHours(), 10);
now.setMinutes(m);
m = parseInt(now.getMinutes(), 10);
optionDateTime = new Date(_xdsoft_datetime.currentTime);
optionDateTime.setHours(h);
optionDateTime.setMinutes(m);
classes = [];
if ((options.minDateTime !== false && options.minDateTime > optionDateTime) || (options.maxTime !== false && _xdsoft_datetime.strtotime(options.maxTime).getTime() < now.getTime()) || (options.minTime !== false && _xdsoft_datetime.strtotime(options.minTime).getTime() > now.getTime())) {
classes.push('xdsoft_disabled');
} else if ((options.minDateTime !== false && options.minDateTime > optionDateTime) || ((options.disabledMinTime !== false && now.getTime() > _xdsoft_datetime.strtotime(options.disabledMinTime).getTime()) && (options.disabledMaxTime !== false && now.getTime() < _xdsoft_datetime.strtotime(options.disabledMaxTime).getTime()))) {
classes.push('xdsoft_disabled');
} else if (input.is('[disabled]')) {
var currentMinutesOfDay = 60 * h + m;
if (input.is('[disabled]') || (currentMinutesOfDay >= maxTimeMinutesOfDay) || (currentMinutesOfDay < minTimeMinutesOfDay)) {
classes.push('xdsoft_disabled');
}
@ -1858,6 +1895,9 @@ var datetimepickerFactory = function ($) {
if (!options.allowTimes || !$.isArray(options.allowTimes) || !options.allowTimes.length) {
for (i = 0, j = 0; i < (options.hours12 ? 12 : 24); i += 1) {
for (j = 0; j < 60; j += options.step) {
var currentMinutesOfDay = i * 60 + j;
if (currentMinutesOfDay < minTimeMinutesOfDay) continue;
if (currentMinutesOfDay >= maxTimeMinutesOfDay) continue;
h = (i < 10 ? '0' : '') + i;
m = (j < 10 ? '0' : '') + j;
line_time(h, m);