From bdfad2e332ec9211bfcb4b79f247182a8d1da774 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Tue, 7 Jul 2020 09:21:00 +0200 Subject: [PATCH] Only restrict event time picker times when same day Otherwise it was getting tricky to change time for a different date Signed-off-by: Thomas Citharel --- js/src/components/Event/DateTimePicker.vue | 26 ++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/js/src/components/Event/DateTimePicker.vue b/js/src/components/Event/DateTimePicker.vue index 93a8604bb..d20fac8eb 100644 --- a/js/src/components/Event/DateTimePicker.vue +++ b/js/src/components/Event/DateTimePicker.vue @@ -34,8 +34,8 @@ placeholder="Type or select a time..." icon="clock" v-model="dateWithTime" - :min-time="minDatetime" - :max-time="maxDatetime" + :min-time="minTime" + :max-time="maxTime" size="is-small" inline > @@ -100,6 +100,28 @@ export default class DateTimePicker extends Vue { */ this.$emit("input", this.dateWithTime); } + + get minTime(): Date | null { + if (this.minDatetime && this.datesAreOnSameDay(this.dateWithTime, this.minDatetime)) { + return this.minDatetime; + } + return null; + } + + get maxTime(): Date | null { + if (this.maxDatetime && this.datesAreOnSameDay(this.dateWithTime, this.maxDatetime)) { + return this.maxDatetime; + } + return null; + } + + private datesAreOnSameDay(first: Date, second: Date): boolean { + return ( + first.getFullYear() === second.getFullYear() && + first.getMonth() === second.getMonth() && + first.getDate() === second.getDate() + ); + } }