chore: try to parse naive dates as UTC
This commit is contained in:
parent
eb0d17154c
commit
37e0582b30
5 changed files with 29 additions and 9 deletions
|
@ -1,5 +1,6 @@
|
|||
import { DomUtil, DomEvent, stamp } from '../../vendors/leaflet/leaflet-src.esm.js'
|
||||
import { translate } from './i18n.js'
|
||||
import * as Utils from './utils.js'
|
||||
|
||||
export default class Facets {
|
||||
constructor(map) {
|
||||
|
@ -133,18 +134,15 @@ export default class Facets {
|
|||
}
|
||||
|
||||
getParser(type) {
|
||||
switch(type) {
|
||||
switch (type) {
|
||||
case 'number':
|
||||
return parseFloat
|
||||
case 'datetime':
|
||||
return (v) => new Date(v)
|
||||
case 'date':
|
||||
return (v) => new Date(new Date(v).toDateString()) // Without time
|
||||
return Utils.parseNaiveDate
|
||||
default:
|
||||
return (v) => String(v || '')
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -356,3 +356,9 @@ export function template(str, data) {
|
|||
return value
|
||||
})
|
||||
}
|
||||
|
||||
export function parseNaiveDate(value) {
|
||||
const naive = new Date(value)
|
||||
// Let's pretend naive date are UTC, and remove time…
|
||||
return new Date(Date.UTC(naive.getFullYear(), naive.getMonth(), naive.getDate()))
|
||||
}
|
||||
|
|
|
@ -504,7 +504,6 @@ U.FeatureMixin = {
|
|||
case 'number':
|
||||
min = parser(min)
|
||||
max = parser(max)
|
||||
value = parser(value)
|
||||
if (!isNaN(min) && !isNaN(value) && min > value) return false
|
||||
if (!isNaN(max) && !isNaN(value) && max < value) return false
|
||||
break
|
||||
|
|
|
@ -590,4 +590,21 @@ describe('Utils', function () {
|
|||
assert.deepEqual(getImpactsFromSchema(['foo', 'bar', 'baz'], schema), ['A', 'B'])
|
||||
})
|
||||
})
|
||||
describe('parseNaiveDate', () => {
|
||||
it('should parse a date', () => {
|
||||
assert.equal(Utils.parseNaiveDate("2024/03/04").toISOString(), "2024-03-04T00:00:00.000Z")
|
||||
})
|
||||
it('should parse a datetime', () => {
|
||||
assert.equal(Utils.parseNaiveDate("2024/03/04 12:13:14").toISOString(), "2024-03-04T00:00:00.000Z")
|
||||
})
|
||||
it('should parse an iso datetime', () => {
|
||||
assert.equal(Utils.parseNaiveDate("2024-03-04T00:00:00.000Z").toISOString(), "2024-03-04T00:00:00.000Z")
|
||||
})
|
||||
it('should parse a GMT time', () => {
|
||||
assert.equal(Utils.parseNaiveDate("04 Mar 2024 00:12:00 GMT").toISOString(), "2024-03-04T00:00:00.000Z")
|
||||
})
|
||||
it('should parse a GMT time with explicit timezone', () => {
|
||||
assert.equal(Utils.parseNaiveDate("Thu, 04 Mar 2024 00:00:00 GMT+0300").toISOString(), "2024-03-03T00:00:00.000Z")
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
@ -59,7 +59,7 @@ DATALAYER_DATA2 = {
|
|||
"mytype": "odd",
|
||||
"name": "Point 3",
|
||||
"mynumber": 14,
|
||||
"mydate": "2024/04/04 10:19:17",
|
||||
"mydate": "2024-04-04T10:19:17.000Z",
|
||||
},
|
||||
"geometry": {"type": "Point", "coordinates": [4.372559, 47.945786]},
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue