Repository navigation
Bounds datetimes to years 0000 through 9999 - #255
Merged
Merged
Conversation
A datetime is an instant from 0000-01-01T00:00:00Z through 9999-12-31T23:59:59.999999Z in UTC, and nothing outside that range is one (ruled by the operator, 2026-11-20). An offset can carry a string or a literal naming a time inside those years to an instant outside them. A string cast to ::datetime naming such an instant now answers :undefined, the answer an unreadable string gets: past the top it raised out of the cast, below the bottom it answered a year -0001 value. A datetime literal naming one is refused by the lexer with the same malformed-literal error and span a bad datetime literal gets; before, the top side lexed to a value whose decompiled text carried a five-digit year the lexer refused, so the text round trip broke. docs/isa.md section 3 states the range. conformance/cases/casts.json gains four new cases at both bounds; mix corpus.generate rewrote tier-7 and the manifest, so the corpus hash moves and the ISA version does not. The ratchet example's corpus_hash follows the manifest. The corpus has no shape for a compile refusal, so the lexer refusal is pinned by unit tests and an enumerated round-trip test instead. Refs: px-dd1b
Codecov Report✅ All modified and coverable lines are covered by tests.
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
A datetime is an instant from
0000-01-01T00:00:00Zthrough9999-12-31T23:59:59.999999Zin UTC, and nothing outside that range is a datetime (ruled by the operator, 2026-11-20). An offset can carry a string or a literal that names a time inside those years to an instant outside them. This PR enforces the range at the two places a string becomes a datetime.::datetimewhose UTC instant is outside the range answers:undefined, the answer an unreadable string already gets (Predicator.Cast.cast/2). Before, past the top the cast raised anArgumentError, and below the bottom it answered a year-0001value.Invalid datetime format: ...message and a span over the whole literal (parse_date_content/1inlib/predicator/lexer.ex). Before, a literal past the top lexed to a year-10000 value, and its decompiled text had a five-digit year that the lexer refused, so the text round trip broke.docs/isa.mdsection 3 states the range in one sentence.No other function changes its answer.
ISA
The ISA does not move: no opcode, operand or encoding changes, and
isa_versionstays 6.Corpus
conformance/manifest.jsonandconformance/corpus/tier-7.jsonmoved becauseconformance/cases/casts.jsongained four new cases.mix corpus.generatewrote both files. No existing case changed. The new ids:casts/string-to-datetime-last-in-range-instantcasts/string-to-datetime-offset-past-the-top-is-undefinedcasts/string-to-datetime-offset-below-the-bottom-is-undefinedcasts/string-to-datetime-offset-at-the-bottom-is-in-rangeThe corpus hash moves.
conformance/examples/registry.example.json'scorpus_hashfollows the manifest, as the ratchet registry test requires. That example has no tier-7 entries, so nothing else in it changed.The corpus has no shape for a source that fails to compile (
conformance/README.md, "Not a parse-error test"). So the lexer refusal is pinned by unit tests rather than a corpus case, and the follow-up for a corpus shape is tracked separately.Tests
test/predicator/cast_test.exstests both bounds with positive and negative offsets. A sweep over offsets at both bounds turns any raise into a test failure.test/predicator/lexer_literals_test.exstests the refusal at each end with its message and span, and acceptance at each bound.test/predicator/visitors/string_visitor_datetime_range_test.exsis the round-trip property. It is enumerated rather than randomised, because the repo carries no property-testing dependency and this PR adds none. It applies every UTC offset from-23:59to+23:59, minute by minute, to several local times at each bound. Each candidate's expected verdict is computed without the lexer. It asserts that a literal is accepted exactly when its instant is in range, that a refused literal gets the malformed-literal error, and that every accepted literal decompiles to text that parses to the same value.Each new range guard was removed in turn, and each removal turned the new tests red on assertions.
Gate
The full
mix qualitygate is green on this commit. Doctor, Gettext, Sobelow and the opt-in Diataxis stage report skipped, as they do onmain.Changelog
changelog.d/px-dd1b.md, under Fixed.