Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upParsing single digit months #24
Comments
|
It is a shortcoming in Boost Date_Time. It just doesn't do it: R> anytime:::testFormat("%m/%d/%Y", "10/11/2016")
[1] "2016-10-11 CDT"
R> anytime:::testFormat("%m/%d/%Y", "2/3/2016")
[1] NA
R> Sadly, there is nothing we can do here. My wording is a little off on the help page but this is documented. So I'll close this, ok? The "good news" that base R does parse it:
|
|
Yes, sure. No problem. |
|
Trust me, I find it annoying as hell too. The hope for anytime was to parse all sane formats. But arguably single digit is not one. You could write a regexp which transform a single digit month or day to two and then parse that... |
|
Thank you for explanation. I'm having the same problem, but with hours (it doesn't recognize e.g 9:15, but does 09:15). |
|
Try setting the R parser which should do it: R> anytime("2018-9-20 7:24:30", useR=TRUE)
[1] "2018-09-20 07:24:30 CDT"
R> It's too bad the Boost one doesn't by default but such is life. |
|
Thank you for quick reply. Unfortunately it didn't work out for me from the 1st attempt. I didn't want to dig why, so used lubridate::parse_date_time2("dmY HM") - was also pretty fast for 2mn rows. |
|
|
|
:) thank you! you are doing really cool stuff. Unfortunately, I still do not understand all your packages, but maybe one day :) |
|
Good news - this now works in master (and hence the next release probably at the end of the month): R> inp <- c("2/10/2016", "4/4/2016", "5/8/2016", "10/1/2016")
R> library(anytime)
R> anytime(inp)
[1] "2016-02-10 CST" "2016-04-04 CDT" "2016-05-08 CDT"
[4] "2016-10-01 CDT"
R> |
I wanted to answer this question on StackOverFlow, with "anytime".
This are the dates the have, the format is: "single digit month, day, full year"
However, anydate() only works on the first entry, not the rest. In the PDF at CRAN, we find:
Issues
The Boost Date_Time library cannot parse single digit months or days. So while ‘2016/09/02’
works (as expected), ‘2016/9/2’ will not. Other non-standard formats may also fail.
The is a known issue (discussed at length in issue tick 5) where Australian times are off by an hour.
This seems to affect only Windows, not Linux.
So, apparently this is a known bug/issue. Are there anywork arounds?
Or we should just use
as.POSIXct(df$final_date, format = "%d/%m/%Y")?