Print a Rust date the way it is read, so a year before 0 reads back

Merged
JE
8d ago
+23-1

Follow-up to #1106. jiff's civil::Date Display writes a year before 0 with six digits (-000001-01-01), but Date parses with %Y-%m-%d, which reads at most four. So Date::new(-1, 1, 1) printed, and serialized, as something it couldn't read back. chrono round-tripped it. Copilot found the same thing on the matching hey-sdk change (basecamp/hey-sdk#311).

Display now formats with the same %Y-%m-%d it parses with. For years 0 to 9999 the output is byte-identical to before (checked across 59,997 dates from -9999 to 9999, all of which round-trip). The new every_date_reads_back_what_it_prints test round-trips the calendar's ends, -1 and 0 through both Date::parse and serde.

Neither API sends such dates, so this only matters to a caller building one by hand. It is a patch-level fix to an unreleased change.


Summary by cubic

Fixes date display so a year before 0 prints as something Date can read back. jiff's Display writes a year before 0 with six digits (-000001), which %Y-%m-%d parsing doesn't read, so such a date no longer round-tripped through printing or JSON as it did with chrono.

Display now formats with the same %Y-%m-%d used for parsing; years 0-9999 print byte-identically. A new test round-trips the calendar's ends, years before 0 included, through both Date::parse and serde. Neither API sends such dates, so this only matters when building one by hand.