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

Vectorised force_tz() #438

Closed
hadley opened this issue Jul 27, 2016 · 10 comments
Closed

Vectorised force_tz() #438

hadley opened this issue Jul 27, 2016 · 10 comments

Comments

@hadley
Copy link
Member

@hadley hadley commented Jul 27, 2016

At a minimum, this should be an error:

force_tz(rep(now(), 2), c("US/Eastern", "US/Central"))

But ideally, it would allow you to combine a vector of times with a vector of times, as when a dataset records local times and you want to standardise.

@vspinu
Copy link
Member

@vspinu vspinu commented Jul 27, 2016

Why is this needed? If you know your groups you can map by groups yourself.

This would go against all other functions which don't vectorize over TZ and will give wrong hints to folks who ask multiple tzs within a vector.

@hadley
Copy link
Member Author

@hadley hadley commented Jul 27, 2016

Obviously I can do that, but it's pretty tough challenge for most people. It's a not uncommon to have a vector of local times that you need to fix.

I think it's reasonable to vectorise tz here in the same way it's reasonable to vectorise hour, minute etc in the appropriate settors + update().

@vspinu
Copy link
Member

@vspinu vspinu commented Jul 28, 2016

This one is likely to be challenging. The update code is already quite complex as it tries to cut edges whenever possible.

@zyxdef
Copy link

@zyxdef zyxdef commented May 3, 2017

Can this become a feature request?

@vspinu
Copy link
Member

@vspinu vspinu commented May 3, 2017

I am looking at this right now. Trying to put CCTZ to do some work here.

@vspinu
Copy link
Member

@vspinu vspinu commented May 3, 2017

Folks, vectorized force_tz doesn't make sense. tz argument indicates the time zone of the output vector, but in R vectors cannot have heterogeneus time zone. Could you please elaborate on the exact semantics that you had in mind?

@hadley
Copy link
Member Author

@hadley hadley commented May 3, 2017

I think what I actually want is more like local_time(datetimes, timezones), and feel like maybe it's more natural in hms.

@vspinu
Copy link
Member

@vspinu vspinu commented May 3, 2017

I see, that could be straightforwardly done with CCTZ. Will look into it. We need local_time function anyways.

@gregmacfarlane
Copy link

@gregmacfarlane gregmacfarlane commented Jul 13, 2017

Here's a stack overflow questions detailing the precise problem and why a solution of some kind would be useful: https://stackoverflow.com/questions/33848563/with-tz-with-a-vector-of-timezones/33848764

@vspinu
Copy link
Member

@vspinu vspinu commented Oct 4, 2017

Just added two functions, force_tzs and local_time, both verctorized on the time zone argument. See the docs for more details and usage examples.

@gregmacfarlane, the SO questions looks for vectorized with_tz. Is that really what you want? with_tzs could be added for completeness, but one should be aware that time zone of the returned vector is meaningless.

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

Successfully merging a pull request may close this issue.

None yet
4 participants