Fixed #998 - Calendar seconds are locked when min/max set

pull/1021/head
Tuğçe Küçükoğlu 2021-02-21 14:24:58 +03:00
parent 72b79e3ef3
commit 39816eb5e5
1 changed files with 81 additions and 109 deletions

View File

@ -1079,122 +1079,123 @@ export default {
break; break;
} }
}, },
incrementHour(event) { convertTo24Hour(hours, pm) {
const prevHour = this.currentHour; if (this.hourFormat == '12') {
const newHour = this.currentHour + this.stepHour; if (hours === 12) {
return (pm ? 12 : 0);
if (this.validateHour(newHour)) { } else {
if (this.hourFormat == '24') return (pm ? hours + 12 : hours);
this.currentHour = (newHour >= 24) ? (newHour - 24) : newHour;
else if (this.hourFormat == '12') {
// Before the AM/PM break, now after
if (prevHour < 12 && newHour > 11) {
this.pm = !this.pm;
}
this.currentHour = (newHour >= 13) ? (newHour - 12) : newHour;
} }
} }
event.preventDefault(); return hours;
}, },
decrementHour(event) { validateTime(hour, minute, second, pm) {
const newHour = this.currentHour - this.stepHour;
if (this.validateHour(newHour)) {
if (this.hourFormat == '24')
this.currentHour = (newHour < 0) ? (24 + newHour) : newHour;
else if (this.hourFormat == '12') {
// If we were at noon/midnight, then switch
if (this.currentHour === 12) {
this.pm = !this.pm;
}
this.currentHour = (newHour <= 0) ? (12 + newHour) : newHour;
}
}
event.preventDefault();
},
validateHour(hour) {
let valid = true;
let value = this.modelValue; let value = this.modelValue;
const convertedHour = this.convertTo24Hour(hour, pm);
if (!this.isComparable()) { if (!this.isComparable()) {
return valid; return true;
} }
if (this.isRangeSelection()) { if (this.isRangeSelection()) {
value = this.modelValue[1] || this.modelValue[0]; value = this.modelValue[1] || this.modelValue[0];
} }
if (this.isMultipleSelection()) { if (this.isMultipleSelection()) {
value = this.modelValue[this.modelValue.length - 1]; value = this.modelValue[this.modelValue.length - 1];
} }
let valueDateString = value ? value.toDateString() : null; const valueDateString = value ? value.toDateString() : null;
if (this.minDate && valueDateString && this.minDate.toDateString() === valueDateString) { if (this.minDate && valueDateString && this.minDate.toDateString() === valueDateString) {
if (this.minDate.getHours() > hour) { if (this.minDate.getHours() > convertedHour) {
valid = false; return false;
}
if (this.minDate.getHours() === convertedHour) {
if (this.minDate.getMinutes() > minute) {
return false;
}
if (this.minDate.getMinutes() === minute) {
if (this.minDate.getSeconds() > second) {
return false;
}
}
} }
} }
if (this.maxDate && valueDateString && this.maxDate.toDateString() === valueDateString) { if (this.maxDate && valueDateString && this.maxDate.toDateString() === valueDateString) {
if (this.maxDate.getHours() < hour) { if (this.maxDate.getHours() < convertedHour) {
valid = false; return false;
}
if (this.maxDate.getHours() === convertedHour) {
if (this.maxDate.getMinutes() < minute) {
return false;
}
if (this.maxDate.getMinutes() === minute) {
if (this.maxDate.getSeconds() < second) {
return false;
}
}
} }
} }
return true;
},
incrementHour(event) {
let prevHour = this.currentHour;
let newHour = this.currentHour + this.stepHour;
let newPM = this.pm;
return valid;
if (this.hourFormat == '24')
newHour = (newHour >= 24) ? (newHour - 24) : newHour;
else if (this.hourFormat == '12') {
// Before the AM/PM break, now after
if (prevHour < 12 && newHour > 11) {
newPM= !this.pm;
}
newHour = (newHour >= 13) ? (newHour - 12) : newHour;
}
if (this.validateTime(newHour, this.currentMinute, this.currentSecond, newPM)) {
this.currentHour = newHour;
this.pm = newPM;
}
event.preventDefault();
},
decrementHour(event) {
let newHour = this.currentHour - this.stepHour;
let newPM = this.pm;
if (this.hourFormat == '24')
newHour = (newHour < 0) ? (24 + newHour) : newHour;
else if (this.hourFormat == '12') {
// If we were at noon/midnight, then switch
if (this.currentHour === 12) {
newPM = !this.pm;
}
newHour = (newHour <= 0) ? (12 + newHour) : newHour;
}
if (this.validateTime(newHour, this.currentMinute, this.currentSecond, newPM)) {
this.currentHour = newHour;
this.pm = newPM;
}
event.preventDefault();
}, },
incrementMinute(event) { incrementMinute(event) {
let newMinute = this.currentMinute + this.stepMinute; let newMinute = this.currentMinute + this.stepMinute;
if (this.validateMinute(newMinute)) { if (this.validateTime(this.currentHour, newMinute, this.currentSecond, true)) {
this.currentMinute = (newMinute > 59) ? newMinute - 60 : newMinute; this.currentMinute = (newMinute > 59) ? newMinute - 60 : newMinute;
} }
event.preventDefault(); event.preventDefault();
}, },
decrementMinute(event) { decrementMinute(event) {
let newMinute = this.currentMinute - this.stepMinute; let newMinute = this.currentMinute - this.stepMinute;
newMinute = (newMinute < 0) ? 60 + newMinute : newMinute; newMinute = (newMinute < 0) ? 60 + newMinute : newMinute;
if (this.validateMinute(newMinute)) { if (this.validateTime(this.currentHour, newMinute, this.currentSecond, true)) {
this.currentMinute = newMinute; this.currentMinute = newMinute;
} }
event.preventDefault(); event.preventDefault();
}, },
validateMinute(minute) {
let valid = true;
let value = this.modelValue;
if (!this.isComparable()) {
return valid;
}
if (this.isRangeSelection()) {
value = this.modelValue[1] || this.modelValue[0];
}
if (this.isMultipleSelection()) {
value = this.modelValue[this.modelValue.length - 1];
}
let valueDateString = value ? value.toDateString() : null;
if (this.minDate && valueDateString && this.minDate.toDateString() === valueDateString) {
if (value.getHours() == this.minDate.getHours()){
if (this.minDate.getMinutes() > minute) {
valid = false;
}
}
}
if (this.maxDate && valueDateString && this.maxDate.toDateString() === valueDateString) {
if (value.getHours() == this.maxDate.getHours()){
if (this.maxDate.getMinutes() < minute) {
valid = false;
}
}
}
return valid;
},
incrementSecond(event) { incrementSecond(event) {
let newSecond = this.currentSecond + this.stepSecond; let newSecond = this.currentSecond + this.stepSecond;
if (this.validateSecond(newSecond)) { if (this.validateTime(this.currentHour, this.currentMinute, newSecond, true)) {
this.currentSecond = (newSecond > 59) ? newSecond - 60 : newSecond; this.currentSecond = (newSecond > 59) ? newSecond - 60 : newSecond;
} }
@ -1203,41 +1204,12 @@ export default {
decrementSecond(event) { decrementSecond(event) {
let newSecond = this.currentSecond - this.stepSecond; let newSecond = this.currentSecond - this.stepSecond;
newSecond = (newSecond < 0) ? 60 + newSecond : newSecond; newSecond = (newSecond < 0) ? 60 + newSecond : newSecond;
if (this.validateSecond(newSecond)) { if (this.validateTime(this.currentHour, this.currentMinute, newSecond, true)) {
this.currentSecond = newSecond; this.currentSecond = newSecond;
} }
event.preventDefault(); event.preventDefault();
}, },
validateSecond(second) {
let valid = true;
let value = this.modelValue;
if (!this.isComparable()) {
return valid;
}
if (this.isRangeSelection()) {
value = this.modelValue[1] || this.modelValue[0];
}
if (this.isMultipleSelection()) {
value = this.modelValue[this.modelValue.length - 1];
}
let valueDateString = value ? value.toDateString() : null;
if (this.minDate && valueDateString && this.minDate.toDateString() === valueDateString) {
if (this.minDate.getSeconds() > second) {
valid = false;
}
}
if (this.maxDate && valueDateString && this.maxDate.toDateString() === valueDateString) {
if (this.maxDate.getSeconds() < second) {
valid = false;
}
}
return valid;
},
updateModelTime() { updateModelTime() {
let value = this.isComparable() ? this.modelValue : new Date(); let value = this.isComparable() ? this.modelValue : new Date();