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

Wrongfully recognition with %m/%d/%y #74

Closed
Wistarr opened this issue Feb 26, 2018 · 4 comments
Closed

Wrongfully recognition with %m/%d/%y #74

Wistarr opened this issue Feb 26, 2018 · 4 comments

Comments

@Wistarr
Copy link

Wistarr commented Feb 26, 2018

I want to convert strings that are formatted as such 01/15/17 (January 15th 2017). But when I add the %m/%d/%y formats, it recognises random strings as date.

library(anytime)
string <- "121013_3_1"
anytime(string) #NA

addFormats(c("%m/%d/%y"))
anytime(string) #1999-12-01 UTC

Interestingly, it seems like many characters are actually ignored.

vector <- c("121013_3_1", "1210111", "12z01z_3_1", "121013_3$1")
all(anytime(vector) == "1999-12-01 UTC") #TRUE

Is there another more specific format I could use?

@eddelbuettel
Copy link
Owner

I am not sure what you are expecting. anytime() and anydate() test a fairly large, known, and documented set of formats as a convenience.

If you have an obscure new format, use as.Date() with the format string. If need, loop over several inputs with several formats.

As for %y : I recommend against, just how I recommend against non-iso8661 formats (but living where I do I grudgingly accept the m-d-y variant).

I plan to close this unless you manage to convince that there is shortcoming in anytime() vis a vis its documented behaviour. So far we mostly have you wishing for something we never said we'd do.

@eddelbuettel
Copy link
Owner

Also

R> library(anytime)
R> anytime::addFormats("%m/%d/%y %H:%M:%S")
R> anytime("03/04/05 06:07:08")
[1] "2005-03-04 06:07:08 CST"
R> 

So I am not sure what the question is here.

@Wistarr
Copy link
Author

Wistarr commented Feb 27, 2018

I think %m/%d/%y %H:%M:%S was the answer I was looking for. It make the recognition much more precise and resolve the issue I stated.

@Wistarr Wistarr closed this as completed Feb 27, 2018
@eddelbuettel
Copy link
Owner

Yes, while writing it I realized you may "simply" have confused the formats between anytime() (needs hour/min/sec) and anydate() (does not). All good then.

And yes, executive decision at my end to prefer four-digit years so the default formats are all with %Y.

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

No branches or pull requests

2 participants