Dates, times and timezones for Zig 0.17: IANA tzdata, ISO 8601, RFC 822, strftime, CLDR, Go, .NET and git date formats

give nearly every function a doctest

A doctest is a test declaration named by a bare identifier rather than a string, which the compiler attaches to the declaration of that name and `zig build docs` renders as its example. There are now 136 of them and the suite has gone from 65 tests to 195. They are documentation before they are coverage, so each one is short, self-contained, and about the single function it names. The exhaustive table-driven tests are left alone under their string names; only the few that were already brief enough to read as an example were converted. What makes this worth more than the tidiness is that a doctest forces a function to be called, and Zig does not analyze the body of a function nothing references. Three defects had been sitting in shipped code because nothing ever called the code that held them: * Month.as had never compiled. It reached for info.bits.signedness, but @typeInfo returns a union with no such field; it is info.int. Nothing in the library or the tests had ever called it. * formatAllocSentinel returned ![]const u8, dropping the sentinel from the type. toOwnedSliceSentinel allocates n+1 bytes and every caller was freeing n, which the DebugAllocator reports the moment anything completes the round trip. It now returns ![:sentinel]const u8. * tzdb.embedded.load was a compile error in any build without -Dembed-tzdata, which is the one case the stub module exists to support. find binary searches generated.entries, comptime-empty in the stub, and indexing a slice of known-zero length is an error however unreachable the index. Verified against the unmodified tree before changing anything, and the embedded build still passes. Two doc comments were wrong and are corrected with them: toUtc said the offset was in minutes where it is seconds, and ParseError.IllegalToken was described as a returned error when it is raised inside a comptime block and so can only ever surface as a compile error. One structural fix was needed to make any of this run: src/ordinal.zig is named only from inside comptime-generic bodies, so none of its tests were being collected. The root test block asks for it explicitly now. Splitting bytesForTest out of loadForTest is what lets the TimeZone constructors have doctests of their own. What is left without one: tools/docs_server.zig, kept byte-for-byte identical to the copies in the other repositories; build.zig, bench.zig and tools/tzpack.zig, which the test step never compiles, so a doctest there would not run; the test-only helpers; and Month.Iterator.next, where the bare identifier a doctest needs would be ambiguous with Month.next in the enclosing scope. That last one is noted in its doc comment. zig fmt, `zig build docs` and `reuse lint` pass. The suite passes both with and without -Dembed-tzdata; the four tests that skip by default are the ones needing embedded data, and they run in that configuration. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TFydFscsLXY7WWaGL4NKnL


Author jcollie.dev
Co-author Claude Opus 5 (1M context) Date Commit Parent d3383c68