Appendix A. ISO 8601 Collected ABNF
This information is based on the 1988 version of ISO 8601. There may be some changes in the 2000 revision.
Explanation
ISO 8601 does not specify a formal grammar for the date and time formats it defines. The following is an attempt to create a formal grammar from ISO 8601. This is for information only and may contain errors. ISO 8601 remains the authoritative reference.
Ambiguities and Interpretations
Note that due to ambiguities in ISO 8601, some interpretation was necessary:
-
Mixing Basic and Extended Formats: ISO 8601 is not clear if mixing of basic and extended format is permissible. This grammar permits mixing.
-
24 Hours: ISO 8601 is not clear whether the hour 24 is only permitted if minutes and seconds are 0. This grammar assumes hour 24 is permissible in any context.
-
Date Restrictions: The restrictions in Section 5.7 regarding date-mday apply.
-
"T" Delimiter: ISO 8601 specifies that "T" may be omitted under some circumstances. This grammar requires "T" to avoid ambiguity.
-
Decimal Point: ISO 8601 requires (in section 5.3.1.3) that if the decimal fraction is less than 1, it must be preceded by a "0". ISO 8601's Appendix B.2 gives examples with decimal fractions not preceded by "0". This grammar assumes section 5.3.1.3 is correct and Appendix B.2 is in error.
Complete ISO 8601 ABNF Grammar
date-century = 2DIGIT ; 00-99
date-decade = DIGIT ; 0-9
date-subdecade = DIGIT ; 0-9
date-year = date-decade date-subdecade
date-fullyear = date-century date-year
date-month = 2DIGIT ; 01-12
date-wday = DIGIT ; 1-7 ; 1 is Monday, 7 is Sunday
date-mday = 2DIGIT ; 01-28, 01-29, 01-30, 01-31
date-yday = 3DIGIT ; 001-365, 001-366
date-week = 2DIGIT ; 01-52, 01-53
datepart-fullyear = [date-century] date-year ["-"]
datepart-ptyear = "-" [date-subdecade ["-"]]
datepart-wkyear = datepart-fullyear / datepart-ptyear
dateopt-century = "-" / date-century
dateopt-fullyear = "-" / datepart-fullyear
dateopt-year = "-" / (date-year ["-"])
dateopt-month = "-" / (date-month ["-"])
dateopt-week = "-" / (date-week ["-"])
datespec-full = datepart-fullyear date-month ["-"] date-mday
datespec-year = date-century / dateopt-century date-year
datespec-month = "-" dateopt-year date-month [["-"] date-mday]
datespec-mday = "--" dateopt-month date-mday
datespec-week = datepart-wkyear "W"
(date-week / dateopt-week date-wday)
datespec-wday = "---" date-wday
datespec-yday = dateopt-fullyear date-yday
date = datespec-full
/ datespec-year
/ datespec-month
/ datespec-mday
/ datespec-week
/ datespec-wday
/ datespec-yday
time-hour = 2DIGIT ; 00-24
time-minute = 2DIGIT ; 00-59
time-second = 2DIGIT ; 00-58, 00-59, 00-60
time-fraction = ("," / ".") 1*DIGIT
time-numoffset = ("+" / "-") time-hour [[":"] time-minute]
time-zone = "Z" / time-numoffset
timeopt-hour = "-" / (time-hour [":"])
timeopt-minute = "-" / (time-minute [":"])
timespec-hour = time-hour [[":"] time-minute [[":"] time-second]]
timespec-minute = timeopt-hour time-minute [[":"] time-second]
timespec-second = "-" timeopt-minute time-second
timespec-base = timespec-hour / timespec-minute / timespec-second
time = timespec-base [time-fraction] [time-zone]
iso-date-time = date "T" time
RFC 3339 vs Complete ISO 8601
RFC 3339 is a restricted subset of ISO 8601, not a complete implementation:
| Feature | ISO 8601 | RFC 3339 |
|---|---|---|
| Basic format (20020715) | ✅ Supported | ❌ Not supported |
| Extended format (2002-07-15) | ✅ Supported | ✅ Supported |
| Week dates (2002-W29-1) | ✅ Supported | ❌ Not supported |
| Ordinal dates (2002-196) | ✅ Supported | ❌ Not supported |
| Partial dates (2002-07) | ✅ Supported | ❌ Not supported |
| 24 hours (2002-07-16T24:00:00) | ✅ Supported | ❌ Not supported |
| Timezone "Z" | ✅ Supported | ✅ Supported |
| Numeric timezone offset | ✅ Supported | ✅ Supported (mandatory) |
| Fractional seconds | ✅ Supported | ✅ Supported |
Reasons for RFC 3339 Simplification
RFC 3339 chose a simplified subset for:
- Interoperability: Reduce implementation variations
- Clarity: Avoid ambiguity
- Completeness: Require full date-time information
- Simplicity: Easier to implement and test
Note: If complete ISO 8601 functionality (such as week dates) is needed, consult the ISO 8601 standard directly. RFC 3339 focuses on the most common timestamp use cases in Internet protocols.