How to filter date independent of Timezone?

1.1k views Asked by At

I have an array of objects where each object has a date property.

Date is in ISO 8601 format

When I try to filter this array based on date using spread sheet formula like this

[Date]=Date(2017,8,2)

This formula only works in the timezone +1:00. It does not work any other timezone. How can I make this formula work on any timezone?

I am using spread views library from Grapecity.

1

There are 1 answers

0
Zp Bappi On BEST ANSWER

I could not find any way to set the timezone in the query for SpreadView either. In an answer to a similar query here, they mentioned that they do not support timezone in their controls either. You can, however, apply an intermediate solution. They seem to be considering the current browser's timezone when you are passing a date object like Date(yyyy,mm,dd). So, if you can convert the dates into your data that you are receiving (or, the array of objects you have) in the browser's timezone, it would solve your problem in theory. You can convert your Date field in the the array of objects using moment.js as-

cons convertDateTimeToBrowserTime = (dateTimeWithTimeZone)
    => moment(dateTimeWithTimeZone, 'YYYY-MM-DDTHH:mm:ssZ').local().format('YYYY-MM-DD')
    // with recent version of moment, you can use a slightly shorter syntax like:
    // => moment(dateTimeWithTimeZone, moment.ISO_8601).local().format(YYYY-MM-DD)

This will convert your date values in the collection to the appropriate date according to the browser's timezone. After this pre-processing, your given query should work as expected.