djnavarro commented on PR #12154:
URL: https://github.com/apache/arrow/pull/12154#issuecomment-1169578666

   Another bug report for you @rok, sorry 😢 
   
   It looks like the temporal rounding functions in acero only respect the 
timezone when the rounding unit is `"week"` or smaller. For rounding units at 
the `"month"`, `"quarter"` and `"year"` level, it doesn't
   
   An example based on New Years in Sydney. The timestamp `ts` corresponds to 
00:00:01 January 1, 2018 AEDT, which maps to the same instant as 13:00:01 
December 31, 2017 UTC. Whenever I call `floor_temporal()` for a rounding unit 
of a week or smaller, I get the correct answer: the boundaries are expressed in 
Sydney time. The New Year in Sydney corresponds to `2017-12-31 13:00:00.000000 
UTC` and that's what we get (the print method doesn't show it, but the timezone 
is properly recorded in the metadata and `year()` correctly returns `"2018"` 
for this instant.
   
   For the larger rounding units, it looks to me like the UTC offset (+11 in 
this case) needs to be subtracted from the stored instant? They all look 
superficially like the right answer but they're all 11 hours in the future
   
   ``` r
   # one second after New Year in 2018 (happens to be Monday!)
   ts <- arrow::Scalar$create(as.POSIXct("2018-01-01 00:00:01", 
tz="Australia/Sydney"))
   
   # rounding units for week and below correctly respect timezone
   arrow::call_function("floor_temporal", ts, options = list(unit = 7L))  # day
   #> Scalar
   #> 2017-12-31 13:00:00.000000
   arrow::call_function("floor_temporal", ts, options = list(unit = 6L))  # day
   #> Scalar
   #> 2017-12-31 13:00:00.000000
   arrow::call_function("floor_temporal", ts, options = list(unit = 5L))  # hour
   #> Scalar
   #> 2017-12-31 13:00:00.000000
   arrow::call_function("floor_temporal", ts, options = list(unit = 4L))  # 
minute
   #> Scalar
   #> 2017-12-31 13:00:00.000000
   
   # rounding units for month and above don't
   arrow::call_function("floor_temporal", ts, options = list(unit = 10L)) # year
   #> Scalar
   #> 2018-01-01 00:00:00.000000
   arrow::call_function("floor_temporal", ts, options = list(unit = 9L))  # 
quarter
   #> Scalar
   #> 2018-01-01 00:00:00.000000
   arrow::call_function("floor_temporal", ts, options = list(unit = 8L))  # 
month
   #> Scalar
   #> 2018-01-01 00:00:00.000000
   ```
   
   <sup>Created on 2022-06-29 by the [reprex 
package](https://reprex.tidyverse.org) (v2.0.1)</sup>


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

Reply via email to