adjust date format

This commit is contained in:
Pete Matsyburka
2024-08-05 19:38:47 +03:00
parent 478167ea4f
commit 91d44a3e31
4 changed files with 27 additions and 6 deletions
+23 -3
View File
@@ -435,6 +435,7 @@ export default {
save: this.save,
t: this.t,
currencies: this.currencies,
locale: this.locale,
baseFetch: this.baseFetch,
fieldTypes: this.fieldTypes,
backgroundColor: this.backgroundColor,
@@ -468,6 +469,11 @@ export default {
required: false,
default: ''
},
locale: {
type: String,
required: false,
default: ''
},
editable: {
type: Boolean,
required: false,
@@ -649,6 +655,20 @@ export default {
computed: {
selectedAreaRef: () => ref(),
fieldsDragFieldRef: () => ref(),
defaultDateFormat () {
const isUsBrowser = Intl.DateTimeFormat().resolvedOptions().locale.endsWith('-US')
const isUsTimezone = new Intl.DateTimeFormat('en-US', { timeZoneName: 'short' }).format(new Date()).match(/\s(?:CST|CDT|PST|PDT|EST|EDT)$/)
return this.localeDateFormats[this.locale] || ((isUsBrowser || isUsTimezone) ? 'MM/DD/YYYY' : 'DD/MM/YYYY')
},
localeDateFormats () {
return {
'de-DE': 'DD.MM.YYYY',
'fr-FR': 'DD/MM/YYYY',
'it-IT': 'DD/MM/YYYY',
'es-ES': 'DD/MM/YYYY'
}
},
fieldAreasIndex () {
const areas = {}
@@ -768,7 +788,7 @@ export default {
if (type === 'date') {
field.preferences = {
format: Intl.DateTimeFormat().resolvedOptions().locale.endsWith('-US') || new Intl.DateTimeFormat('en-US', { timeZoneName: 'short' }).format(new Date()).match(/\s(?:CST|CDT|PST|PDT|EST|EDT)$/) ? 'MM/DD/YYYY' : 'DD/MM/YYYY'
format: this.defaultDateFormat
}
}
@@ -801,7 +821,7 @@ export default {
if (type === 'date') {
field.preferences = {
format: Intl.DateTimeFormat().resolvedOptions().locale.endsWith('-US') || new Intl.DateTimeFormat('en-US', { timeZoneName: 'short' }).format(new Date()).match(/\s(?:CST|CDT|PST|PDT|EST|EDT)$/) ? 'MM/DD/YYYY' : 'DD/MM/YYYY'
format: this.defaultDateFormat
}
}
@@ -1138,7 +1158,7 @@ export default {
if (field.type === 'date') {
field.preferences = {
format: Intl.DateTimeFormat().resolvedOptions().locale.endsWith('-US') || new Intl.DateTimeFormat('en-US', { timeZoneName: 'short' }).format(new Date()).match(/\s(?:CST|CDT|PST|PDT|EST|EDT)$/) ? 'MM/DD/YYYY' : 'DD/MM/YYYY'
format: this.defaultDateFormat
}
}
}