feat: add more date ranges and make sure they actually make sense

This commit is contained in:
kolaente 2021-12-29 16:48:34 +01:00
parent e93be0d04c
commit 8f8d25ece1
No known key found for this signature in database
GPG key ID: F40E70337AB24C9B
2 changed files with 97 additions and 9 deletions

View file

@ -4,13 +4,25 @@
<button @click="setDateRange(datesToday)" :class="{'is-active': dateRange === datesToday}"> <button @click="setDateRange(datesToday)" :class="{'is-active': dateRange === datesToday}">
{{ $t('task.show.today') }} {{ $t('task.show.today') }}
</button> </button>
<button @click="setDateRange(datesThisWeek)" :class="{'is-active': dateRange === datesThisWeek}">
{{ $t('task.show.thisWeek') }}
</button>
<button @click="setDateRange(datesNextWeek)" :class="{'is-active': dateRange === datesNextWeek}"> <button @click="setDateRange(datesNextWeek)" :class="{'is-active': dateRange === datesNextWeek}">
{{ $t('task.show.nextWeek') }} {{ $t('task.show.nextWeek') }}
</button> </button>
<button @click="setDateRange(datesNext7Days)" :class="{'is-active': dateRange === datesNext7Days}">
{{ $t('task.show.next7Days') }}
</button>
<button @click="setDateRange(datesThisMonth)" :class="{'is-active': dateRange === datesThisMonth}">
{{ $t('task.show.thisMonth') }}
</button>
<button @click="setDateRange(datesNextMonth)" :class="{'is-active': dateRange === datesNextMonth}"> <button @click="setDateRange(datesNextMonth)" :class="{'is-active': dateRange === datesNextMonth}">
{{ $t('task.show.nextMonth') }} {{ $t('task.show.nextMonth') }}
</button> </button>
<button @click="setDateRange('')" :class="{'is-active': customRangeActive}"> <button @click="setDateRange(datesNext30Days)" :class="{'is-active': dateRange === datesNext30Days}">
{{ $t('task.show.next30Days') }}
</button>
<button @click="setDateRange('')" :class="{'is-active': customRangeActive}">
{{ $t('misc.custom') }} {{ $t('misc.custom') }}
</button> </button>
</div> </div>
@ -45,7 +57,7 @@ const flatPickerConfig = computed(() => ({
mode: 'range', mode: 'range',
/*locale: { /*locale: {
// FIXME: This seems to always contain the default value - that breaks the picker // 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') 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<string>(() => { const datesToday = computed<string>(() => {
const startDate = new Date() const startDate = startOfDay(new Date())
const endDate = new Date((new Date()).setDate((new Date()).getDate() + 1)) 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<string>(() => {
const {startDate, endDate} = thisWeek()
return `${formatDate(startDate)} to ${formatDate(endDate)}` return `${formatDate(startDate)} to ${formatDate(endDate)}`
}) })
const datesNextWeek = computed<string>(() => { const datesNextWeek = computed<string>(() => {
const startDate = new Date() const {startDate, endDate} = thisWeek()
const endDate = new Date((new Date()).getTime() + 7 * 24 * 60 * 60 * 1000) startDate.setDate(startDate.getDate() + 7)
endDate.setDate(endDate.getDate() + 7)
return `${formatDate(startDate)} to ${formatDate(endDate)}`
})
const datesNext7Days = computed<string>(() => {
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<string>(() => {
const {startDate, endDate} = thisMonth()
return `${formatDate(startDate)} to ${formatDate(endDate)}` return `${formatDate(startDate)} to ${formatDate(endDate)}`
}) })
const datesNextMonth = computed<string>(() => { const datesNextMonth = computed<string>(() => {
const startDate = new Date() const {startDate, endDate} = thisMonth()
const endDate = new Date((new Date()).setMonth((new Date()).getMonth() + 1))
startDate.setMonth(startDate.getMonth() + 1)
endDate.setMonth(endDate.getMonth() + 1)
return `${formatDate(startDate)} to ${formatDate(endDate)}`
})
const datesNext30Days = computed<string>(() => {
const startDate = startOfDay(new Date())
const endDate = endOfDay(new Date((new Date()).setMonth((new Date()).getMonth() + 1)))
return `${formatDate(startDate)} to ${formatDate(endDate)}` return `${formatDate(startDate)} to ${formatDate(endDate)}`
}) })
@ -99,8 +179,12 @@ function setDateRange(range: string) {
const customRangeActive = computed<Boolean>(() => { const customRangeActive = computed<Boolean>(() => {
return dateRange.value !== datesToday.value && return dateRange.value !== datesToday.value &&
dateRange.value !== datesThisWeek.value &&
dateRange.value !== datesNextWeek.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
}) })
</script> </script>

View file

@ -536,8 +536,12 @@
"fromuntil": "Tasks from {from} until {until}", "fromuntil": "Tasks from {from} until {until}",
"select": "Select a range:", "select": "Select a range:",
"today": "Today", "today": "Today",
"thisWeek": "This Week",
"nextWeek": "Next Week", "nextWeek": "Next Week",
"next7Days": "Next 7 Days",
"thisMonth": "This Month",
"nextMonth": "Next Month", "nextMonth": "Next Month",
"next30Days": "Next 30 Days",
"noTasks": "Nothing to do — Have a nice day!" "noTasks": "Nothing to do — Have a nice day!"
}, },
"detail": { "detail": {