Show weather in both Celsius and Fahrenheit

This commit is contained in:
2026-06-27 18:59:32 -05:00
parent 9a130be5e0
commit 085ecd5ce4
3 changed files with 16 additions and 9 deletions
+11 -5
View File
@@ -25,17 +25,23 @@ export async function GET() {
const current = json.current_weather || {};
const daily = json.daily || {};
const celsius = (v: number | undefined) => (v === undefined ? undefined : Math.round(v));
const fahrenheit = (v: number | undefined) => (v === undefined ? undefined : Math.round((v * 9) / 5 + 32));
return NextResponse.json({
data: {
current: {
temperature: current.temperature,
celsius: celsius(current.temperature),
fahrenheit: fahrenheit(current.temperature),
windspeed: current.windspeed,
weathercode: current.weathercode,
summary: codeMap[current.weathercode] || 'Unknown',
},
today: {
max: daily.temperature_2m_max?.[0],
min: daily.temperature_2m_min?.[0],
maxC: celsius(daily.temperature_2m_max?.[0]),
minC: celsius(daily.temperature_2m_min?.[0]),
maxF: fahrenheit(daily.temperature_2m_max?.[0]),
minF: fahrenheit(daily.temperature_2m_min?.[0]),
weathercode: daily.weathercode?.[0],
summary: codeMap[daily.weathercode?.[0]] || 'Unknown',
},
@@ -46,8 +52,8 @@ export async function GET() {
return NextResponse.json(
{
data: {
current: { temperature: 18, windspeed: 6, weathercode: 1, summary: 'Mainly clear' },
today: { max: 22, min: 10, weathercode: 1, summary: 'Mainly clear' },
current: { celsius: 18, fahrenheit: 64, windspeed: 6, weathercode: 1, summary: 'Mainly clear' },
today: { maxC: 22, minC: 10, maxF: 72, minF: 50, weathercode: 1, summary: 'Mainly clear' },
},
},
{ status: 200 }