Sys.timeDate takes local time zone if converted to dataframe ? Probably a bug ?

Why does the SYs.timeDate considers local time if converted to dataframe ?

timeDate::Sys.timeDate(FinCenter = "America/Mexico_City")
America/Mexico_City
[1] [2019-11-28 03:31:07]

(timestamp = timeDate::Sys.timeDate(FinCenter = "America/Mexico_City")) %>%
+           as.data.frame()
  America/Mexico_City:.
1   2019-11-28 09:31:30

The short answer is that Sys.timeDate is no longer responsible for parsing:

library(timeDate)
# default is GMT
timeDate(Sys.time())
#> GMT
#> [1] [2019-11-28 22:15:33]
# CST
timeDate(Sys.time(), FinCenter = "America/Mexico_City")
#> America/Mexico_City
#> [1] [2019-11-28 16:15:33]
# assign to an object for inspection
timestamp <- timeDate(Sys.time(), FinCenter = "America/Mexico_City")
str(timestamp)
#> Formal class 'timeDate' [package "timeDate"] with 3 slots
#>   ..@ Data     : POSIXct[1:1], format: "2019-11-28 22:15:33"
#>   ..@ format   : chr "%Y-%m-%d %H:%M:%S"
#>   ..@ FinCenter: chr "America/Mexico_City"
# convert to data frame for inspection
df. <- as.data.frame(timestamp)
df.
#>   America/Mexico_City:timestamp
#> 1           2019-11-28 22:15:33
str(df.)
#> 'data.frame':    1 obs. of  1 variable:
#>  $ America/Mexico_City:timestamp: POSIXct, format: "2019-11-28 22:15:33"
#>  - attr(*, "control")= Named chr "America/Mexico_City"
#>   ..- attr(*, "names")= chr "FinCenter"
# convert to a tibble for inspection
tib <- tibble::enframe(timestamp)
tib
#> # A tibble: 1 x 2
#>    name value              
#>   <int> <timeDate>         
#> 1     1 2019-11-28 16:15:33
str(tib)
#> Classes 'tbl_df', 'tbl' and 'data.frame':    1 obs. of  2 variables:
#>  $ name : int 1
#>  $ value:Formal class 'timeDate' [package "timeDate"] with 3 slots
#>   .. ..@ Data     : POSIXct, format: "2019-11-28 22:15:33"
#>   .. ..@ format   : chr "%Y-%m-%d %H:%M:%S"
#>   .. ..@ FinCenter: chr "America/Mexico_City"

Created on 2019-11-28 by the reprex package (v0.3.0)

1 Like

Enframing with tibble before converting to dataframe is the solution

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.