superset icon indicating copy to clipboard operation
superset copied to clipboard

Custom time filter "Now" uses UTC now as local time

Open alexanderkoek opened this issue 1 year ago • 1 comments

Bug description

When using a time filter of type "Custom" and select "Specific Date/Time" and click on "now" I get the correct timestamp in local time. image

However, when I select "Now" as time, the system selects the current time as UTC and not in the correct timezone. image

In the Netherlands in summer time this means that the time is 2 hours behind (I clicked on the Now button around 14:59, but time is shown as 12:59), causing me to miss two hours of the most recent data: image

Please, make sure the "Now" is implemented taking the correct timezone into account.

Screenshots/recordings

No response

Superset version

master / latest-dev

Python version

3.9

Node version

16

Browser

Chrome

Additional context

No response

Checklist

  • [X] I have searched Superset docs and Slack and didn't find a solution to my problem.
  • [X] I have searched the GitHub issue tracker and didn't find a similar bug report.
  • [ ] I have checked Superset's logs for errors and if I found a relevant Python stacktrace, I included it here as text in the "additional context" section.

alexanderkoek avatar Oct 16 '24 13:10 alexanderkoek

Hello @alexanderkoek! I'm here to help you with any bugs, questions, or contributions you have for the project. Let's take a look at the issue you've reported and see how we can solve it together.

The issue you're experiencing with the "Now" button in the time filter not accounting for the correct timezone is known. The expected behavior is for the "Now" button to return the current date and time adjusted to the specified timezone. Tests indicate that when 'now' is used, the function parseDttmToDate should return the current date and time in the specified timezone, such as 'Etc/GMT-2' for the Netherlands during summer time [1].

The logic for handling the 'Now' button is implemented in the CustomFrame component within the file superset-frontend/src/explore/components/controls/DateFilterControl/components/CustomFrame.tsx. The onAnchorMode function updates the anchorValue to 'now' when the 'Now' button is selected [2].

It seems like there might be an issue with how the timezone is being applied when using the "Now" button. You might want to check if the timezone settings are correctly configured in your environment or if there are any updates or patches available that address this issue.

To continue talking to Dosu, mention @dosu.

dosubot[bot] avatar Oct 16 '24 13:10 dosubot[bot]

I have the same issue

hardstuding avatar Oct 24 '24 03:10 hardstuding

@dosu I have the same problem, how to solve it? I have version 4.0.2 Suprset is running in a container, it has my timezone set, but Suprset has UTC time

Alexeyalexeyalex avatar Nov 06 '24 11:11 Alexeyalexeyalex

@alexanderkoek Were you able to fix the problem?

Alexeyalexeyalex avatar Nov 06 '24 11:11 Alexeyalexeyalex

@hardstuding Were you able to fix the problem?

Alexeyalexeyalex avatar Nov 06 '24 11:11 Alexeyalexeyalex

No, I did not solve it

alexanderkoek avatar Nov 06 '24 12:11 alexanderkoek

The issue with the "Now" button using UTC instead of the local timezone is a known limitation in Superset. Superset has implicit assumptions that timestamps are in UTC, which can lead to discrepancies when using features like the "Now" button in time filters [1].

To address this, you can try configuring the timezone in your Superset environment to ensure it matches your desired local timezone. This involves setting the timezone for both the Superset backend and the database engine to ensure consistency. It's recommended to use UTC for both to avoid issues, but if you need to use a local timezone, ensure that both are configured accordingly [1].

Additionally, you can use the TimezoneSelector component to select and apply the local timezone dynamically in the frontend. This component allows users to choose from a list of timezones, ensuring that Superset uses the correct timezone for data visualization and exploration [2].

If the issue persists, you may need to check for any updates or patches that address this specific problem in your version of Superset.

To continue talking to Dosu, mention @dosu.

dosubot[bot] avatar Nov 06 '24 12:11 dosubot[bot]

@dosu changed the value in DEFAULT_TIMEZONE in index.tsx did not help tried to rewrite the code in CustomFrame.tsx also did not help please help

gg

Alexeyalexeyalex avatar Nov 12 '24 09:11 Alexeyalexeyalex

I believe the setting you are looking for is covered in this commit: #23014

AstralBlader avatar Dec 05 '24 21:12 AstralBlader

The linked PR needs to be rebased in order to be mergeable. This thread has been quiet for quite some time, though, so I wondered if it's still an issue, or if something else relevant was changed along the way?

rusackas avatar Apr 29 '25 15:04 rusackas

To resolve the issue of the "Now" button using UTC instead of the local timezone, you need to ensure that the useLocalTime parameter is set to true when calling the createUtils function in the d3Time.ts file. This will switch the time intervals from UTC to local time.

Here's the relevant code snippet:

function createUtils(useLocalTime = false) {
  // ... other code ...
  if (useLocalTime) {
    // Use local time intervals
    floorSecond = timeSecond;
    floorMinute = timeMinute;
    floorHour = timeHour;
    floorDay = timeDay;
    floorWeek = timeWeek;
    floorWeekStartOnSunday = timeSunday;
    floorWeekStartOnMonday = timeMonday;
    floorWeekStartOnTuesday = timeTuesday;
    floorWeekStartOnWednesday = timeWednesday;
    floorWeekStartOnThursday = timeThursday;
    floorWeekStartOnFriday = timeFriday;
    floorWeekStartOnSaturday = timeSaturday;
    floorMonth = timeMonth;
    floorYear = timeYear;
  } else {
    // Use UTC time intervals
    floorSecond = utcSecond;
    floorMinute = utcMinute;
    floorHour = utcHour;
    floorDay = utcDay;
    floorWeek = utcWeek;
    floorWeekStartOnSunday = utcSunday;
    floorWeekStartOnMonday = utcMonday;
    floorWeekStartOnTuesday = utcTuesday;
    floorWeekStartOnWednesday = utcWednesday;
    floorWeekStartOnThursday = utcThursday;
    floorWeekStartOnFriday = utcFriday;
    floorWeekStartOnSaturday = utcSaturday;
    floorMonth = utcMonth;
    floorYear = utcYear;
  }
}

Ensure that when you call createUtils, you pass true for useLocalTime:

const timeUtils = createUtils(true);

This change should make the "Now" button use the local timezone instead of UTC [1].

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other

dosubot[bot] avatar Apr 29 '25 15:04 dosubot[bot]

@Alexeyalexeyalex any success you had with this issue ?

neeravsalaria avatar May 08 '25 05:05 neeravsalaria

This timezone issue has been confirmed by multiple users and remains unresolved.

Current status: PR #23014 exists but needs rebasing to be mergeable.

The core issue is that the "Now" button in time filters uses UTC instead of respecting the user's local/configured timezone. This causes users to miss recent data when their timezone is ahead of UTC.

Next steps needed:

  1. Rebase PR #23014, or
  2. A new PR implementing the fix in CustomFrame.tsx to use local time when appropriate

Can the original PR author or a contributor pick this up? The fix location has been identified (superset-frontend/src/explore/components/controls/DateFilterControl/components/CustomFrame.tsx).

rusackas avatar Dec 11 '25 21:12 rusackas