chore: add prettier formatting
All checks were successful
CI / Lint, typecheck and build (push) Successful in 9m56s

This commit is contained in:
zv
2026-06-14 20:26:56 +02:00
parent 8bbd9397a1
commit ee55521803
79 changed files with 2451 additions and 969 deletions

View File

@@ -1,6 +1,11 @@
import type { Language, TranslationKey } from "@/lib/i18n";
import { translate } from "@/lib/i18n";
import { DEFAULT_TEMPERATURE_UNIT, DEFAULT_WIND_SPEED_UNIT, formatTemperature, formatWindSpeed } from "@/lib/weather-utils";
import {
DEFAULT_TEMPERATURE_UNIT,
DEFAULT_WIND_SPEED_UNIT,
formatTemperature,
formatWindSpeed,
} from "@/lib/weather-utils";
import type { DailyForecast, HourlyForecast } from "@/types/forecast";
import type { TemperatureUnit, WindSpeedUnit } from "@/types/units";
@@ -24,14 +29,20 @@ function isDryWeatherCode(code: number | null) {
return code === null || (code >= 0 && code <= 3) || code === 45 || code === 48;
}
export function getEffectiveHourlyWeatherCode(hour: Pick<HourlyForecast, "weatherCode" | "precipitation" | "precipitationProbability">) {
export function getEffectiveHourlyWeatherCode(
hour: Pick<HourlyForecast, "weatherCode" | "precipitation" | "precipitationProbability">,
) {
const hasMeasuredPrecipitation = (hour.precipitation ?? 0) > 0;
const hasLikelyPrecipitation = (hour.precipitationProbability ?? 0) >= 70;
if (isDryWeatherCode(hour.weatherCode) && (hasMeasuredPrecipitation || hasLikelyPrecipitation)) return 61;
return hour.weatherCode;
}
export function formatForecastTemperature(value: number | null, language: Language, unit: TemperatureUnit = DEFAULT_TEMPERATURE_UNIT) {
export function formatForecastTemperature(
value: number | null,
language: Language,
unit: TemperatureUnit = DEFAULT_TEMPERATURE_UNIT,
) {
if (value === null) return "—";
return formatTemperature(value, language, unit);
}
@@ -41,7 +52,11 @@ export function formatForecastRainfall(value: number | null, language: Language)
return `${new Intl.NumberFormat(language === "pl" ? "pl-PL" : "en-GB", { maximumFractionDigits: 1 }).format(value)} mm`;
}
export function formatForecastWind(value: number | null, language: Language, unit: WindSpeedUnit = DEFAULT_WIND_SPEED_UNIT) {
export function formatForecastWind(
value: number | null,
language: Language,
unit: WindSpeedUnit = DEFAULT_WIND_SPEED_UNIT,
) {
if (value === null) return "—";
return formatWindSpeed(value, language, unit);
}
@@ -76,22 +91,24 @@ function getForecastHourOfDay(time: string) {
export function getUpcomingHourlyForecast(hours: HourlyForecast[], limit = 24) {
const currentHour = getWarsawForecastHour();
const currentTimestamp = parseForecastHour(currentHour);
const upcomingHours = currentTimestamp === null
? hours.filter((hour) => hour.time >= currentHour)
: hours.filter((hour) => {
const hourTimestamp = parseForecastHour(hour.time);
return hourTimestamp === null ? hour.time >= currentHour : hourTimestamp >= currentTimestamp;
});
const upcomingHours =
currentTimestamp === null
? hours.filter((hour) => hour.time >= currentHour)
: hours.filter((hour) => {
const hourTimestamp = parseForecastHour(hour.time);
return hourTimestamp === null ? hour.time >= currentHour : hourTimestamp >= currentTimestamp;
});
if (upcomingHours.length) return upcomingHours.slice(0, limit);
const currentHourOfDay = getForecastHourOfDay(currentHour);
const fallbackHours = currentHourOfDay === null
? hours
: hours.filter((hour) => {
const forecastHourOfDay = getForecastHourOfDay(hour.time);
return forecastHourOfDay === null || forecastHourOfDay >= currentHourOfDay;
});
const fallbackHours =
currentHourOfDay === null
? hours
: hours.filter((hour) => {
const forecastHourOfDay = getForecastHourOfDay(hour.time);
return forecastHourOfDay === null || forecastHourOfDay >= currentHourOfDay;
});
return (fallbackHours.length ? fallbackHours : hours).slice(0, limit);
}