sadmann7 / shadcn-table

A shadcn table component with server-side sorting, filtering, and pagination.

Home Page:https://table.sadmn.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

dBianchii opened this issue · comments

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

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?

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