diff --git a/src/components/ModalSelectDate.vue b/src/components/ModalSelectDate.vue index 2650b185357..61bfab329ea 100644 --- a/src/components/ModalSelectDate.vue +++ b/src/components/ModalSelectDate.vue @@ -11,6 +11,16 @@ const { open } = toRefs(props); const step = ref(0); const input = ref(''); const time = ref('12:00'); +const isTimeValid = computed(() => { + const isTimeEnteringStep = step.value === 1; + if (!isTimeEnteringStep) return true; + if (!input.value) return false; + + const startDateString = `${input.value} ${time.value}:59`; + const startTimestamp = new Date(startDateString).getTime(); + + return startTimestamp >= Date.now(); +}); function formatDate(date) { const output = { h: '12', m: '00', dateString: '' }; @@ -28,7 +38,8 @@ function handleSubmit() { if (step.value === 0) return (step.value = 1); const dateString = `${input.value} ${time.value}:00`; const timestamp = new Date(dateString).getTime() / 1000; - emit('input', timestamp); + const now = parseInt((Date.now() / 1e3).toFixed()); + emit('input', Math.max(timestamp, now)); emit('close'); } @@ -39,6 +50,17 @@ watch(open, () => { time.value = `${h}:${m}`; input.value = dateString; }); + +watch(step, () => { + if (step.value === 0) return; + const timestamp = Math.max( + props.value, + parseInt((Date.now() / 1e3 + 10).toFixed()) + ); + const { dateString, h, m } = formatDate(timestamp); + time.value = `${h}:${m}`; + input.value = dateString; +});