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
This commit is contained in:
kolaente 2025-03-09 09:44:56 +01:00
parent 4ba5aeb911
commit 5db22c9964
No known key found for this signature in database
GPG Key ID: F40E70337AB24C9B
1 changed files with 14 additions and 7 deletions

View File

@ -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)
},
})