shadcn-table icon indicating copy to clipboard operation
shadcn-table copied to clipboard

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

Open dBianchii opened this issue 9 months ago • 5 comments

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

dBianchii avatar May 10 '24 17:05 dBianchii

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

nuclei272 avatar May 21 '24 18:05 nuclei272

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

sadmann7 avatar Jun 02 '24 06:06 sadmann7

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

dBianchii avatar Jun 02 '24 11:06 dBianchii

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?

sadmann7 avatar Jun 03 '24 02:06 sadmann7

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

dBianchii avatar Jun 03 '24 12:06 dBianchii