shadcn-table
shadcn-table copied to clipboard
[bug]: Recent Date-Range fix is displaying the previous day instead of selected url date
Describe the bug
https://www.loom.com/share/b92de30f533e4b2bbdf3008811f566ea?sid=5d2f66f4-76bb-45a6-b389-388c2c1688ac
How to reproduce
- Go here: https://table.sadmn.com/?page=1&sort=createdAt.desc&from=2024-05-08&to=2024-05-14
- Look at the date-range component, compare with url.
Link to reproduction
https://table.sadmn.com/?page=1&sort=createdAt.desc&from=2024-05-08&to=2024-05-14
Additional information
No response
I had this problem too. It has to do with how the dates are compared in the query. Basically on queries.ts
, when you create a new Date object, it includes the current time (hours, minutes, seconds) and so, when you're comparing dates with gte and lte (less than or equal to), it's actually comparing down to the millisecond range.
In order to fix this, you can adjust the "from" date to start at the beginning of the day and the "to" date to end at the end of the day:
if (fromDay) {
fromDay.setHours(0, 0, 0, 0);
}
if (toDay) {
toDay.setHours(23, 59, 59, 999);
}
So simply add these lines of code after:
const fromDay = from ? new Date(from) : undefined
const toDay = to ? new Date(to) : undefined
i updated the date-range-picker
component
also using sql to get date now
const fromDay = from ? sql`to_date(${from}, 'yyyy-mm-dd')` : undefined
const toDay = to ? sql`to_date(${to}, 'yyy-mm-dd')` : undefined
let me know if it works for you now
If the website is up to date with the code, the error
i updated the
date-range-picker
componentalso using sql to get date now
const fromDay = from ? sql`to_date(${from}, 'yyyy-mm-dd')` : undefined const toDay = to ? sql`to_date(${to}, 'yyy-mm-dd')` : undefined
If the website is up to date with the code, the error persists
If the website is up to date with the code, the error
i updated the
date-range-picker
component also using sql to get date nowconst fromDay = from ? sql`to_date(${from}, 'yyyy-mm-dd')` : undefined const toDay = to ? sql`to_date(${to}, 'yyy-mm-dd')` : undefined
If the website is up to date with the code, the error persists
can you provide a reproduction link?
If the website is up to date with the code, the error
i updated the
date-range-picker
component also using sql to get date nowconst fromDay = from ? sql`to_date(${from}, 'yyyy-mm-dd')` : undefined const toDay = to ? sql`to_date(${to}, 'yyy-mm-dd')` : undefined
If the website is up to date with the code, the error persists
can you provide a reproduction link?
It must be related to timezone issues then? Because it's the same link I provided in this post. Maybe try changing your computer's timezone to reproduce, or something?