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

character method for as_date forces `tz` arg when `format` present, doesn't use it #674

Closed
ClaytonJY opened this issue May 17, 2018 · 3 comments · Fixed by #817
Closed

character method for as_date forces `tz` arg when `format` present, doesn't use it #674

ClaytonJY opened this issue May 17, 2018 · 3 comments · Fixed by #817
Labels

Comments

@ClaytonJY
Copy link

@ClaytonJY ClaytonJY commented May 17, 2018

If you try to convert a string using lubridate::as_date while specifying the format, you must also set tz, but it isn't used.

library(lubridate)
#> 
#> Attaching package: 'lubridate'
#> The following object is masked from 'package:base':
#> 
#>     date

x <- "05172018"

as_date(x)
#> Warning: All formats failed to parse. No formats found.
#> [1] NA

as_date(x, format = "%m%d%Y")
#> Error in strptime(x, format, tz): invalid 'tz' value

as_date(x, tz = "America/New_York", format = "%m%d%Y")
#> [1] "2018-05-17"

tz(.Last.value)
#> [1] "UTC"

Current Github version, 1.7.4.

On the one hand, this is unexpected, surprising behavior, but on the other hand, do timezones ever matter for Date's?

In the very least, seems like you shouldn't need the tz arg here; the second option should work.

@vspinu

This comment has been minimized.

Copy link
Member

@vspinu vspinu commented May 18, 2018

Indeed, should be fixed.

as_date is not an idiomatic parser btw. Use mdy for this particular case.

@ClaytonJY

This comment has been minimized.

Copy link
Author

@ClaytonJY ClaytonJY commented Jun 3, 2018

per discussion on #675 should as_date have its tz arg removed?

@hadley

This comment has been minimized.

Copy link
Member

@hadley hadley commented Nov 19, 2019

Minimal reprex:

library(lubridate, warn.conflicts = FALSE)
x <- "05172018"

as_date(x)
#> Warning: All formats failed to parse. No formats found.
#> [1] NA

as_date(x, format = "%m%d%Y")
#> Error in strptime(x, format, tz): invalid 'tz' value

as_date(x, tz = "America/New_York", format = "%m%d%Y")
#> [1] "2018-05-17"

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

hadley added a commit that referenced this issue Nov 19, 2019
Fixes #674
@hadley hadley added bug wip labels Nov 19, 2019
@vspinu vspinu closed this in #817 Dec 7, 2019
vspinu added a commit that referenced this issue Dec 7, 2019
* Ignore tz argument in as_date()

Fixes #674
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.