Browse Source

fix: datetime and date handling(wip)

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/863/head
Pranav C 3 years ago
parent
commit
fae5c9d572
  1. 13
      packages/nc-gui/components/project/spreadsheet/components/editableCell/datePickerCell.vue
  2. 24
      packages/nc-gui/components/project/spreadsheet/components/editableCell/dateTimePickerCell.vue
  3. 6
      packages/nc-gui/package-lock.json
  4. 2
      packages/nc-gui/package.json
  5. 4
      packages/nocodb/src/lib/noco/meta/NcMetaMgr.ts
  6. 11
      packages/nocodb/src/lib/utils/NcConfigFactory.ts

13
packages/nc-gui/components/project/spreadsheet/components/editableCell/datePickerCell.vue

@ -13,6 +13,8 @@
</template>
<script>
import dayjs from 'dayjs'
export default {
name: 'DatePickerCell',
props: {
@ -20,13 +22,22 @@ export default {
},
computed: {
localState: {
get() {
/* get() {
return typeof this.value === 'string' ? this.value.replace(/(\d)T(?=\d)/, '$1 ').replace(/\s\d{2}:\d{2}:[\d:.]+z?$/i, '') : (this.value && new Date(this.value))
},
set(val) {
const v = new Date(val)
this.$emit('input', v.toString() === 'Invalid Date' ? '' : new Date(val).toJSON().slice(0, 10))
} */
get() {
if (!this.value) { return this.value }
return dayjs(this.value).format('YYYY-MM-DD')
},
set(val) {
this.$emit('input', val && dayjs(val).format('YYYY-MM-DD'))
}
},
parentListeners() {

24
packages/nc-gui/components/project/spreadsheet/components/editableCell/dateTimePickerCell.vue

@ -19,23 +19,33 @@
<script>
import dayjs from 'dayjs'
import utc from 'dayjs/plugin/utc'
dayjs.extend(utc)
export default {
name: 'DateTimePickerCell',
props: ['value', 'ignoreFocus'],
computed: {
localState: {
get() {
// todo : time value correction
if (!this.value) { return this.value }
if (/^\d{6,}$/.test(this.value)) {
return new Date(+this.value)
}
return dayjs(this.value).format('YYYY-MM-DD HH:mm')
return /\dT\d/.test(this.value) ? new Date(this.value.replace(/(\d)T(?=\d)/, '$1 ')) : ((this.value && new Date(this.value)))
// todo : time value correction
//
// if (/^\d{6,}$/.test(this.value)) {
// return new Date(+this.value)
// }
//
// return /\dT\d/.test(this.value) ? new Date(this.value.replace(/(\d)T(?=\d)/, '$1 ')) : ((this.value && new Date(this.value)))
},
set(val) {
const uVal = val && new Date(val).toISOString().slice(0, 19).replace('T', ' ').replace(/(\d{1,2}:\d{1,2}):\d{1,2}$/, '$1')
this.$emit('input', uVal)
// console.log('dayjs=====', dayjs.utc(val).toString())
// const uVal = val && new Date(val).toISOString().slice(0, 19).replace('T', ' ').replace(/(\d{1,2}:\d{1,2}):\d{1,2}$/, '$1')
this.$emit('input', val && dayjs(val).format('YYYY-MM-DD HH:mm'))
}
},
parentListeners() {

6
packages/nc-gui/package-lock.json generated

@ -4561,9 +4561,9 @@
"integrity": "sha512-5ycpauovVyAk0kXNZz6ZoB9AYMZB4DObse7P3BPWmyEjXNORTI8EJ6X0uaSAq4sCHzM1uajzrkr6HnsLQpxGXA=="
},
"dayjs": {
"version": "1.10.6",
"resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.10.6.tgz",
"integrity": "sha512-AztC/IOW4L1Q41A86phW5Thhcrco3xuAA+YX/BLpLWWjRcTj5TOt/QImBLmCKlrF7u7k47arTnOyL6GnbG8Hvw=="
"version": "1.10.7",
"resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.10.7.tgz",
"integrity": "sha512-P6twpd70BcPK34K26uJ1KT3wlhpuOAPoMwJzpsIWUxHZ7wpmbdZL/hQqBDfz7hGurYSa5PhzdhDHtt319hL3ig=="
},
"de-indent": {
"version": "1.0.2",

2
packages/nc-gui/package.json

@ -19,7 +19,7 @@
"animate.css": "^4.1.1",
"browser-lang": "^0.1.0",
"canvas-confetti": "^1.4.0",
"dayjs": "^1.10.4",
"dayjs": "^1.10.7",
"debounce": "^1.2.0",
"file-saver": "^2.0.5",
"fix-path": "^3.0.0",

4
packages/nocodb/src/lib/noco/meta/NcMetaMgr.ts

@ -37,6 +37,7 @@ import NcMetaIO, { META_TABLES } from './NcMetaIO';
import { promisify } from 'util';
import NcTemplateParser from '../../templateParser/NcTemplateParser';
import UITypes from '../../sqlUi/UITypes';
import { defaultConnectionConfig } from '../../utils/NcConfigFactory';
const XC_PLUGIN_DET = 'XC_PLUGIN_DET';
@ -300,7 +301,8 @@ export default class NcMetaMgr {
+process.env.DB_QUERY_LIMIT_MAX || 100
),
+process.env.DB_QUERY_LIMIT_MIN || 1
)
),
timezone: defaultConnectionConfig.timezone
};
return res.json(result);
}

11
packages/nocodb/src/lib/utils/NcConfigFactory.ts

@ -32,8 +32,9 @@ const defaultClientPortMapping = {
mssql: 1433
};
const defaultConnectionConfig = {
// timezone: 'UTC',
const defaultConnectionConfig: any = {
// https://github.com/knex/knex/issues/97
// timezone: process.env.NC_TIMEZONE || 'UTC',
// dateStrings: true
};
@ -163,7 +164,8 @@ export default class NcConfigFactory implements NcConfig {
password:
url.searchParams.get('p') || url.searchParams.get('password'),
port: +url.port,
user: url.searchParams.get('u') || url.searchParams.get('user')
user: url.searchParams.get('u') || url.searchParams.get('user'),
timezone: 'utc'
},
// pool: {
// min: 1,
@ -559,7 +561,8 @@ export default class NcConfigFactory implements NcConfig {
db: {
client: 'sqlite3',
connection: {
filename: 'noco.db'
filename: 'noco.db',
timezone: 'utc'
}
}
};

Loading…
Cancel
Save