diff --git a/umap/static/umap/js/modules/facets.js b/umap/static/umap/js/modules/facets.js index 74ae3d2c..def0541b 100644 --- a/umap/static/umap/js/modules/facets.js +++ b/umap/static/umap/js/modules/facets.js @@ -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 || '') - } } - - } diff --git a/umap/static/umap/js/modules/utils.js b/umap/static/umap/js/modules/utils.js index 125945ee..5b18286e 100644 --- a/umap/static/umap/js/modules/utils.js +++ b/umap/static/umap/js/modules/utils.js @@ -27,9 +27,9 @@ export function checkId(string) { /** * Compute the impacts for a given list of fields. - * + * * Return an array of unique impacts. - * + * * @param {fields} list[fields] * @returns Array[string] */ @@ -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())) +} diff --git a/umap/static/umap/js/umap.features.js b/umap/static/umap/js/umap.features.js index f8411ab3..d0749a81 100644 --- a/umap/static/umap/js/umap.features.js +++ b/umap/static/umap/js/umap.features.js @@ -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 diff --git a/umap/static/umap/unittests/utils.js b/umap/static/umap/unittests/utils.js index 68148c56..4624b273 100644 --- a/umap/static/umap/unittests/utils.js +++ b/umap/static/umap/unittests/utils.js @@ -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") + }) + }) }) diff --git a/umap/tests/integration/test_facets_browser.py b/umap/tests/integration/test_facets_browser.py index 19faf78d..37bc1eba 100644 --- a/umap/tests/integration/test_facets_browser.py +++ b/umap/tests/integration/test_facets_browser.py @@ -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]}, },