0
0
Fork 0

Fix date time timezone

This commit is contained in:
Kevin Martinez 2024-03-06 22:45:23 -03:00
parent 98cf665126
commit c34fc0f79e
2 changed files with 14 additions and 6 deletions

View File

@ -1,7 +1,7 @@
<script setup> <script setup>
import { computed, ref } from 'vue'; import { computed, ref } from 'vue';
import { toDate } from 'src/filters';
import VnInput from 'components/common/VnInput.vue'; import VnInput from 'components/common/VnInput.vue';
import isValidDate from "filters/isValidDate";
const props = defineProps({ const props = defineProps({
modelValue: { modelValue: {
@ -54,6 +54,16 @@ const formatDate = (dateString) => {
date.getDate() date.getDate()
)}`; )}`;
}; };
const displayDate = (dateString) => {
if (!dateString || !isValidDate(dateString)) {
return '';
}
return new Date(dateString).toLocaleDateString([], {
year: 'numeric',
month: '2-digit',
day: '2-digit',
});
};
const styleAttrs = computed(() => { const styleAttrs = computed(() => {
return props.isOutlined return props.isOutlined
@ -69,7 +79,7 @@ const styleAttrs = computed(() => {
<template> <template>
<VnInput <VnInput
class="vn-input-date" class="vn-input-date"
:model-value="toDate(value)" :model-value="displayDate(value)"
v-bind="{ ...$attrs, ...styleAttrs }" v-bind="{ ...$attrs, ...styleAttrs }"
readonly readonly
@click="isPopupOpen = true" @click="isPopupOpen = true"

View File

@ -1,6 +1,5 @@
<script setup> <script setup>
import { computed, ref } from 'vue'; import { computed, ref } from 'vue';
import { toHour } from 'src/filters';
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
import isValidDate from 'filters/isValidDate'; import isValidDate from 'filters/isValidDate';
import VnInput from "components/common/VnInput.vue"; import VnInput from "components/common/VnInput.vue";
@ -41,14 +40,13 @@ const value = computed({
const isPopupOpen = ref(false); const isPopupOpen = ref(false);
const onDateUpdate = (date) => { const onDateUpdate = (date) => {
internalValue.value = date; internalValue.value = date;
isPopupOpen.value = false;
}; };
const save = () => { const save = () => {
value.value = internalValue.value; value.value = internalValue.value;
}; };
const formatTime = (dateString) => { const formatTime = (dateString) => {
if (!isValidDate(dateString)) { if (!dateString || !isValidDate(dateString)) {
return ''; return '';
} }
@ -76,7 +74,7 @@ const styleAttrs = computed(() => {
<VnInput <VnInput
class="vn-input-time" class="vn-input-time"
readonly readonly
:model-value="toHour(value)" :model-value="formatTime(value)"
v-bind="{ ...$attrs, ...styleAttrs }" v-bind="{ ...$attrs, ...styleAttrs }"
@click="isPopupOpen = true" @click="isPopupOpen = true"
> >