fix minTime/maxTime; improvement: timebox only contains time lines between minTime <= x < maxTime

This commit is contained in:
HuBandiT 2018-03-07 21:24:53 +01:00
parent a530a454a3
commit 9eba6ad646
3 changed files with 35 additions and 5 deletions

View File

@ -1824,6 +1824,17 @@ 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();
}
line_time = function line_time(h, m) {
var now = _xdsoft_datetime.now(), optionDateTime, current_time,
isALlowTimesInit = options.allowTimes && $.isArray(options.allowTimes) && options.allowTimes.length;
@ -1835,7 +1846,8 @@ var datetimepickerFactory = function ($) {
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())) {
var currentMinutesOfDay = 60 * h + m;
if ((options.minDateTime !== false && options.minDateTime > optionDateTime) || (currentMinutesOfDay >= maxTimeMinutesOfDay) || (currentMinutesOfDay < minTimeMinutesOfDay)) {
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');
@ -1866,6 +1878,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

View File

@ -1814,6 +1814,17 @@ 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();
}
line_time = function line_time(h, m) {
var now = _xdsoft_datetime.now(), optionDateTime, current_time,
isALlowTimesInit = options.allowTimes && $.isArray(options.allowTimes) && options.allowTimes.length;
@ -1825,7 +1836,8 @@ var datetimepickerFactory = function ($) {
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())) {
var currentMinutesOfDay = 60 * h + m;
if ((options.minDateTime !== false && options.minDateTime > optionDateTime) || (currentMinutesOfDay >= maxTimeMinutesOfDay) || (currentMinutesOfDay < minTimeMinutesOfDay)) {
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');
@ -1856,6 +1868,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);