tempUtils.ts
Temperature unit conversion and display formatting utilities
Purpose
This module provides the two temperature utility functions used across all screens to convert and format core temperature values according to the user’s unit system preference.
Its responsibilities include:
- Converting Celsius values to Fahrenheit
- Formatting a Celsius temperature as a localized display string with the appropriate unit suffix
Invariants
Celsius-to-Fahrenheit Formula
°F = (°C × 9/5) + 32
No rounding is applied in celsiusToFahrenheit; rounding is the caller’s responsibility via decimals.
Default Decimal Places
formatTemp defaults to 1 decimal place.
Callers may pass a different decimals value; this is forwarded directly to toFixed.
Exports
celsiusToFahrenheit(...)
function celsiusToFahrenheit(c: number): number
Returns the Fahrenheit equivalent of the given Celsius value.
formatTemp(...)
function formatTemp(
tempC: number,
unitSystem: "metric" | "imperial",
decimals?: number,
): string
Returns a display string for the given temperature:
- Imperial:
"98.6°F"(Fahrenheit, rounded todecimalsplaces) - Metric:
"37.0°C"(Celsius, rounded todecimalsplaces)
Parameters
| Parameter | Default | Description |
|---|---|---|
tempC | — | Temperature in Celsius |
unitSystem | — | "metric" or "imperial" |
decimals | 1 | Decimal places passed to toFixed |