Skip to content

Commit 20e87a0

Browse files
committed
Explicitly disallow year 0
Year "0" doesn't exist; it goes from 1 BC to 1 AD. RFC 3339 is somewhat unclear if this should be allowed, at least in my reading of it: > This document defines a [..] representation of dates and times using > the Gregorian calendar. "Gregorian calendar" has no "year zero", so it should be forbidden. But also: > All dates and times are assumed to be in the "current era", > somewhere between 0000AD and 9999AD. So meh. Practically speaking, supporting this across the board is rather tricky. Python's datetime has no way to represent this (other than None, maybe? Ugh.), PostgreSQL doesn't support it, Go's time.Time behaves oddly (e.g. IsZero() is false, which is rather surprising), etc. ISO 8601 defines year 0 as "1 BC", which is even worse since most datetime implementations don't really do BC dates. Just forbidding it is by far the easiest for everyone; for implementations with a datetime that supports it, it's just a single `if`, and for e.g. Python nothing needs to be done. The only potential downside is that people may have `d = 0000-01-01`. We already broke compatibility "for sanity" by disallowing table overrides, so I think that's okay. The alternative is making it implementation dependent. Meh. RFC 3339 is supposed to be a "ISO 8601, without obscure edge cases"; this seems to fit with the intended purpose.
1 parent 23c3fb7 commit 20e87a0

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
- Seconds in Date-Time and Time values are now optional.
1313
- Allow non-English scripts in unquoted (bare) keys
1414
- Clarify newline normalization in multi-line literal strings.
15+
- Explicitly disallow year zero.
1516

1617
## 1.0.0 / 2021-01-11
1718

toml.abnf

+1-1
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ false = %x66.61.6C.73.65 ; false
177177

178178
date-time = offset-date-time / local-date-time / local-date / local-time
179179

180-
date-fullyear = 4DIGIT
180+
date-fullyear = 4DIGIT ; 0001-9999
181181
date-month = 2DIGIT ; 01-12
182182
date-mday = 2DIGIT ; 01-28, 01-29, 01-30, 01-31 based on month/year
183183
time-delim = "T" / %x20 ; T, t, or space

toml.md

+7
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,13 @@ implementation-specific. If the value contains greater precision than the
582582
implementation can support, the additional precision must be truncated, not
583583
rounded.
584584

585+
The first year in the Gregorian calendar is year 1 (1 BC is followed by 1 AD),
586+
and year 0 is not allowed:
587+
588+
```
589+
odt7 = 0000-01-01 07:32:32Z # INVALID
590+
```
591+
585592
## Local Date-Time
586593

587594
If you omit the offset from an [RFC 3339](https://tools.ietf.org/html/rfc3339)

0 commit comments

Comments
 (0)