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

Parsing ISO 8601 compatible standard timestamp format (yyyy-mm-ddThh:mm:ss+-ZONE) #37

Closed
dusko opened this issue Dec 14, 2016 · 3 comments

Comments

@dusko
Copy link

dusko commented Dec 14, 2016

Is there any possibility to support ISO 8601 compatible standard timestamp format (yyyy-mm-ddThh:mm:ss+-ZONE) with timezone offset?

library(anytime)
Sys.setenv(TZ=anytime:::getTZ())      ## helper function to try to get TZ
anytime("2016-12-13T17:09:48+01:00")

> anytime("2016-12-13T17:09:48+01:00")
[1] "2016-12-12 23:00:00 UTC"

Thanks,
Dusan

@eddelbuettel
Copy link
Owner

eddelbuettel commented Dec 14, 2016

There is a function testFormat() just for that so that you can test formats:

R> anytime:::testFormat("%Y-%m-%dT%H:%M:%S%z", "2016-12-13T17:09:48+01:00")
[1] "2016-12-13 17:09:48 CST"
R> anytime:::testFormat("%Y-%m-%dT%H:%M:%S%z", "2016-12-13T17:09:48-03:00")
[1] "2016-12-13 17:09:48 CST"
R> 

As you can see, the date is parsed (good, and better than what we have now) but the actual tz argument is always ignored -- and that is documented -- which is bad.

But yes, ISO is good. I will add some variants. Luckily this seems tolerant to with/without T and seems to equally ignore tz suffixes of the -0000 and -00:00 variants.

@eddelbuettel
Copy link
Owner

Ok, I just added it, with this test block:

cat("\n") # ISO 8601 variants, note that TZ field is always ignored, see Boost documentation
anytime(c("2016-09-01T10:11:12-05:00", "2016-09-01T10:11:12.345678-05:00"))
anytime(c("2016-09-01T10:11:12-0500",  "2016-09-01T10:11:12.345678-0500"))
anytime(c("2016-09-01T10:11:12 CDT",   "2016-09-01T10:11:12.345678 CDT"))

The wierd thing is that the ones on the right were already being parsed in the just-release 0.1.2. Now we also get the ones on the left which is good.

@dusko
Copy link
Author

dusko commented Dec 25, 2016

Thank you very much! Works great in version 0.2.0.

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