Browse Source

fix: pg date formatting

Signed-off-by: mertmit <mertmit99@gmail.com>
pull/1816/head
mertmit 3 years ago
parent
commit
d77a5f1c6d
  1. 1
      packages/nc-gui/components/project/spreadsheet/components/virtualCell.vue
  2. 23
      packages/nc-gui/components/project/spreadsheet/components/virtualCell/formulaCell.vue
  3. 4
      packages/nocodb/src/lib/dataMapper/lib/sql/functionMappings/pg.ts

1
packages/nc-gui/components/project/spreadsheet/components/virtualCell.vue

@ -85,6 +85,7 @@
v-else-if="formula"
:row="row"
:column="column"
:client="nodes.dbConnection.client"
/>
<rollup-cell
v-else-if="rollup"

23
packages/nc-gui/components/project/spreadsheet/components/virtualCell/formulaCell.vue

@ -11,19 +11,27 @@
</v-tooltip>
<div v-else-if="urls" v-html="urls" />
<div v-else>
{{ row[column.title] }}
{{ result }}
</div>
</template>
<script>
import dayjs from 'dayjs'
export default {
name: 'FormulaCell',
props: { column: Object, row: Object },
props: { column: Object, row: Object, client: String },
computed: {
result() {
if (this.client === 'pg') {
return this.handleTZ(this.row[this.column.title])
}
return this.row[this.column.title]
},
urls() {
if (!this.row[this.column.title]) { return }
const rawText = this.row[this.column.title].toString()
const rawText = this.result.toString()
let found = false
const out = rawText.replace(/URI::\((.*?)\)/g, (_, url) => {
found = true
@ -36,6 +44,15 @@ export default {
return found && out
}
},
methods: {
// handle date returned from PostgreSQL
handleTZ(val) {
if (!val) { return }
return val.replace(/((?:-?(?:[1-9][0-9]*)?[0-9]{4})-(?:1[0-2]|0[1-9])-(?:3[01]|0[1-9]|[12][0-9])T(?:2[0-3]|[01][0-9]):(?:[0-5][0-9]):(?:[0-5][0-9])(?:\.[0-9]+)?(?:Z|[+-](?:2[0-3]|[01][0-9]):[0-5][0-9]))/g, (i, v) => {
return dayjs(v).format('YYYY-MM-DD HH:mm')
})
}
}
}
</script>

4
packages/nocodb/src/lib/dataMapper/lib/sql/functionMappings/pg.ts

@ -37,13 +37,13 @@ const pg = {
return knex.raw(
`CASE
WHEN CAST(${fn(pt.arguments[0])} AS text) LIKE '%:%' THEN
${fn(pt.arguments[0])}::timestamptz + INTERVAL '${fn(pt.arguments[1])}
${fn(pt.arguments[0])} + INTERVAL '${fn(pt.arguments[1])}
${String(fn(pt.arguments[2])).replace(
/["']/g,
''
)}'
ELSE
${fn(pt.arguments[0])}::timestamptz + INTERVAL '${fn(pt.arguments[1])}
${fn(pt.arguments[0])} + INTERVAL '${fn(pt.arguments[1])}
${String(fn(pt.arguments[2])).replace(/["']/g, '')}'
END${colAlias}`
);

Loading…
Cancel
Save