mirror of
https://git.undefined-dev.fr/Blendman974/faceclaw.git
synced 2026-11-19 21:03:09 +00:00
18 lines
759 B
TypeScript
18 lines
759 B
TypeScript
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";
|
|
}
|