Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
dBianchii opened this issue May 10, 2024 · 5 comments

Comments

@dBianchii
Copy link
Contributor

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

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
Copy link
Owner

sadmann7 commented Jun 2, 2024

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
Copy link
Contributor Author

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
Copy link
Owner

sadmann7 commented Jun 3, 2024

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
Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants