Commit 7ab5634
authored
feat: extend math engine: currencies, timezones, finance, cooking (#715)
* feat(math): add workday calculations
- `workdays in 3 weeks` → 15 workdays
- `workdays from April 12 to June 15` → N workdays
- `March 3 to March 7 in workdays` → N workdays
- `2 workdays after March 3` → date
* feat(math): add timestamps and ISO 8601 support
- `date to timestamp` → unix timestamp
- `date as iso8601` → ISO 8601 string
- `2019-04-01T15:30:00 to date` → parsed date
- `1733823083000 to date` → millisecond timestamp auto-detection
* feat(math): add timezone extensions — airport codes, countries, date in, time difference
- Airport codes: LAX, JFK, SYD, NRT, CDG, FRA, etc.
- Country names: Japan, Germany, Thailand, etc.
- City aliases: Seattle, Boston, Miami, etc.
- `date in Vancouver` → date-only display in timezone
- `time difference between Seattle and Moscow` → hours
- `difference between PDT & AEST` → hours
* feat(math): add timespan, laptime formats and shorthand time input
- `5.5 minutes as timespan` → 5 min 30 s
- `72 days as timespan` → 10 weeks 2 days
- `5.5 minutes as laptime` → 00:05:30
- `3h 5m 10s` shorthand input → stacked time units
- `03:04:05` laptime input → parsed as hours + minutes + seconds
- Laptime arithmetic: `03:04:05 + 01:02:03 as laptime` → 04:06:08
* feat(math): add clock time intervals
- `7:30 to 20:45` → 13 hours 15 min
- `4pm to 3am` → 11 hours (wraps around midnight)
- `9am to 5pm` → 8 hours
* fix(math): use absolute value for 'time difference between' phrases
* fix(math): preserve sign in timezone difference (matches Soulver behavior)
* fix(math): correct timezone difference sign for 'between' phrases
* test(math): add timezone difference sign verification tests
* test(math): add comprehensive edge case tests from audit
- Rounding: negative numbers, to 0 dp, to nearest 1, pi to 10 digits
- Fix: 'to N dp' now preserves N digits in output (not capped by default precision)
- Percentages: 0%, 100%, 200%, edge cases
- Fractions: 0.25 as fraction, -0.5 as fraction
- Multipliers: 0x, fractional multiplier
- Currency: euros/rubles words, implicit rate with EUR, reverse order
- Format directives: 0 in hex/bin, 0.001 in sci, mixed hex+bin input
- Conditionals: if with and, expression in condition, expression in postfix if
- Calendar: Q1/Q2/Q4, 0 days between, months/years from now/ago
- Clock intervals: midnight crossing, 12am/12pm, same time
- Timespans: 0 seconds, 1.5 hours, singular form
* feat(math): add misc phrase functions
- min/max, half, midpoint, random, gcd/lcm
- permutations/combinations, clamp, proportions (rule of three)
* feat(math): add video timecode and frame rate support
- Timecode format HH:MM:SS:FF with `at/@ N fps` (default 24 fps)
- `frame`/`frames` and `fps` units registered in math.js
- Timecode → frames conversion: `00:30:10:00 @ 24 fps in frames`
- Timecode arithmetic: `03:10:20:05 at 30 fps + 50 frames`
- fps calculations: `30 fps * 3 minutes`
* feat(math): add financial calculations
- Compound interest: yearly/monthly/quarterly compounding
- Interest only, ROI, annual return, present value
- Mortgage: daily/monthly/annual/total repayment and interest
* feat(math): add base N conversion and Python-style hex/bin/int
- `0b101101 as base 8` → 0o55
- `0x2D as base 2` → 0b101101
- `hex(99)` → 0x63, `bin(0x73)` → 0b1110011, `int(0o55)` → 45
* feat(math): add large number symbols and comment extensions
- Large numbers: B/bn (billion), T/tn (trillion), trillion word
- Comments: parenthesis comments `$999 (for iPhone)`, end-of-line `// comment`
- Parenthesis stripping safely skips function calls like sin(x)
* feat(math): add cooking calculations with substance density database
- `density of yogurt` → 1.06 g/cm³
- `300g butter in cups` → mass-to-volume conversion
- `10 cups olive oil in grams` → volume-to-mass conversion
- ~120 cooking substances with densities
* feat(math): extend currencies to 166 fiat + 21 crypto + prefix symbols
- Expand fiat currencies from 27 to 166 (all from open.er-api.com)
- Add 21 cryptocurrencies via CoinGecko API (BTC, ETH, SOL, DOGE, etc.)
- Prefixed dollar symbols: US$, NZ$, CA$, AU$, HK$, S$, NT$
- Custom exchange rates: `50 EUR in USD at 1.05 USD/EUR`
- CoinGecko + fiat fetched in parallel with 1h cache
* test(math): add comprehensive fixture documents for visual testing
14 fixture files covering all math engine features:
- arithmetic, variables, percentages, aggregates, rounding
- math functions, conditionals, units, currency
- fractions/multipliers, calendar, timezones, timespans
- finance, misc functions, cooking
- 4 real-world scenarios: budget, travel, cooking, dev
* fix(math): use user locale for timezone date formatting
* feat(math): unify date formatting with configurable dateFormat setting
- Single formatMathDate() for all date outputs (timezone, calendar, arithmetic)
- DateFormatStyle: 'numeric' | 'short' | 'long' (configurable via setFormatSettings)
- Options: timeZone, timeZoneName, dateOnly for context-specific formatting
- Remove separate formatTimeZoneDate function
- All dates now respect user locale consistently
* feat(math): add date format setting and currency/crypto refresh buttons
- Date format preference: numeric, short, long
- Separate refresh buttons for fiat currencies and crypto rates
- IPC handlers for forced refresh (ignores cache)
- i18n keys for new preferences
* fix: use shadcn Button import in Math preferences
* fix: match Button style with other preferences (remove size=sm)
* fix: unify currency/crypto rate descriptions in preferences
* fix: restore rate limit info in crypto description
* fix: clean up currency/crypto rate descriptions
* fix(math): use fixed notation for unit formatting to avoid scientific notation
* feat(math): support total/sum for unit results (currency, same units)
- numericBlock stores value + unit name
- Aggregates sum only if all entries have same unit
- Mixed units → aggregate returns null (cannot sum)
- $100 + $200 + $50 → sum = 350 USD
- Unit info extracted from math.js rawResult for block tracking
* fix(math): set numericValue for unit results so TOTAL works in UI
* fix: address 5 review findings
- P1: merge partial rates with existing cache instead of overwriting
- P2: show error toast on fiat refresh failure (was showing success)
- P2: finance evaluator uses user locale for formatting
- P2: cooking evaluator uses user locale for formatting
- P2: cooking classifier supports all volume units (pints, quarts, etc.)
* fix(math): address review fixes for rates and cooking locale
* refactor(test): split useMathEngine tests into domain-based files
- useMathEngine.integration.test.ts (66) — multi-line, variables, aggregates, errors
- useMathEngine.math.test.ts (229) — arithmetic, rounding, percentages, conditionals
- useMathEngine.units.test.ts (59) — unit conversion, area/volume, css, rates
- useMathEngine.currency.test.ts (22) — currency symbols, prefixes, modifiers
- useMathEngine.timezones.test.ts (28) — timezone display, conversion, difference
- useMathEngine.calendar.test.ts (47) — calendar, workdays, timestamps, timespans
- useMathEngine.domain.test.ts (17) — finance, cooking
- Shared setup in mathEngineTestUtils.ts
* test: add real-world math engine scenarios1 parent 911562f commit 7ab5634
File tree
58 files changed
+5115
-1627
lines changed- src
- main
- __tests__
- i18n/locales/en_US
- ipc/handlers
- store
- module
- types
- types
- renderer
- components
- math-notebook
- preferences
- composables
- __tests__
- math-notebook
- math-engine
- __tests__/fixtures
- evaluators
- pipeline
- rules
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
58 files changed
+5115
-1627
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
17 | 41 | | |
18 | 42 | | |
19 | 43 | | |
| |||
28 | 52 | | |
29 | 53 | | |
30 | 54 | | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
31 | 107 | | |
32 | 108 | | |
33 | 109 | | |
| |||
39 | 115 | | |
40 | 116 | | |
41 | 117 | | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
48 | 122 | | |
49 | | - | |
50 | | - | |
51 | | - | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
52 | 127 | | |
53 | 128 | | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
| 129 | + | |
| 130 | + | |
59 | 131 | | |
60 | 132 | | |
61 | | - | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
62 | 136 | | |
63 | | - | |
64 | | - | |
65 | | - | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
66 | 142 | | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
67 | 153 | | |
68 | 154 | | |
69 | 155 | | |
| |||
80 | 166 | | |
81 | 167 | | |
82 | 168 | | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
124 | 124 | | |
125 | 125 | | |
126 | 126 | | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
127 | 147 | | |
128 | 148 | | |
129 | 149 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
4 | 8 | | |
5 | 9 | | |
6 | 10 | | |
| |||
14 | 18 | | |
15 | 19 | | |
16 | 20 | | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
17 | 29 | | |
18 | 30 | | |
19 | 31 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
| |||
153 | 154 | | |
154 | 155 | | |
155 | 156 | | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
156 | 160 | | |
157 | 161 | | |
158 | 162 | | |
159 | 163 | | |
160 | 164 | | |
161 | 165 | | |
162 | 166 | | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
163 | 170 | | |
164 | 171 | | |
165 | 172 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
81 | 81 | | |
82 | 82 | | |
83 | 83 | | |
| 84 | + | |
84 | 85 | | |
85 | 86 | | |
86 | 87 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
| 37 | + | |
| 38 | + | |
37 | 39 | | |
38 | 40 | | |
39 | 41 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
24 | 28 | | |
25 | 29 | | |
26 | 30 | | |
27 | 31 | | |
28 | 32 | | |
29 | | - | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
30 | 38 | | |
31 | 39 | | |
32 | 40 | | |
| |||
0 commit comments