A browser input control is not a complete validation policy. This example defines exactly which decimal-minute strings are accepted, tests that contract in Python, and generates an offline HTML page with the equivalent rules. The page contains its own styles and script and contacts no external service.
Run the example
All illustrative records are fictional. Save the following as offline_converter.py. I ran the script in PythonIDE on an English iPhone simulator and checked the generated HTML preview with 2.5 and -1.
from decimal import Decimal from pathlib import Path import re # A shared contract: non-negative decimal, at most 2 places. def convert(text): if not re.fullmatch(r'[0-9]+(?:\.[0-9]{1,2})?', text): raise ValueError('Use non-negative minutes, max 2 decimals') value = Decimal(text) if value > 10080: raise ValueError('Maximum is one week: 10080 minutes') seconds = int(value * 60) return divmod(seconds, 60) for value, expected in [('2.5', (2, 30)), ('0', (0, 0)), ('1.01', (1, 0)), ('60', (60, 0))]: assert convert(value) == expected for value in ['', '-1', 'NaN', '1e3', '1.234', '10081']: try: convert(value) except ValueError: continue raise AssertionError(f'Unexpected acceptance: {value}') print('Python input-contract tests passed.') html = r"""<!doctype html><html lang="en"> <meta charset="utf-8"><meta name="viewport" content="width=device-width"> <title>Minutes to minutes and seconds</title> <style>body{font:18px system-ui;max-width:32rem;margin:2rem;padding:1rem} input,button{font:inherit;padding:.5rem}output{display:block;margin-top:1rem}</style> <h1>Split decimal minutes</h1><p>Offline. Whole seconds are truncated.</p> <label for="minutes">Minutes (0–10080, max 2 decimals)</label> <input id="minutes" inputmode="decimal" value="2.5"> <button id="convert">Convert</button><output id="result" aria-live="polite"></output> <script> function convert(text) { const match = text.match(/^[0-9]+(?:\.[0-9]{1,2})?$/); if (!match || match[0] !== text) throw Error('Invalid decimal'); const [whole, fraction=''] = text.split('.'); const hundredths = BigInt(whole)*100n + BigInt(fraction.padEnd(2,'0')); if (hundredths > 1008000n) throw Error('Maximum is 10080 minutes'); const seconds = hundredths*60n/100n; return `${seconds/60n} min ${seconds%60n} sec`; } document.querySelector('#convert').onclick = () => { const output = document.querySelector('#result'); try { output.textContent = convert(document.querySelector('#minutes').value); } catch (error) { output.textContent = error.message; } }; </script></html>""" path = Path('offline_minutes_demo.html') if path.exists(): raise FileExistsError('Demo file exists; choose a new name before running') path.write_text(html, encoding='utf-8') print('Created:', path.name) print('Open the file in the available HTML preview; test 2.5 and -1.') Understand the checks and their limits
The contract accepts non-negative decimal text with at most two fractional digits and a one-week maximum. Whole seconds are deliberately truncated, so 1.01 minutes becomes 1 minute 0 seconds, not 1 minute 1 second. Python uses Decimal; JavaScript converts hundredths to BigInt, preventing a floating-point rounding mismatch at a truncation boundary.
The script creates a new HTML file in the working directory and refuses to overwrite an existing one. Python assertions verify the Python function only, not the browser implementation. The actual HTML preview was separately checked with 2.5 and -1. The remaining browser checks for 0, 1.01, empty input, 1e3 and 10081 still need to be run. The interface uses textContent rather than treating input as HTML. The observed preview supports this BigInt example; compatibility on other devices remains a separate check.
Try one change
Change the rule from truncating seconds to rounding them. Update both implementations and the 1.01 test before calling the interfaces equivalent.
I build PythonIDE, a Python coding app for iPhone and iPad. The example is intended to teach a workflow you can inspect and adapt.
AI assisted with drafting and translation. The Python assertions and the two HTML preview interactions described above were checked in PythonIDE.
Observed workflow: run the script once, open offline_minutes_demo.html in the file list, and select Preview. Clicking Convert with 2.5 displayed “2 min 30 sec”; entering -1 and clicking Convert displayed “Invalid decimal”. No deployment was needed. The HTML uses only inline assets. Its last result updates when Convert is clicked, not on every keystroke.






