fix: Custom attribute date is not working in some time zone (#7224)

This commit is contained in:
Muhsin Keloth
2023-06-10 05:25:03 +05:30
committed by GitHub
parent 879a244f93
commit cd28f401ba

View File

@@ -115,7 +115,7 @@
</template> </template>
<script> <script>
import format from 'date-fns/format'; import { format, parseISO } from 'date-fns';
import { required, url } from 'vuelidate/lib/validators'; import { required, url } from 'vuelidate/lib/validators';
import { BUS_EVENTS } from 'shared/constants/busEvents'; import { BUS_EVENTS } from 'shared/constants/busEvents';
import MultiselectDropdown from 'shared/components/ui/MultiselectDropdown.vue'; import MultiselectDropdown from 'shared/components/ui/MultiselectDropdown.vue';
@@ -143,15 +143,20 @@ export default {
}, },
computed: { computed: {
formattedValue() { displayValue() {
if (this.isAttributeTypeDate) { if (this.isAttributeTypeDate) {
return format(new Date(this.value || new Date()), DATE_FORMAT); return new Date(this.value || new Date()).toLocaleDateString();
} }
if (this.isAttributeTypeCheckbox) { if (this.isAttributeTypeCheckbox) {
return this.value === 'false' ? false : this.value; return this.value === 'false' ? false : this.value;
} }
return this.value; return this.value;
}, },
formattedValue() {
return this.isAttributeTypeDate
? format(this.value ? new Date(this.value) : new Date(), DATE_FORMAT)
: this.value;
},
listOptions() { listOptions() {
return this.values.map((value, index) => ({ return this.values.map((value, index) => ({
id: index + 1, id: index + 1,
@@ -192,17 +197,11 @@ export default {
} }
return this.$t('CUSTOM_ATTRIBUTES.VALIDATIONS.REQUIRED'); return this.$t('CUSTOM_ATTRIBUTES.VALIDATIONS.REQUIRED');
}, },
displayValue() {
if (this.attributeType === 'date') {
return format(new Date(this.editedValue), 'dd-MM-yyyy');
}
return this.editedValue;
},
}, },
watch: { watch: {
value() { value() {
this.isEditing = false; this.isEditing = false;
this.editedValue = this.value; this.editedValue = this.formattedValue;
}, },
}, },
@@ -249,9 +248,8 @@ export default {
onUpdate() { onUpdate() {
const updatedValue = const updatedValue =
this.attributeType === 'date' this.attributeType === 'date'
? format(new Date(this.editedValue), DATE_FORMAT) ? parseISO(this.editedValue)
: this.editedValue; : this.editedValue;
this.$v.$touch(); this.$v.$touch();
if (this.$v.$invalid) { if (this.$v.$invalid) {
return; return;