From 5db22c9964d1c1b39faae83eec5ac2f49ee768d4 Mon Sep 17 00:00:00 2001 From: kolaente Date: Sun, 9 Mar 2025 09:44:56 +0100 Subject: [PATCH] fix(date): do not format time values using dayjs for use in date pickers This fixes a bug where it would be impossible to set times to something later than 12:00 as they would be automatically converted to am - but the datepicker didn't fully support this and thus it would just be set to 1. Resolves https://kolaente.dev/vikunja/vikunja/issues/3073 --- .../src/components/input/DatepickerInline.vue | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/frontend/src/components/input/DatepickerInline.vue b/frontend/src/components/input/DatepickerInline.vue index ecd152943..f50d6a4f4 100644 --- a/frontend/src/components/input/DatepickerInline.vue +++ b/frontend/src/components/input/DatepickerInline.vue @@ -117,6 +117,16 @@ const flatPickerConfig = computed(() => ({ locale: useFlatpickrLanguage().value, })) +function formatDateToFlatpickrString(date: Date): string { + const year = date.getFullYear() + const month = (date.getMonth() + 1).toString().padStart(2, '0') + const day = date.getDate().toString().padStart(2, '0') + const hours = date.getHours().toString().padStart(2, '0') + const minutes = date.getMinutes().toString().padStart(2, '0') + + return `${year}-${month}-${day} ${hours}:${minutes}` +} + // Since flatpickr dates are strings, we need to convert them to native date objects. // To make that work, we need a separate variable since flatpickr does not have a change event. const flatPickrDate = computed({ @@ -126,11 +136,8 @@ const flatPickrDate = computed({ return } - if (date.value !== null) { - const oldDate = formatDate(date.value, 'YYYY-MM-DD h:m') - if (oldDate === newValue) { - return - } + if (date.value && formatDateToFlatpickrString(date.value) === newValue) { + return } date.value = createDateFromString(newValue) updateData() @@ -139,8 +146,8 @@ const flatPickrDate = computed({ if (!date.value) { return '' } - - return formatDate(date.value, 'YYYY-MM-DD h:m') + + return formatDateToFlatpickrString(date.value) }, })