map_vec not returning same values as map_ for dates with timezones
PaulGunsalus opened this issue · comments
Paul Gunsalus commented
purrr::map_vec is not retuning the same output as purrr::map when converting time zones.
tz <- c('America/Los_Angeles', 'America/Denver', 'America/Chicago', 'America/New_York')
dt <- as.POSIXct("13-06-2017 12:00:00 EDT", format = "%d-%m-%Y %H:%M:%S")
purrr::map_vec(tz, ~lubridate::with_tz(dt, .x))
purrr::map(tz, ~lubridate::with_tz(dt, .x))
## I would expect the object from map_vec to return something like this
v1 <- c(as.POSIXct('2017-06-13 09:00:00 PDT'), as.POSIXct('2017-06-13 10:00:00 MDT'), as.POSIXct('2017-06-13 11:00:00 CDT'), as.POSIXct('2017-06-13 12:00:00 EDT'))
This also does the same thing.
purrr::map(tz, ~lubridate::with_tz(dt, .x)) |> purrr::list_c()
Jennifer (Jenny) Bryan commented
The timezone for a POSIXct vector is a single attribute that applies to the whole object. The timezone is not something that can vary for element 1 vs, say, element 3. Since map()
returns a list of length-1 POSIXct here, each one can have its own timezone. But when you force them all to live together in a POSIXct vector, such as the return value of map_vec()
or list_c()
, there must be a common timezone attribute.
Paul Gunsalus commented
Thanks for clarifying, that makes sense.
I will close the thread.