This repository was archived by the owner on Oct 17, 2026. It is now read-only.
Repository navigation
feat(calc): convert units - #5
Merged
Merged
Conversation
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.
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
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.convertreads<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
Dimensionconverters: 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
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;leavesEverythingElseAlonecovers the obvious cases, but there may be a phrase where a number and two letters collide.Checklist
scripts/task checkpasses locally--snapshot("70 f in c")