alamb commented on code in PR #9068:
URL: https://github.com/apache/arrow-datafusion/pull/9068#discussion_r1472659955
##########
datafusion/physical-expr/src/datetime_expressions.rs:
##########
@@ -662,8 +663,42 @@ fn _date_trunc_coarse_with_tz(
granularity: &str,
value: Option<DateTime<Tz>>,
) -> Result<Option<i64>> {
- let value = _date_trunc_coarse::<DateTime<Tz>>(granularity, value)?;
- Ok(value.and_then(|value| value.timestamp_nanos_opt()))
+ if let Some(value) = value {
+ let local = value.naive_local();
+ let truncated = _date_trunc_coarse::<NaiveDateTime>(granularity,
Some(local))?;
+ let truncated = truncated.and_then(|truncated| {
+ match truncated.and_local_timezone(value.timezone()) {
+ LocalResult::None => {
+ // This can happen if the date_trunc operation moves the
time into
+ // an hour that doesn't exist due to daylight savings. On
known example where
+ // this can happen is with historic dates in the
America/Sao_Paulo time zone.
+ // To account for this adjust the time by a few hours,
convert to local time,
+ // and then adjust the time back.
Review Comment:
Timezones continue to blow my mind
--
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]