Open
Description
openedon Feb 27, 2023
write_csv
removes the time zone information from the POSIXlt values in tibble and appends Z to the output.
> version
_
platform x86_64-w64-mingw32
arch x86_64
os mingw32
crt ucrt
system x86_64, mingw32
status
major 4
minor 2.2
year 2022
month 10
day 31
svn rev 83211
language R
version.string R version 4.2.2 (2022-10-31 ucrt)
nickname Innocent and Trusting
> library(readr)
> packageVersion("readr")
[1] ‘2.1.4’
> library(tibble)
> packageVersion("tibble")
[1] ‘3.1.8’
> Sys.timezone()
[1] "Asia/Tokyo"
> dt <- "2000/01/01 09:00:00"
> dt.ct <- as.POSIXct(dt, tz=Sys.timezone())
> dt.ct
[1] "2000-01-01 09:00:00 JST"
> dt.lt <- as.POSIXlt(dt, tz=Sys.timezone())
> dt.lt
[1] "2000-01-01 09:00:00 JST"
> df <- data.frame(ct=dt.ct, lt=dt.lt)
> df
ct lt
1 2000-01-01 09:00:00 2000-01-01 09:00:00
> tbl <- tibble(ct=dt.ct, lt=dt.lt)
> tbl
# A tibble: 1 × 2
ct lt
<dttm> <dttm>
1 2000-01-01 09:00:00 2000-01-01 09:00:00
> write_csv(df, "write_csv_df.csv")
> readLines("write_csv_df.csv")
[1] "ct,lt"
[2] "2000-01-01T00:00:00Z,2000-01-01T00:00:00Z"
> write_csv(tbl, "write_csv_tbl.csv")
> readLines("write_csv_tbl.csv")
[1] "ct,lt"
[2] "2000-01-01T00:00:00Z,2000-01-01T09:00:00Z"
"2000-01-01 09:00:00 JST" equals "2000-01-01 00:00:00Z".
However, when using tibble, the POSIXlt value of "2000-01-01 09:00:00 JST" is output as "2000-01-01 09:00:00Z".
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment