Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
BojanSovticEngIT committed Jan 10, 2025
1 parent a4eceab commit 594ad19
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 15 deletions.
34 changes: 34 additions & 0 deletions src/helpers/commons/localeHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,40 @@ export function formatDate(dateString?: string, format?: string, incomingFormat?
else return tmp.format(format || 'L')
}

export function formatDateLuxon(dateString: string, format: string, incomingFormat: string) {
const baseLocale = getLocale()?.split('_')[0] ?? fallbackLocale
const dt = DateTime.fromFormat(dateString, incomingFormat, { locale: baseLocale })

if (!dt.isValid) {
return null
}

switch (format) {
case 'LT':
return dt.toLocaleString(DateTime.TIME_SIMPLE)
case 'LTS':
return dt.toLocaleString(DateTime.TIME_WITH_SECONDS)
case 'L':
return dt.toLocaleString(DateTime.DATE_SHORT)
case 'l':
return dt.toLocaleString(DateTime.DATE_SHORT).replace(/^0+/, '')
case 'LL':
return dt.toLocaleString(DateTime.DATE_MED)
case 'll':
return dt.toLocaleString(DateTime.DATE_MED).replace(/(\w{3})/, (match) => match.toUpperCase())
case 'LLL':
return dt.toLocaleString(DateTime.DATETIME_MED)
case 'lll':
return dt.toLocaleString(DateTime.DATETIME_MED)
case 'LLLL':
return dt.toLocaleString(DateTime.DATETIME_FULL)
case 'llll':
return dt.toLocaleString(DateTime.DATETIME_FULL)
default:
return dt.toLocaleString(DateTime.DATE_SHORT)
}
}

export function formatDateWithLocale(dateString?: string | number, format?: any, keepNull?: boolean): string {
if (keepNull && !dateString) return ''
let dateToFormat = new Date()
Expand Down
18 changes: 9 additions & 9 deletions src/modules/qbe/qbeDialogs/qbePreviewDialog/QBEPreviewDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

<script lang="ts">
import { defineComponent } from 'vue'
import { formatDate } from '@/helpers/commons/localeHelper'
import { formatDateLuxon } from '@/helpers/commons/localeHelper'
import Column from 'primevue/column'
import DataTable from 'primevue/datatable'
import QBEPreviewDialogDescriptor from './QBEPreviewDialogDescriptor.json'
Expand Down Expand Up @@ -89,10 +89,10 @@ export default defineComponent({
for (let i = 1; i < data.metaData?.fields?.length; i++) {
const tempColumn = data.metaData?.fields[i]
if (['timestamp', 'date'].includes(tempColumn.type)) {
const field = this.findField(tempColumn) as any
if (field) tempColumn.metawebDateFormat = field.format
this.setCalculatedFieldDateFormat(tempColumn, i - 1)
if (!tempColumn.metawebDateFormat) {
this.setCalculatedFieldDateFormat(tempColumn, i - 1)
const field = this.findField(tempColumn) as any
if (field) tempColumn.metawebDateFormat = field.format
}
}
this.columns.push(data.metaData?.fields[i])
Expand All @@ -103,10 +103,10 @@ export default defineComponent({
if (this.selectedQuery.fields[index]) tempColumn.metawebDateFormat = this.selectedQuery.fields[index].id.format ?? 'L'
},
findField(column: any) {
if (!this.entities) return
let field = null
if (!this.entities) return field
for (let i = 0; i < this.entities.length; i++) {
const tempEntity = this.entities[i] as any
for (let j = 0; j < tempEntity.children.length; j++) {
Expand All @@ -133,13 +133,13 @@ export default defineComponent({
this.lazyParams = {}
},
getFormattedDate(date: any, column: any) {
if (!date) return null;
const inputFormat = column.type === 'timestamp' ? 'DD/MM/YYYY HH:mm:ss.SSS' : 'DD/MM/YYYY'
if (!date) return null
const inputFormat = column.type === 'timestamp' ? 'dd/MM/yyyy HH:mm:ss.SSS' : 'dd/MM/yyyy'
let format = undefined as string | undefined
if (QBEDescriptor.admissibleDateFormats.includes(column.metawebDateFormat)) {
format = column.metawebDateFormat
}
return formatDate(date, format, inputFormat)
return formatDateLuxon(date, format ?? '', inputFormat)
}
}
})
Expand Down
12 changes: 6 additions & 6 deletions src/modules/qbe/qbeTables/qbeSmartTable/QBESmartTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@
</template>
<template #body="slotProps">
<span v-if="typeof slotProps.data[`column_${index + 1}`] === 'number' && slotProps.data[`column_${index + 1}`]" v-tooltip="{ value: slotProps.data[`column_${index + 1}`] }"> {{ getFormattedNumber(col, slotProps.data[`column_${index + 1}`]) }}</span>
<span v-else-if="previewData?.metaData?.fields[index + 1]?.type === 'date' && col.type != 'inline.calculated.field'">{{ getFormattedDate(slotProps.data[`column_${index + 1}`], previewData.metaData.fields[index + 1].metawebDateFormat, 'DD/MM/YYYY') }} </span>
<span v-else-if="previewData?.metaData?.fields[index + 1]?.type === 'date' && col.type == 'inline.calculated.field'">{{ getFormattedDate(slotProps.data[`column_${index + 1}`], col.id.format, 'DD/MM/YYYY') }} </span>
<span v-else-if="previewData?.metaData?.fields[index + 1]?.type === 'timestamp' && col.type != 'inline.calculated.field'">{{ getFormattedDate(slotProps.data[`column_${index + 1}`], previewData.metaData.fields[index + 1].metawebDateFormat, 'DD/MM/YYYY HH:mm:ss.SSS') }} </span>
<span v-else-if="previewData?.metaData?.fields[index + 1]?.type === 'timestamp' && col.type == 'inline.calculated.field'">{{ getFormattedDate(slotProps.data[`column_${index + 1}`], col.id.format, 'DD/MM/YYYY HH:mm:ss.SSS') }} </span>
<span v-else-if="previewData?.metaData?.fields[index + 1]?.type === 'date' && col.type != 'inline.calculated.field'">{{ getFormattedDate(slotProps.data[`column_${index + 1}`], previewData.metaData.fields[index + 1].metawebDateFormat, 'dd/MM/yyyy') }} </span>
<span v-else-if="previewData?.metaData?.fields[index + 1]?.type === 'date' && col.type == 'inline.calculated.field'">{{ getFormattedDate(slotProps.data[`column_${index + 1}`], col.id.format, 'dd/MM/yyyy') }} </span>
<span v-else-if="previewData?.metaData?.fields[index + 1]?.type === 'timestamp' && col.type != 'inline.calculated.field'">{{ getFormattedDate(slotProps.data[`column_${index + 1}`], previewData.metaData.fields[index + 1].metawebDateFormat, 'dd/MM/yyyy HH:mm:ss.SSS') }} </span>
<span v-else-if="previewData?.metaData?.fields[index + 1]?.type === 'timestamp' && col.type == 'inline.calculated.field'">{{ getFormattedDate(slotProps.data[`column_${index + 1}`], col.id.format, 'dd/MM/yyyy HH:mm:ss.SSS') }} </span>
<span v-else v-tooltip.bottom="slotProps.data[`column_${index + 1}`]">{{ slotProps.data[`column_${index + 1}`] }}</span>
</template>
</Column>
Expand Down Expand Up @@ -91,7 +91,7 @@ import Column from 'primevue/column'
import Menu from 'primevue/contextmenu'
import Dialog from 'primevue/dialog'
import qbeSimpleTableDescriptor from './QBESmartTableDescriptor.json'
import { formatDate, getLocale } from '@/helpers/commons/localeHelper'
import { formatDateLuxon, getLocale } from '@/helpers/commons/localeHelper'
import { formatNumber } from '@/helpers/commons/qbeHelpers'
export default defineComponent({
Expand Down Expand Up @@ -215,7 +215,7 @@ export default defineComponent({
},
getFormattedDate(date: any, output: any, input: any) {
if (!date) return null
return formatDate(date, output, input)
return formatDateLuxon(date, output, input)
}
}
})
Expand Down

0 comments on commit 594ad19

Please sign in to comment.