[R] How to convert the timestamp without time zone type to the POSIXct type ideally?
- Dominant language
- C++
- Stars
- 17.1k
- Forks
- 4.3k
- Avg merge
- 3d 13h
- Merged PRs (30d)
- 88
Description
### Describe the bug, including details regarding any error messages, version, and platform.
The POSIXct type in R seems to behave in the absence of time zone information in such a way that it is interpreted as the time zone time in which the R session is running.
However, the arrow package does not consider the time zone of the R session when converting from the Arrow timestamp type to the POSIXct type.
``` r
library(arrow)
#>
#> Attaching package: 'arrow'
#> The following object is masked from 'package:utils':
#>
#> timestamp
Sys.setenv(TZ = "UTC")
x <- "1900-01-01"
a_a <- chunked_array(as.POSIXct(x), type = timestamp())
a_a
#> ChunkedArray
#>
#> [
#> [
#> 1900-01-01 00:00:00
#> ]
#> ]
out <- as.vector(a_a)
as.POSIXct(x)
#> [1] "1900-01-01 UTC"
unclass(as.POSIXct(x))
#> [1] -2208988800
#> attr(,"tzone")
#> [1] ""
out
#> [1] "1900-01-01 UTC"
unclass(out)
#> [1] -2208988800
Sys.setenv(TZ = "Europe/Paris")
out <- as.vector(a_a)
as.POSIXct(x)
#> [1] "1900-01-01 PMT"
unclass(as.POSIXct(x))
#> [1] -2208989361
#> attr(,"tzone")
#> [1] ""
out
#> [1] "1900-01-01 00:09:21 PMT"
unclass(out)
#> [1] -2208988800
```
Created on 2024-03-01 with [reprex v2.0.2](https://reprex.tidyverse.org)
Is there a reason why this behavior was chosen? Or is this a bug and should be fixed? (which is, of course, a breaking change).
I found this behavior in this issue (pola-rs/r-polars#875)
### Component(s)
R
Contributor guide
Assessment
This issue has not been assessed yet.