Skip to content
This repository was archived by the owner on Oct 17, 2026. It is now read-only.

feat(calc): convert units - #5

Merged
oddurs merged 1 commit into
mainfrom
feat/unit-conversion
Oct 16, 2026
Merged

oddurs merged 1 commit into
mainfrom
feat/unit-conversion

Conversation

@oddurs

@oddurs oddurs commented Oct 16, 2026

Copy link
Copy Markdown
Owner

Problem

Spotlight converts units ("10 km to mi") and people use it for exactly that. Without it, Common Command left a reason to keep Spotlight around.

Approach

Converter.convert reads <amount> <unit> to|in|as|into|=|→ <unit>, searching for the separator from the right so "5 in in cm" works. The unit is the longest known name the left side ends with, so "10km" and "10 km" both work. The amount goes through the calculator (Calculator.value(of:requiringOperation: false)), so it can be arithmetic ("6*12 in to cm") and follows the region's decimal separator.

Factors come from Foundation's Dimension converters: length, mass, temperature, volume, speed, area, data (decimal KB/MB/GB as Finder counts, plus KiB/MiB/GiB), duration (days and weeks added as linear units), and angle. Both units must be the same kind; "10 km to kg" is not a conversion.

The result sits where calculations do, shown and copied to six significant figures ("70 f in c" → "= 21.1111 °C"). It turns off with the Calculator setting.

Look at sceptically

  • "cup" is Foundation's 240 ml US legal cup, not the 236.6 ml customary cup. Both are real; the test pins the Foundation one.
  • Single-letter units (m, g, c, f, k, s, h, t, d) are accepted only after an amount and before/after a separator, so ordinary searches are untouched; leavesEverythingElseAlone covers the obvious cases, but there may be a phrase where a number and two letters collide.
  • No currency: it needs exchange rates from the network, and the app makes no connections of its own.

Checklist

  • scripts/task check passes locally
  • UI reviewed with --snapshot ("70 f in c")

Spotlight converts units and people reach for it to do so; without it this was a reason to keep Spotlight around. Foundation's Unit types supply the factors, so they're Apple's and offline. The amount goes through the calculator, so it can be arithmetic and follows the region's decimal separator.
@oddurs
oddurs merged commit 240cc13 into main Oct 16, 2026
2 checks passed
@oddurs
oddurs deleted the feat/unit-conversion branch October 16, 2026 23:28
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant