Repository navigation
docs: explain date_bin daylight saving behavior #26041
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2472,6 +2472,8 @@ Calculates time intervals and returns the start of the interval nearest to the s | |
|
|
||
| For example, if you "bin" or "window" data into 15 minute intervals, an input timestamp of `2023-01-01T18:18:18Z` will be updated to the start time of the 15 minute bin it is in: `2023-01-01T18:15:00Z`. | ||
|
|
||
| Bins are anchored to an origin instant (the UNIX epoch by default); an origin does not adjust for daylight saving time. For example, a bin aligned to midnight in `America/Denver` can shift to 01:00 after the spring daylight saving transition. Use `date_trunc` for calendar units such as local days. To bin other intervals on local wall-clock boundaries, convert the timestamp with `to_local_time(expression AT TIME ZONE '<zone>')` before calling `date_bin`, then apply `AT TIME ZONE` to the result if a timezone-aware timestamp is needed. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider specifying a |
||
|
|
||
| ```sql | ||
| date_bin(interval, expression[, origin_timestamp]) | ||
| ``` | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As an optional follow-up, consider adding a before/after-DST comparison to
datafusion/sqllogictest/test_files/datetime/timestamps.slt. With origin2024-01-01T00:00:00-07:00, daily instant bins for Denver local noon on March 9 and March 11 start at00:00-07:00and01:00-06:00, whiledate_trunc('day', ...)and wall-clock binning with timezone reattachment should preserve local midnight. The existing tests at lines 4536–4545 already cover the conversion recipe, so the value would be explicitly testing the DST contrast. This is not required for this documentation-only PR.