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

[GitHub] [arrow] jorisvandenbossche commented on a diff in pull request #35671: GH-35633: [R] R builds failing with error 'Invalid: Timestamps already have a timezone: 'UTC'. Cannot localize to 'UTC''

jorisvandenbossche commented on code in PR #35671:
URL: https://github.com/apache/arrow/pull/35671#discussion_r1203809343


##########
r/R/dplyr-funcs-datetime.R:
##########
@@ -61,12 +61,14 @@ register_bindings_datetime_utility <- function() {
         tz <- Sys.timezone()
       }
 
-      # if a timestamp does not contain timezone information (i.e. it is
+      # If a timestamp does not contain timezone information (i.e. it is
       # "timezone-naive") we can attach timezone information (i.e. convert it into
       # a "timezone-aware" timestamp) with `assume_timezone`
       # if we want to cast to a different timezone, we can only do it for
-      # timezone-aware timestamps, not for timezone-naive ones
-      if (!is.null(tz)) {
+      # timezone-aware timestamps, not for timezone-naive ones.
+      # strptime in Acero will return a timezone-aware timestamp if %z is
+      # part of the format string.
+      if (!is.null(tz) && !grepl("%z", format, fixed = TRUE)) {

Review Comment:
   I don't understand how timezones work in R (and with POSIXlt and POSIXct), but with the above change, the `tz` keyword will just be ignored when the string includes an offset? 
   
   That doesn't match fully what base R does:
   
   ```
   > strptime("2020-05-01T00:00+0100", format="%Y-%m-%dT%H:%M%z")
   [1] "2020-05-01 01:00:00"
   > strptime("2020-05-01T00:00+0100", format="%Y-%m-%dT%H:%M%z", tz="US/Eastern")
   [1] "2020-04-30 19:00:00"
   ```
   
   (but again, I don't really know how to interpret those returned values, and whether they are tz "aware" or "native" or even if those concepts even exist in R. I looked at the `$zone` and `$gmtoff` attributes of the above return values, but can't make sense of it)



-- 
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