Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ Works:
- arithmetic and functions
- Soulver-style percentages (`$30 + 20%`, `20% off 50`, `50 as a % of 200`)
- ~250 units (`5 ft to cm`, `60 mph * 2 h`, `16px to rem`)
- currencies (ECB rates from frankfurter.dev, cached daily in `~/.cache/omacast/currencies.json`; turn off with `"currencyRates": false` in config.json)
- currencies (~160, central-bank rates from frankfurter.dev's v2 API, cached daily in `~/.cache/omacast/currencies.json`; turn off with `"currencyRates": false` in config.json)
- dates (`3 days from now`, `days until christmas`)
- time zones (`time in tokyo`, `3pm london to nyc`; offsets come from one bash `printf %(%z)T` pass because QML has no Intl)
- bases (`255 to hex`)
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ has its own engine, so there's nothing to install.
| Arithmetic and functions | `2^10`, `sqrt(2) * 10`, `sin(30°)` |
| Percentages | `$30 + 20%`, `20% off 50`, `50 as a % of 200` |
| ~250 units, including mixed units | `5 ft to cm`, `5 ft 3 in to cm`, `60 mph * 2 h`, `16px to rem` |
| Currencies | `100 usd in eur` |
| ~160 currencies | `100 usd in eur`, `100 aed to inr` |
| Dates | `3 days from now`, `days until christmas` |
| Time zones | `time in tokyo`, `3pm london to nyc` |
| Number bases | `255 to hex` |
Expand All @@ -140,7 +140,7 @@ has its own engine, so there's nothing to install.
"question = answer". Each one is saved to **Calculator History** (searchable, kept for 90 days; `Ctrl+D`
deletes an entry, `Ctrl+Shift+D` deletes all). Trig takes radians unless you add `°` or `deg`.

Currency rates are ECB reference rates (see [network access](#dependencies-and-network-access)).
Currency rates are central-bank reference rates (see [network access](#dependencies-and-network-access)).
`config.json` sets `remToPxRate` (16), `workHoursPerDay` (8) and `clockFormat` (`auto` follows your locale,
or `12h` / `24h`).

Expand Down Expand Up @@ -307,7 +307,7 @@ It adds no packages and no background services.
(`com.superwhisper.ShellOverlay`), so Superwhisper's recording glow or pill draws on the launcher instead
of the window under it. It makes no network requests, and does nothing without Superwhisper.
- **Currency rates.** When you open the launcher and its rates are over 12 hours old, the calculator downloads
ECB exchange rates from `api.frankfurter.dev` (retrying 30 minutes after a failure) and caches them in
central-bank exchange rates from `api.frankfurter.dev` (retrying 30 minutes after a failure) and caches them in
`~/.cache/omacast/currencies.json`. This is the only network request omacast makes. Turn it off with
`"currencyRates": false` in `~/.config/omacast/config.json`.
- **Optional search helper.** With Rust (`cargo`) installed, `omacast install` (or `omacast build-search`)
Expand Down
181 changes: 177 additions & 4 deletions core/Calculator.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion core/Schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ var documents = {
var configDefaults = {
logLevel: "info",
keepVisibleOnFocusLoss: false,
// Daily ECB reference rates from frankfurter.dev for currency conversion
// Daily central-bank reference rates from frankfurter.dev for currency conversion
// (SPEC §8 Calculator). The only network request omacast makes. [D]
currencyRates: true,
// Calculator preferences named after Raycast's (ref 04 App. B) [O].
Expand Down
13 changes: 5 additions & 8 deletions services/CalculatorData.qml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import QtQuick
import Quickshell.Io
import "../core/Calculator.js" as Calculator

// Live inputs for core/Calculator.js: ECB exchange rates (SPEC §8: cached
// daily, frankfurter.dev) and the current UTC offset of every time zone the
// Live inputs for core/Calculator.js: central-bank exchange rates (SPEC §8:
// cached daily, frankfurter.dev) and the current UTC offset of every time zone the
// calculator knows. QML's JS engine has no Intl, so one bash process asks
// strftime for all of them (~40 ms).
Item {
Expand All @@ -22,8 +22,8 @@ Item {
property bool cacheRead: false
property var request: null

readonly property string ratesUrl: "https://api.frankfurter.dev/v1/latest"
readonly property double ratesMaxAgeMs: 12 * 3600 * 1000 // ECB publishes once a working day
readonly property string ratesUrl: "https://api.frankfurter.dev/v2/rates"
readonly property double ratesMaxAgeMs: 12 * 3600 * 1000 // central banks publish once a working day
readonly property double retryAfterMs: 30 * 60 * 1000
readonly property double zonesMaxAgeMs: 10 * 60 * 1000 // catches DST switches

Expand All @@ -39,10 +39,7 @@ Item {
}

function validRates(doc) {
if (!doc || typeof doc.base !== "string" || !doc.rates || typeof doc.rates !== "object") return null
var out = {}
for (var code in doc.rates) if (/^[A-Z]{3}$/.test(code) && typeof doc.rates[code] === "number" && doc.rates[code] > 0) out[code] = doc.rates[code]
return { base: doc.base, date: String(doc.date || ""), rates: out }
return Calculator.parseRates(doc)
}

function fetchRates() {
Expand Down
2 changes: 1 addition & 1 deletion site/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ What it runs on:
| File in `public/demo/` | What | In git |
|---|---|---|
| `core.js`, `emoji.json` | `core/*.js` bundled, and a copy of `data/emoji.json`. Written by `node build.mjs` | no |
| `snapshot.json` | Omarchy's menu, which rows are hidden or checked, and ECB exchange rates. Written by `node snapshot.mjs` | yes |
| `snapshot.json` | Omarchy's menu, which rows are hidden or checked, and exchange rates. Written by `node snapshot.mjs` | yes |
| `emoji-keywords.json` | Omarchy's emoji search keywords. Written by `node snapshot.mjs` | yes |
| `symbols.woff2` | the icon glyphs, subset from JetBrainsMono Nerd Font. Written by `node snapshot.mjs` (needs `uvx`) | yes |
| `NOTICE.md`, `OFL.txt` | licences for the three above | yes |
Expand Down
2 changes: 1 addition & 1 deletion site/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ <h2 class="display">Just type the question.</h2>
<li class="reveal"><span><b>Math</b>: arithmetic, powers, roots, trig and more</span></li>
<li class="reveal"><span><b>Percentages</b>: <code>$30 + 20%</code>, <code>20% off 50</code>, <code>50 as a % of 200</code></span></li>
<li class="reveal"><span><b>Units</b>: about 250 of them, mixed units like <code>5 ft 3 in</code>, and CSS <code>px</code> / <code>rem</code></span></li>
<li class="reveal"><span><b>Currencies</b>: daily ECB rates, cached for the day</span></li>
<li class="reveal"><span><b>Currencies</b>: ~160 of them at daily central-bank rates, cached for the day</span></li>
<li class="reveal"><span><b>Dates and time zones</b>: <code>3 days from now</code>, <code>days until christmas</code>, <code>3pm london to nyc</code></span></li>
<li class="reveal"><span><b>Number bases, work time and Unix time</b></span></li>
</ul>
Expand Down
2 changes: 1 addition & 1 deletion site/snapshot.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// node site/snapshot.mjs
// Writes, under site/public/demo/ (all committed):
// snapshot.json Omarchy's menu (default/omarchy/omarchy-menu.jsonc), which rows are hidden or
// checked, and the day's ECB exchange rates
// checked, and the day's exchange rates
// emoji-keywords.json Omarchy's emoji search keywords (shell/plugins/emojis/emojis.json)
// symbols.woff2 the icon glyphs the launcher draws, subset from JetBrainsMono Nerd Font
// (needs `uvx`, which fetches fonttools)
Expand Down
34 changes: 34 additions & 0 deletions tests/calculator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,40 @@ test("currencies use the rates and need them only to convert", () => {
assert.equal(result("$30 + 20%", Object.assign({}, env, { rates: null })), "$36.00")
})

test("currencies beyond the ECB set convert by code or full name", () => {
const more = Object.assign({}, env, { rates: { base: "EUR", date: "2026-10-19", rates: { USD: 2, AED: 4, DOP: 100, KWD: 0.5, VND: 30000 } } })
assert.equal(result("100 aed to usd", more), "$50.00")
assert.equal(result("10 usd in aed", more), "20.00 AED")
assert.equal(result("10 usd to dominican pesos", more), "500.00 DOP")
assert.equal(result("1 eur to kwd", more), "0.500 KWD", "three decimals")
assert.equal(result("1 eur to vnd", more), "30,000 VND", "no decimals")
assert.equal(result("1 eur to vietnamese dong", more), "30,000 VND", "accents are optional")
assert.equal(C.evaluate("10 usd in aed", more).resultCaption, "United Arab Emirates Dirham (AED)")
assert.equal(C.evaluate("10 usd in xof", Object.assign({}, more, { rates: Object.assign({}, more.rates, { rates: { USD: 2, XOF: 600 } }) })).resultCaption, "West African CFA Franc (XOF)")
assert.equal(result("10 usd in aed", env), null, "a known code still needs its rate")
assert.equal(result("5 cup to ml", more), "1,182.9412 mL", "CUP the currency leaves the cup alone")
assert.equal(result("2 ton to kg", more), "1,814.3695 kg")
assert.ok(Object.keys(C.CURRENCIES).length > 150)
})

test("exchange rates parse from the v2 answer and from the cache", () => {
const v2 = [
{ date: "2026-11-19", base: "EUR", quote: "USD", rate: 1.1 },
{ date: "2026-11-18", base: "EUR", quote: "AED", rate: 4.03 },
{ date: "2026-11-19", base: "EUR", quote: "USDT", rate: 1.1 },
{ date: "2026-11-19", base: "EUR", quote: "BAD", rate: 0 },
{ date: "2026-11-19", base: "EUR", quote: "NAN", rate: "1" },
{ date: "2026-11-19", base: "USD", quote: "GBP", rate: 0.8 },
null
]
assert.deepEqual(C.parseRates(v2), { base: "EUR", date: "2026-11-19", rates: { USD: 1.1, AED: 4.03 } })
assert.deepEqual(C.parseRates({ fetchedAt: 1, base: "EUR", date: "2026-10-19", rates: { USD: 1.1, usd: 2, JPY: -1 } }), { base: "EUR", date: "2026-10-19", rates: { USD: 1.1 } })
assert.equal(C.parseRates([]), null)
assert.equal(C.parseRates({ base: "EUR", rates: {} }), null)
assert.equal(C.parseRates(null), null)
assert.equal(C.parseRates("nope"), null)
})

test("dates and durations", () => {
assert.equal(result("3 days from now"), "Thursday, 22 October 2026 at 4:06 PM")
assert.equal(result("2 weeks ago"), "Monday, 5 October 2026 at 4:06 PM")
Expand Down