ISO8601 Analysis in R

Are there any existing implementations in R for parsing ISO8601 strings into POSIXt objects? The ISO8601 specification allows you to print dates / times in various (non-overlapping) formats, so you may need to do some regular expression magic to determine the format and serve that to strptime .

Doing this correctly can be quite complicated , however, what discovers the most common formats will already be very useful. I cannot imagine that I am the first to come across this, but it is difficult for me to find good implementations.

+8
date datetime r posixct
source share
4 answers

Strictly speaking, you cannot. I don’t need to know anything about r or cran (or even that they are) to tell you about it, because I know ISO 8601 well enough to know that I just know something, that ISO 8601 is not enough, to know clearly what it means to them, especially in shorter forms.

Find out which ISO 8601 profile the other party is using. If they do not know what you are talking about, then you will do them a favor when you indicate what I just said in the paragraph above. As I wrote once in another place,

Unfortunately, many people think about a specific profile that they are familiar with when they hear "ISO 8601", other people know that using 8601 is a good thing, but they are not familiar with implementation details. Consequently, a specification or requirements document may mention 8601, but no more explicit than that. In such cases, it is important to seek clarification rather than suggesting that the format you consider β€œISO 8601” is the right one to use.

So tell them that "ISO 8601" is not specific enough, I need to know exactly what you are doing, what are your limitations on accuracy. "(And maybe your policy regarding dates before 1582 and possibly before 0001, your jump-second policy and a few other things remain open, but standard)

Then what you are dealing with should be fairly simple: besides this point of ambiguity, this is a fairly simple standard. It should simply be seen as a standard for defining date formats, more than one that defines the date format.

+6
source share

See .parseISO8601 in the xts package for one implementation. I doubt it will work out of the box, but it should give you an idea of ​​how to realize your specific needs.

+3
source share

This looks promising: http://cran.r-project.org/web/packages/parsedate

parsedate: recognize and analyze dates in various formats, including all ISO 8601 formats

Parsing dates automatically without needing to specify a format. Currently, it includes a git date parser. It can also recognize and analyze all ISO 8601 formats.

+2
source share
 t <- strptime("2013-08-20T14:56:37", "%FT%T") 

worked well enough for me in most cases. It already fails for a split second, although it does not include the solution to all the problems that John Hannah spoke about. (And that make working with time data types so incredibly difficult.)

-one
source share

All Articles