Revision as of 01:45, 17 February 2016 by Jbfaden (Talk | contribs)
(diff) ←Older revision | Current revision (diff) | Newer revision→ (diff)
Jump to: navigation, search


  1. Introduction
  2. Interface
  3. Examples
  4. To Consider
  5. Implementations

1. Introduction

This page proposes a standard and complete parser for ISO8601 times and time intervals as specified in This parser should be language-agnostic, so that it can easily be implemented in Python, Matlab, IDL, C, Java, and Javascript. We present a list of examples and the correct interpretation as well, to serve as a reference for implementations.

2. Interface

parseISO8601( String ) -> int[14]

where index i represents:

0 Year
1 Month
2 Day
3 Hour
4 Minute
5 Second
6 Nanoseconds
7 Year of the interval end
8 Month
9 Day
10 Hour
11 Minute
12 Second
13 Nanoseconds

There should also be a convenient y,m,d to y,doy

3. Examples

The following is a table of particular and canonical representations.

"2000-01-01T13:00Z/PT1H"                    "2000-01-01T13:00Z/2000-01-01T14:00Z"
"20000101T1300Z/PT1H"                       "2000-01-01T13:00Z/2000-01-01T14:00Z"
"2000-01-01T00:00Z/P1D"                     "2000-01-01T00:00Z/2000-01-01T24:00Z"
"2007-03-01T13:00:00Z/P1Y2M10DT2H30M"       "2007-03-01T13:00:00Z/2008-05-11T15:30:00Z"
"2007-03-01T13:00:00Z/2008-05-11T15:30:00Z" "2007-03-01T13:00:00Z/2008-05-11T15:30:00Z"
"P1Y2M10DT2H30M/2008-05-11T15:30:00Z"       "2007-03-01T13:00:00Z/2008-05-11T15:30:00Z"
"2007-009/2007-021"                         "2007-01-09T00:00:00Z/2007-01-21T00:00:00Z"
"2007-05-15/2007-05-30"                     "2007-05-15T00:00:00Z/2007-05-30T00:00:00Z"
"2007-03-01/P5D"                            "2007-03-01T00:00:00Z/2007-03-06T00:00:00Z"
"P5D/2007-03-06"                            "2007-03-01T00:00:00Z/2007-03-06T00:00:00Z"
"2000-01-01T13:00/PT1H"                     "2000-01-01T13:00:00Z/2000-01-01T14:00:00Z"

"2012/P1Y"                                  "2012-01-01/2013-01-01"
"2012/P1M"                                  "2012-01-01/2012-02-01"
"2012-01-01/P1M"                            "2012-01-01/2012-02-01" contains validated ranges.

4. To Consider

Autoplot uses a "now" keyword:

"2013/now"   the interval from 2013-01-01 to the present time.
"P1D/now"    the last 24 hours.
"2013/now-P1D"       from 2013-01-01 to 24 hours ago.  Why?  Because you know it takes 24 hours to process data...
"now-P10D/now-P1D"   process the last nine days of data.

Note these are resolved immediately into conventional timeranges.

Bob has been using things like negative intervals:

"end=-P1D"       24 hours ago.

Autoplot doesn't allow plus with now, and we should finish off this functionality.

"2013/now+P1D"   from 2013-01-01 to 24 hours from now.  Why would you want this?  Models, or to have a visual gap showing the end of data.

Also it might be nice to round to nice intervals, since this is trivial to implement. Suppose underscore truncated the finer digits:

"2001/now_P1Y"    from 2001-01-01 to xxxx-01-01 where xxxx is the current year.
"2001/now_P2Y"    from 2001-01-01 to xxxx-01-01 where xxxx is the year before the current year.
"now_P1Y/now_P1Y+P1Y"  The current year.

5. Implementations

Retrieved from ""
Personal tools