Skip to content
This repository was archived by the owner on Apr 17, 2022. It is now read-only.

Commit 2624aeb

Browse files
committed
fix: Time min and max proper validation
1 parent 1bf8c21 commit 2624aeb

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

src/Vue3DatePicker/components/SelectionGrid.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@
133133
const onClick = (val: string | number): void => {
134134
if (
135135
!props.disabledValues.some((value) => value === val) &&
136-
(props.minValue ? +props.minValue < val : true) &&
137-
(props.maxValue ? +props.maxValue > val : true)
136+
(props.minValue ? +props.minValue <= val : true) &&
137+
(props.maxValue ? +props.maxValue >= val : true)
138138
) {
139139
emit('update:modelValue', val);
140140
emit('selected');

src/Vue3DatePicker/components/TimePicker/TimeInput.vue

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -166,57 +166,61 @@
166166
167167
const handleHours = (type: string): void => {
168168
if (type === 'increment') {
169+
const hoursValue = addDateHours(hours.value, +props.hoursIncrement);
169170
if (props.maxTime.hours) {
170-
if (hours.value + +props.hoursIncrement > +props.maxTime.hours) {
171+
if (hoursValue > +props.maxTime.hours) {
171172
return;
172173
}
173174
}
174175
if (props.minTime.hours) {
175-
if (hours.value + +props.hoursIncrement < +props.minTime.hours) {
176+
if (hoursValue < +props.minTime.hours) {
176177
return;
177178
}
178179
}
179-
emit('update:hours', addDateHours(hours.value, +props.hoursIncrement));
180+
emit('update:hours', hoursValue);
180181
} else {
182+
const hoursValue = subDateHours(hours.value, +props.hoursIncrement);
181183
if (props.minTime.hours) {
182-
if (hours.value - +props.hoursIncrement < +props.minTime.hours) {
184+
if (hoursValue < +props.minTime.hours) {
183185
return;
184186
}
185187
}
186188
if (props.maxTime.hours) {
187-
if (hours.value - +props.hoursIncrement > +props.maxTime.hours) {
189+
if (hoursValue > +props.maxTime.hours) {
188190
return;
189191
}
190192
}
191-
emit('update:hours', subDateHours(hours.value, +props.hoursIncrement));
193+
emit('update:hours', hoursValue);
192194
}
193195
};
194196
195197
const handleMinutes = (type: string): void => {
196198
if (type === 'increment') {
199+
const minutesValue = addDateMinutes(minutes.value, +props.minutesIncrement);
197200
if (props.maxTime.minutes) {
198-
if (minutes.value + +props.minutesIncrement > +props.maxTime.minutes) {
201+
if (minutesValue > +props.maxTime.minutes || minutesValue === 0) {
199202
return;
200203
}
201204
}
202205
if (props.minTime.minutes) {
203-
if (minutes.value + +props.minutesIncrement < +props.minTime.minutes) {
206+
if (minutesValue < +props.minTime.minutes || minutesValue === 0) {
204207
return;
205208
}
206209
}
207-
emit('update:minutes', addDateMinutes(minutes.value, +props.minutesIncrement));
210+
emit('update:minutes', minutesValue);
208211
} else {
212+
const minutesValue = subDateMinutes(minutes.value, +props.minutesIncrement);
209213
if (props.minTime.minutes) {
210-
if (minutes.value - +props.minutesIncrement < +props.minTime.minutes) {
214+
if (minutesValue < +props.minTime.minutes || minutesValue === 0) {
211215
return;
212216
}
213217
}
214218
if (props.maxTime.minutes) {
215-
if (minutes.value + +props.minutesIncrement > +props.maxTime.minutes) {
219+
if (minutesValue > +props.maxTime.minutes) {
216220
return;
217221
}
218222
}
219-
emit('update:minutes', subDateMinutes(minutes.value, +props.minutesIncrement));
223+
emit('update:minutes', minutesValue);
220224
}
221225
};
222226

0 commit comments

Comments
 (0)