Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

map_vec not returning same values as map_ for dates with timezones #1112

Closed
PaulGunsalus opened this issue Nov 29, 2023 · 2 comments
Closed

Comments

@PaulGunsalus
Copy link

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()
@jennybc
Copy link
Member

jennybc commented Nov 29, 2023

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.

@PaulGunsalus
Copy link
Author

Thanks for clarifying, that makes sense.

I will close the thread.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants