1
0
Fork 0
mirror of https://framagit.org/framasoft/mobilizon.git synced 2024-12-22 07:52:43 +00:00

Issue #1571 Hide the time when the user chooses to not display it

This commit is contained in:
Massedil 2024-11-04 21:25:37 +01:00
parent 9992286e7e
commit 7f43169fae
2 changed files with 16 additions and 3 deletions

View file

@ -1,6 +1,12 @@
<template>
<!--
:key is required to force rerender when time change
If not used, the input becomes empty
See : https://vuejs.org/api/built-in-special-attributes.html#key
-->
<input
type="datetime-local"
:type="time ? 'datetime-local' : 'date'"
:key="time.toString()"
class="rounded invalid:border-red-500"
v-model="component"
:min="computeMin"
@ -13,6 +19,7 @@ import { computed } from "vue";
const props = withDefaults(
defineProps<{
modelValue: Date | null;
time: boolean;
min?: Date | null | undefined;
}>(),
{
@ -25,7 +32,7 @@ const emit = defineEmits(["update:modelValue", "blur"]);
/** Format a Date to 'YYYY-MM-DDTHH:MM' based on local time zone */
const UTCToLocal = (date: Date) => {
const localDate = new Date(date.getTime() - date.getTimezoneOffset() * 60000);
return localDate.toISOString().slice(0, 16);
return localDate.toISOString().slice(0, props.time ? 16 : 10);
};
const component = computed({
@ -36,12 +43,16 @@ const component = computed({
return UTCToLocal(props.modelValue);
},
set(value) {
console.log("value" + value);
if (!value) {
emit("update:modelValue", null);
return;
}
const date = new Date(value);
if (!props.time) {
date.setHours(0, 0, 0, 0);
}
emit("update:modelValue", date);
},
});

View file

@ -67,6 +67,7 @@
label-for="begins-on-field"
>
<event-date-picker
:time="eventOptions.showStartTime"
v-model="beginsOn"
@blur="consistencyBeginsOnBeforeEndsOn"
></event-date-picker>
@ -83,6 +84,7 @@
class="items-center"
>
<event-date-picker
:time="eventOptions.showEndTime"
v-model="endsOn"
@blur="consistencyBeginsOnBeforeEndsOn"
:min="beginsOn"