Skip to content

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

@ClaytonJY

Description

@ClaytonJY

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behaviorwipwork in progress

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions