mirror of
https://github.com/lana-k/sqliteviz.git
synced 2025-12-06 18:18:53 +08:00
fix csv import with ISO dates #64
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "sqliteviz",
|
"name": "sqliteviz",
|
||||||
"version": "0.13.1",
|
"version": "0.13.2",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@@ -13,7 +13,14 @@ export default {
|
|||||||
result.columns = source.meta.fields.map(col => col.trim())
|
result.columns = source.meta.fields.map(col => col.trim())
|
||||||
result.values = source.data.map(row => {
|
result.values = source.data.map(row => {
|
||||||
const resultRow = []
|
const resultRow = []
|
||||||
source.meta.fields.forEach(col => { resultRow.push(row[col]) })
|
source.meta.fields.forEach(col => {
|
||||||
|
let value = row[col]
|
||||||
|
if (value instanceof Date) {
|
||||||
|
value = value.toISOString()
|
||||||
|
}
|
||||||
|
resultRow.push(value)
|
||||||
|
})
|
||||||
|
|
||||||
return resultRow
|
return resultRow
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -11,18 +11,18 @@ describe('csv.js', () => {
|
|||||||
it('getResult with fields', () => {
|
it('getResult with fields', () => {
|
||||||
const source = {
|
const source = {
|
||||||
data: [
|
data: [
|
||||||
{ id: 1, 'name ': 'foo' },
|
{ id: 1, 'name ': 'foo', date: new Date('2021-06-30T14:10:24.717Z') },
|
||||||
{ id: 2, 'name ': 'bar' }
|
{ id: 2, 'name ': 'bar', date: new Date('2021-07-30T14:10:15.717Z') }
|
||||||
],
|
],
|
||||||
meta: {
|
meta: {
|
||||||
fields: ['id', 'name ']
|
fields: ['id', 'name ', 'date']
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
expect(csv.getResult(source)).to.eql({
|
expect(csv.getResult(source)).to.eql({
|
||||||
columns: ['id', 'name'],
|
columns: ['id', 'name', 'date'],
|
||||||
values: [
|
values: [
|
||||||
[1, 'foo'],
|
[1, 'foo', '2021-06-30T14:10:24.717Z'],
|
||||||
[2, 'bar']
|
[2, 'bar', '2021-07-30T14:10:15.717Z']
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user