Repository navigation
Conversation
The field's "in 3 weeks" and "10 days ago" took a count of any length. Typing "in 1317624576693539402 weeks" overflowed the count times seven and crashed Yab; one less came to Int.max, which Calendar reads as no count, so the answer was today. From about ten million years on the answer was empty, and before year 1 the year was written without its era: 3000 years ago was 0975, and 2026 years ago 0001, as 2025 was. A day some way off is now the answer only in the years 1 to 9999, and a count past the days in ten thousand years is not tried at all.
[Medium impact] The PR appears safe to merge. SummaryLimits relative-date answers to AD 1 through AD 9999.
Reviews (1) · Last reviewed commit: "Give a day some way off only in the year..." · Reviewed by Greptile |
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 changes
The command field's "a day some way off" (
in 3 weeks,10 days ago) answers only with a day in the years 1 to 9999. Before year 1 it named the wrong year, far ahead it gave an empty card, and a 19-digit count of weeks crashed the field.Fixes #1142
Why it happened
Calc.datetook a count of any length and askedCalendarfortoday + sign * count * span:MMM d, yyyy, with no era, so 975 BC came out as0975, and 1 BC as0001, the same as AD 1.Int.maxadded nothing, so the answer was today. One more overflowedcount * 7, a trap.Now:
Calc.writable), the four-digit years the card writes.Int.max.This takes away answers past the year 9999 that were right, such as
in 8000 years(the year 10026). If you'd rather keep those, the bound can be where the formatter stops instead, about year 1,000,000, with the era check kept.Proof
mainand passes here:swift test --filter CalcTests(aDayTooFarOffHasNoAnswer)I can't build Yab here (no Xcode). Instead I compiled
Calculator.swifton its own, with a stub forStore, and ran the synchronous tests ofCalcTeststhrough a small runner. That is 17 tests; the async rate tests and the artwork test need the app. Dates are from the tests' clock, Sep 25, 2026:main2025 years ago2026 years ago3000 years agoin 7973 yearsin 7974 yearsin 10000000 yearsin 1317624576693539401 weeksin 1317624576693539402 weeksOn
mainthe new test fails on its 5 lines before the last, then the last one stops the run with the trap. On this branch all 17 tests pass,daysamong them (in 3 weeks,10 days ago).Checked on
Calculator.swiftcompiled and run on macOS 27.2.1 with Swift 6.2.1.Checklist
swift testpasses (or the suites this touches: list them):CalcTests, not run withswift testhere; the runner above covers its synchronous tests./design-check --headis clean, or each exception says why with// design:NativeActions.swift(none)Written by an AI coding agent (Claude Code, Claude Opus 5.5) at my request.