From 4964cb838b88f43f312523b2c4ae558c487cc23c Mon Sep 17 00:00:00 2001 From: fenn-cs Date: Wed, 15 Nov 2023 16:00:36 +0100 Subject: [PATCH] Improve date-range logic for global search - Allow future dates in custom date range - Fix date ranges for example, before now, today range was roughly between `now()` to `now() + a few milli seconds` - Update text in custom date range modal, right align "Search in range" button. Signed-off-by: fenn-cs --- .../GlobalSearch/CustomDateRangeModal.vue | 31 +++++++++++-------- core/src/views/GlobalSearchModal.vue | 22 ++++++------- 2 files changed, 29 insertions(+), 24 deletions(-) diff --git a/core/src/components/GlobalSearch/CustomDateRangeModal.vue b/core/src/components/GlobalSearch/CustomDateRangeModal.vue index 8cbcc650090..8effdcf0fe0 100644 --- a/core/src/components/GlobalSearch/CustomDateRangeModal.vue +++ b/core/src/components/GlobalSearch/CustomDateRangeModal.vue @@ -1,33 +1,33 @@ @@ -94,5 +94,10 @@ export default { flex-direction: column; } + &__footer { + display: flex; + justify-content: end; + } + } diff --git a/core/src/views/GlobalSearchModal.vue b/core/src/views/GlobalSearchModal.vue index a199a5fb464..9db4c06c9bc 100644 --- a/core/src/views/GlobalSearchModal.vue +++ b/core/src/views/GlobalSearchModal.vue @@ -462,35 +462,36 @@ export default { applyQuickDateRange(range) { this.dateActionMenuIsOpen = false const today = new Date() - let endDate = today let startDate + let endDate + switch (range) { case 'today': // For 'Today', both start and end are set to today - startDate = today + startDate = new Date(today.getFullYear(), today.getMonth(), today.getDate(), 0, 0, 0, 0) + endDate = new Date(today.getFullYear(), today.getMonth(), today.getDate(), 23, 59, 59, 999) this.dateFilter.text = t('core', 'Today') break case '7days': // For 'Last 7 days', start date is 7 days ago, end is today - startDate = new Date(today) - startDate.setDate(today.getDate() - 7) + startDate = new Date(today.getFullYear(), today.getMonth(), today.getDate() - 6, 0, 0, 0, 0) this.dateFilter.text = t('core', 'Last 7 days') break case '30days': // For 'Last 30 days', start date is 30 days ago, end is today - startDate = new Date(today) - startDate.setDate(today.getDate() - 30) + startDate = new Date(today.getFullYear(), today.getMonth(), today.getDate() - 29, 0, 0, 0, 0) this.dateFilter.text = t('core', 'Last 30 days') break case 'thisyear': - // For 'This year', start date is the first day of the year, end is today - startDate = new Date(today.getFullYear(), 0, 1) + // For 'This year', start date is the first day of the year, end is the last day of the year + startDate = new Date(today.getFullYear(), 0, 1, 0, 0, 0, 0) + endDate = new Date(today.getFullYear(), 11, 31, 23, 59, 59, 999) this.dateFilter.text = t('core', 'This year') break case 'lastyear': // For 'Last year', start date is the first day of the previous year, end is the last day of the previous year - startDate = new Date(today.getFullYear() - 1, 0, 1) - endDate = new Date(today.getFullYear() - 1, 11, 31) + startDate = new Date(today.getFullYear() - 1, 0, 1, 0, 0, 0, 0) + endDate = new Date(today.getFullYear() - 1, 11, 31, 23, 59, 59, 999) this.dateFilter.text = t('core', 'Last year') break case 'custom': @@ -498,7 +499,6 @@ export default { return default: return - } this.dateFilter.startFrom = startDate this.dateFilter.endAt = endDate -- 2.39.5