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>
import { computed, ref } from 'vue';
import { toDate } from 'src/filters';
import VnInput from 'components/common/VnInput.vue';
import isValidDate from "filters/isValidDate";
const props = defineProps({
modelValue: {
@ -54,6 +54,16 @@ const formatDate = (dateString) => {
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(() => {
return props.isOutlined
@ -69,7 +79,7 @@ const styleAttrs = computed(() => {
<template>
<VnInput
class="vn-input-date"
:model-value="toDate(value)"
:model-value="displayDate(value)"
v-bind="{ ...$attrs, ...styleAttrs }"
readonly
@click="isPopupOpen = true"

View File

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