You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "tustvold (via GitHub)" <gi...@apache.org> on 2023/05/11 12:15:05 UTC

[GitHub] [arrow-rs] tustvold commented on pull request #4201: Fix incorrect cast Timestamp with Timezone

tustvold commented on PR #4201:
URL: https://github.com/apache/arrow-rs/pull/4201#issuecomment-1543889159

   Thank you for this, I'm not sure this logic is correct, however.
   
   If both quantities have timezones, no adjustment should be necessary, as they are already normalized to UTC.
   
   The complexity arises when converting between timestamps where one doesn't have a timezone. This requires some care, especially to handle timezones that don't have fixed offsets.
   
   In the forward direction I think this involves doing something like
   
   ```
   let from_tz = from_tz.parse()?;
   array.unary_opt(|i| {
       T::make_value(as_datetime_with_timezone(i, from_tz)?.naive_local())
   })
   ```
   
   And in the reverse direction
   
   ```
   let to_tz = to_tz.parse()?;
   array.unary_opt(|i| {
       let local = as_datetime(i);
       let offset = to_tz.offset_from_local_datetime(&local).single()?;
       T::make_value(local + offset.fix())
   })
   ```


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org