dosubot[bot] commented on issue #40871: URL: https://github.com/apache/superset/issues/40871#issuecomment-4653029104
<!-- Answer --> Hi @KRILabs01! I'm [Dosu](https://go.dosu.dev/dosubot) and I'm helping the Apache Superset team. This is a confirmed architectural issue with how the "Hours Offset" feature interacts with time grain grouping. The root cause is the **order of operations**: 1. **Time grain truncation happens first** at the SQL/database layer (e.g., `DATETRUNC(day, col)` for MSSQL), which groups timestamps to midnight boundaries [[1]](https://github.com/apache/superset/blob/829e4d92d91ceae4b43b1ed3b063ffe45377799c/superset/models/helpers.py#L1694-L1697) 2. **Hours offset is applied second** in post-processing via Python after results are returned: `df[col] += timedelta(hours=offset)` [[2]](https://github.com/apache/superset/blob/829e4d92d91ceae4b43b1ed3b063ffe45377799c/superset/utils/core.py#L1708-L1709) So with a -4 offset and "day" grain, the database first truncates `2026-06-02 12:57:16` → `2026-06-02 00:00:00`, then the offset shifts it to `2026-06-01 20:00:00`. This is why your day buckets start at 8pm instead of midnight — the offset should ideally be applied to raw timestamps *before* truncation, but the current architecture does it afterward. This has been partially tracked in [issue #23167](https://github.com/apache/superset/issues/23167), and [PR #37698](https://github.com/apache/superset/pull/37698) attempted to address inconsistencies in offset application, but it was closed without being merged. No comprehensive fix for the offset + time grain interaction has landed yet. **Possible workaround:** Instead of using the dataset's Hours Offset feature, you could create a calculated column in your dataset that applies the timezone conversion directly in SQL (e.g., `DATEADD(hour, -4, your_timestamp_col)` for MSSQL). This way, the offset is baked into the column *before* Superset applies time grain truncation, and day boundaries will align correctly to midnight in your target timezone. <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=reply-with-mention&utm_term=apache%2Fsuperset).* --- Docs are dead. Just use [Dosu](https://dosu.dev?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=static-docs-tagline&utm_term=apache%2Fsuperset). [](https://app.dosu.dev/response-feedback?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=static-docs-feedback&utm_term=apache%2Fsuperset&message_id=fa42ff9a-61e4-4a06-ae8c-589441e9f50b) [](https://github.dosu.com/apache/superset?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=static-docs-ask-repo&utm_term=apache%2Fsuperset) [](https://app.dosu.dev/signup?referrer=openSource&source=github-footer&utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=static-docs-share-team&utm_term=apache%2Fsuperset) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
