Add temperature-units config option

This commit is contained in:
James Babcock committed 2026-10-24 00:16:50 -07:00
1 parent 1780057f3c
commit 5256ab1ddc
8 files changed
+48 -6

No files matched your search

+17
View File
@@ -0,0 +1,17 @@
import { temperatureUnitSetting } from "../../ui/dashboard-settings";
/**
* A temperature (weather data is kept in Fahrenheit) in the unit chosen in
* Settings > Customization > Temperature unit, rounded: "72°F" / "22°C", or
* "72°" without the unit letter.
*/
export function formatTemperature(fahrenheit: number, withUnit = true): string {
const celsius = temperatureUnitSetting.get() === "celsius";
const value = Math.round(celsius ? (fahrenheit - 32) * 5 / 9 : fahrenheit);
return withUnit ? `${value}°${celsius ? "C" : "F"}` : `${value}°`;
}
/** The widest temperature the forecast's column is sized for. */
export function widestTemperatureSample(): string {
return temperatureUnitSetting.get() === "celsius" ? "-20°C" : "100°F";
}