sadmann7 / shadcn-table

A shadcn table component with server-side sorting, filtering, and pagination.
https://table.sadmn.com
MIT License
2.05k stars 175 forks source link

[bug]: Recent Date-Range fix is displaying the previous day instead of selected url date #329

Open dBianchii opened 1 month ago

dBianchii commented 1 month ago

Describe the bug

https://www.loom.com/share/b92de30f533e4b2bbdf3008811f566ea?sid=5d2f66f4-76bb-45a6-b389-388c2c1688ac

How to reproduce

  1. Go here: https://table.sadmn.com/?page=1&sort=createdAt.desc&from=2024-05-08&to=2024-05-14
  2. 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

nuclei272 commented 1 month ago

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
sadmann7 commented 4 weeks ago

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

dBianchii commented 4 weeks ago

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 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

sadmann7 commented 4 weeks ago

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 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

can you provide a reproduction link?

dBianchii commented 3 weeks ago

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 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

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? image