Loading dateTime filter from localStorage

1 Answer 49 Views
Grid
Stacey
Top achievements
Rank 1
Iron
Stacey asked on 09 Jul 2024, 04:28 PM | edited on 09 Jul 2024, 04:50 PM

I am having trouble with loading a dateTime filter from localStorage.

What I have observed is that when I send a request to the server with a Date picked from the DatePicker the request looks as follows:

filter: DateTS~eq~datetime'2024-07-09T00-00-00'

However when sent with a Date loaded from localStorage it looks as follows:

filter: DateTS~eq~'2024-07-09T04:00:00.000Z'

My localStorage variable is just the filter object and looks as follows:

{
"filters": [
{
                "operator": "eq",
                "value": "2024-07-09T04:00:00.000Z",
                "field": "DateTS"
            }
],
      "logic": "and"
}

looking for the best way to translate datetime fields so that the request is sent to the api properly when loading from localStorage.

1 Answer, 1 is accepted

Sort by
0
Stacey
Top achievements
Rank 1
Iron
answered on 09 Jul 2024, 05:27 PM

A bit more searching and I was able to resolve for myself.

Before serializing the filter object to save in local storage I needed to check the filters for any where the value was a Date and then use Date.prototype.toISOString().

storageObject.filter.filters
    .filter(filter => filter.value instanceof Date)
    .forEach(filter => filter.value.toISOString());

 

Tags
Grid
Asked by
Stacey
Top achievements
Rank 1
Iron
Answers by
Stacey
Top achievements
Rank 1
Iron
Share this question
or