diff --git a/src/components/date/datepickerWithRange.vue b/src/components/date/datepickerWithRange.vue index 5fbb7e24..fb812733 100644 --- a/src/components/date/datepickerWithRange.vue +++ b/src/components/date/datepickerWithRange.vue @@ -4,13 +4,25 @@ + + + - + @@ -45,7 +57,7 @@ const flatPickerConfig = computed(() => ({ mode: 'range', /*locale: { // FIXME: This seems to always contain the default value - that breaks the picker - firstDayOfWeek: weekStart, + firstDayOf7Days: weekStart, },*/ })) @@ -75,21 +87,89 @@ function formatDate(date: Date): string { return format(date, 'yyyy-MM-dd HH:mm') } +function startOfDay(date: Date): Date { + date.setHours(0) + date.setMinutes(0) + + return date +} + +function endOfDay(date: Date): Date { + date.setHours(23) + date.setMinutes(59) + + return date +} + const datesToday = computed(() => { - const startDate = new Date() - const endDate = new Date((new Date()).setDate((new Date()).getDate() + 1)) + const startDate = startOfDay(new Date()) + const endDate = endOfDay(new Date()) + + return `${formatDate(startDate)} to ${formatDate(endDate)}` +}) + +function thisWeek() { + const startDate = startOfDay(new Date()) + const first = startDate.getDate() - startDate.getDay() + startDate.setDate(first) + const endDate = endOfDay(new Date((new Date(startDate).setDate(first + 6)))) + + return { + startDate, + endDate, + } +} + +const datesThisWeek = computed(() => { + const {startDate, endDate} = thisWeek() + return `${formatDate(startDate)} to ${formatDate(endDate)}` }) const datesNextWeek = computed(() => { - const startDate = new Date() - const endDate = new Date((new Date()).getTime() + 7 * 24 * 60 * 60 * 1000) + const {startDate, endDate} = thisWeek() + startDate.setDate(startDate.getDate() + 7) + endDate.setDate(endDate.getDate() + 7) + + return `${formatDate(startDate)} to ${formatDate(endDate)}` +}) + +const datesNext7Days = computed(() => { + const startDate = startOfDay(new Date()) + const endDate = endOfDay(new Date((new Date()).getTime() + 7 * 24 * 60 * 60 * 1000)) + return `${formatDate(startDate)} to ${formatDate(endDate)}` +}) + +function thisMonth() { + const startDate = startOfDay(new Date()) + startDate.setDate(1) + const endDate = endOfDay(new Date((new Date()).getFullYear(), (new Date()).getMonth() + 1, 0)) + + return { + startDate, + endDate, + } +} + +const datesThisMonth = computed(() => { + const {startDate, endDate} = thisMonth() + return `${formatDate(startDate)} to ${formatDate(endDate)}` }) const datesNextMonth = computed(() => { - const startDate = new Date() - const endDate = new Date((new Date()).setMonth((new Date()).getMonth() + 1)) + const {startDate, endDate} = thisMonth() + + startDate.setMonth(startDate.getMonth() + 1) + endDate.setMonth(endDate.getMonth() + 1) + + return `${formatDate(startDate)} to ${formatDate(endDate)}` +}) + +const datesNext30Days = computed(() => { + const startDate = startOfDay(new Date()) + const endDate = endOfDay(new Date((new Date()).setMonth((new Date()).getMonth() + 1))) + return `${formatDate(startDate)} to ${formatDate(endDate)}` }) @@ -99,8 +179,12 @@ function setDateRange(range: string) { const customRangeActive = computed(() => { return dateRange.value !== datesToday.value && + dateRange.value !== datesThisWeek.value && dateRange.value !== datesNextWeek.value && - dateRange.value !== datesNextMonth.value + dateRange.value !== datesNext7Days.value && + dateRange.value !== datesThisMonth.value && + dateRange.value !== datesNextMonth.value && + dateRange.value !== datesNext30Days.value }) diff --git a/src/i18n/lang/en.json b/src/i18n/lang/en.json index b5ddf6ea..5d104781 100644 --- a/src/i18n/lang/en.json +++ b/src/i18n/lang/en.json @@ -536,8 +536,12 @@ "fromuntil": "Tasks from {from} until {until}", "select": "Select a range:", "today": "Today", + "thisWeek": "This Week", "nextWeek": "Next Week", + "next7Days": "Next 7 Days", + "thisMonth": "This Month", "nextMonth": "Next Month", + "next30Days": "Next 30 Days", "noTasks": "Nothing to do — Have a nice day!" }, "detail": {