Skip to content

Give a day some way off in the field's calculator only in the years 1 to 9999 - #1143

Open
r0c0y wants to merge 1 commit into
yetanotherbrowser:mainfrom
r0c0y:fix-calculator-far-days
Open

r0c0y wants to merge 1 commit into
yetanotherbrowser:mainfrom
r0c0y:fix-calculator-far-days

Conversation

@r0c0y

@r0c0y r0c0y commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

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.date took a count of any length and asked Calendar for today + sign * count * span:

  • The answer is written MMM d, yyyy, with no era, so 975 BC came out as 0975, and 1 BC as 0001, the same as AD 1.
  • From about ten million years on, the formatter wrote nothing.
  • A count whose product came to exactly Int.max added nothing, so the answer was today. One more overflowed count * 7, a trap.

Now:

  • A day some way off is the answer only in the years 1 to 9999 (Calc.writable), the four-digit years the card writes.
  • A count past the days in ten thousand years (3,660,000) is not tried at all. Every unit is a day or more, so such a count can't land in those years. That also keeps the product far from 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

  • Logic: a test that fails on main and passes here: swift test --filter CalcTests (aDayTooFarOffHasNoAnswer)

I can't build Yab here (no Xcode). Instead I compiled Calculator.swift on its own, with a stub for Store, and ran the synchronous tests of CalcTests through 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:

Typed main This branch
2025 years ago Sep 25, 0001 Sep 25, 0001
2026 years ago Sep 25, 0001 no answer
3000 years ago Sep 25, 0975 no answer
in 7973 years Sep 25, 9999 Sep 25, 9999
in 7974 years Sep 25, 10000 no answer
in 10000000 years empty answer no answer
in 1317624576693539401 weeks Sep 25, 2026 no answer
in 1317624576693539402 weeks overflow trap (exit 133) no answer

On main the 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, days among them (in 3 weeks, 10 days ago).

Checked on

  • Yab Dev built from this branch on macOS: not built here (no Xcode). Calculator.swift compiled and run on macOS 27.2.1 with Swift 6.2.1.
  • Engine(s) tried: not about a page

Checklist

  • swift test passes (or the suites this touches: list them): CalcTests, not run with swift test here; the runner above covers its synchronous tests
  • ./design-check --head is clean, or each exception says why with // design:
  • Anything that changes how Yab looks was approved in the issue first (nothing changes but answers that were wrong or empty)
  • A new menu item is also a command in the field; a new Settings row is classified in NativeActions.swift (none)
  • Words on screen and in docs are American English, with no em dashes

Written by an AI coding agent (Claude Code, Claude Opus 5.5) at my request.

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.
@r0c0y
r0c0y requested a review from serafimcloud as a code owner November 25, 2026 09:18
@greptile-apps

greptile-apps Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge.

Summary

Limits relative-date answers to AD 1 through AD 9999.

  • Relative-day questions only get answers for years 1 through 9999.

Reviews (1) · Last reviewed commit: "Give a day some way off only in the year..." · Reviewed by Greptile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Command field: a day some way off names the wrong year before year 1, is empty far ahead, and a 19-digit count of weeks crashes

1 participant