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

Support parsing year only dates #407

Merged
merged 2 commits into from
Jun 3, 2016
Merged

Support parsing year only dates #407

merged 2 commits into from
Jun 3, 2016

Conversation

jeroen
Copy link
Contributor

@jeroen jeroen commented May 13, 2016

Support parsing a year-only e.g. %Y format:

read_csv("x,y\n2014,2014\n", col_types = list(col_date("%Y"), col_datetime("%Y")))

It's a bit of an edge case, but if the user specifically sets the format to %Y this should work.

@hadley
Copy link
Member

hadley commented Jun 1, 2016

This will also make parse_datetime("2010-01", "%Y-%m"), work, right?

I think it also needs some documentation somewhere explaining that missing month and day will be set to 1, and missing hour, minute, and second will be set to 0.

@@ -81,6 +81,10 @@ test_that("ISO8601 partial dates are not parsed", {
expect_equal(n_problems(parse_datetime("2001-01")), 1)
})

test_that("Year only gets parsed", {
expect_equal(parse_datetime("2010", "%Y"), r_parse("2010-01-01", "%Y-%m-%d"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe better to compare to ISODate(2010, 01, 01)?

@hadley hadley added ready and removed ready labels Jun 1, 2016
@jeroen
Copy link
Contributor Author

jeroen commented Jun 3, 2016

OK I have updated the PR. Related: currently year_ defaults to -1 which is kind of odd:

parse_date('10-10', '%m-%d')

We should probably either default to 1970 or make it required.

@hadley
Copy link
Member

hadley commented Jun 3, 2016

Yeah, that should be an error. Want to tackle it while you're in there?

@jeroen
Copy link
Contributor Author

jeroen commented Jun 3, 2016

OK done (in this same pr)

@hadley hadley merged commit e41bc7e into tidyverse:master Jun 3, 2016
@hadley hadley removed the in progress label Jun 3, 2016
@sbearrows sbearrows mentioned this pull request Mar 7, 2022
1 task
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

Successfully merging this pull request may close these issues.

2 participants