Custom time filter "Now" uses UTC now as local time
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.
However, when I select "Now" as time, the system selects the current time as UTC and not in the correct timezone.
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:
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.
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.
I have the same issue
@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
@alexanderkoek Were you able to fix the problem?
@hardstuding Were you able to fix the problem?
No, I did not solve it
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.
@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
I believe the setting you are looking for is covered in this commit: #23014
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?
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
@Alexeyalexeyalex any success you had with this issue ?
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:
- Rebase PR #23014, or
- A new PR implementing the fix in
CustomFrame.tsxto 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).