evidence-dev / evidence

Business intelligence as code: build fast, interactive data visualizations in pure SQL and markdown
https://evidence.dev
MIT License
4.13k stars 196 forks source link

[Bug]: Date range selector returns range offset by one day #2449

Open martonmesz opened 4 weeks ago

martonmesz commented 4 weeks ago

Describe the bug

When I select the start and end date in the date range selector, the returned values are offset by one day.

Steps to Reproduce

  1. Create a simple date selector as below:

    <DateRange
    name=date_range
    />
  2. Write a simple query that returns the selected values as strings

    sql test
    select
    '${inputs.date_range.start}' as start,
    '${inputs.date_range.end}' as end
  3. Examine the returned values

Logs

No response

System Info

System:
    OS: macOS 13.6.4
    CPU: (4) x64 Intel(R) Core(TM) i7-7660U CPU @ 2.50GHz
    Memory: 102.20 MB / 8.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.16.0 - /usr/local/bin/node
    npm: 10.8.1 - /usr/local/bin/npm
  Browsers:
    Chrome: 127.0.6533.120
    Safari: 17.3
  npmPackages:
    @evidence-dev/bigquery: ^2.0.7 => 2.0.7 
    @evidence-dev/core-components: ^4.7.2 => 4.7.2 
    @evidence-dev/csv: ^1.0.12 => 1.0.12 
    @evidence-dev/databricks: ^1.0.7 => 1.0.7 
    @evidence-dev/duckdb: ^1.0.11 => 1.0.11 
    @evidence-dev/evidence: ^39.1.1 => 39.1.1 
    @evidence-dev/motherduck: ^1.0.2 => 1.0.2 
    @evidence-dev/mssql: ^1.0.9 => 1.0.9 
    @evidence-dev/mysql: ^1.1.3 => 1.1.3 
    @evidence-dev/postgres: ^1.0.6 => 1.0.6 
    @evidence-dev/snowflake: ^1.1.0 => 1.1.0 
    @evidence-dev/sqlite: ^2.0.6 => 2.0.6 
    @evidence-dev/trino: ^1.0.7 => 1.0.7

Severity

serious, but I can work around it

Additional Information, or Workarounds

I tagged this as serious because users might not even notice if the range selector returns an incorrect range behind the scenes. There was an initial discussion on Slack where people suggested this is a timezone issue. If that's the case and the offset depends on the user's timezone then there is no easy fix like manually countering the offset. Workaround is to not use this feature.

martonmesz commented 4 weeks ago

Based on info from @hughess on Slack, an upcoming Timezone support should fix this.

The date selector has to have a timestamp behind the scenes, so it uses midnight and assumes your dates are all in UTC timezone. This doesn’t make a difference if you’re in a timezone west of UTC, but causes the date to shift one day back if you are in a timezone east of UTC This should be solved by the timezone support we’re working on

I also checked and the problem is only present in timezones east of UTC.