Show weather in both Celsius and Fahrenheit
This commit is contained in:
@@ -25,17 +25,23 @@ export async function GET() {
|
|||||||
const current = json.current_weather || {};
|
const current = json.current_weather || {};
|
||||||
const daily = json.daily || {};
|
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({
|
return NextResponse.json({
|
||||||
data: {
|
data: {
|
||||||
current: {
|
current: {
|
||||||
temperature: current.temperature,
|
celsius: celsius(current.temperature),
|
||||||
|
fahrenheit: fahrenheit(current.temperature),
|
||||||
windspeed: current.windspeed,
|
windspeed: current.windspeed,
|
||||||
weathercode: current.weathercode,
|
weathercode: current.weathercode,
|
||||||
summary: codeMap[current.weathercode] || 'Unknown',
|
summary: codeMap[current.weathercode] || 'Unknown',
|
||||||
},
|
},
|
||||||
today: {
|
today: {
|
||||||
max: daily.temperature_2m_max?.[0],
|
maxC: celsius(daily.temperature_2m_max?.[0]),
|
||||||
min: daily.temperature_2m_min?.[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],
|
weathercode: daily.weathercode?.[0],
|
||||||
summary: codeMap[daily.weathercode?.[0]] || 'Unknown',
|
summary: codeMap[daily.weathercode?.[0]] || 'Unknown',
|
||||||
},
|
},
|
||||||
@@ -46,8 +52,8 @@ export async function GET() {
|
|||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
{
|
{
|
||||||
data: {
|
data: {
|
||||||
current: { temperature: 18, windspeed: 6, weathercode: 1, summary: 'Mainly clear' },
|
current: { celsius: 18, fahrenheit: 64, windspeed: 6, weathercode: 1, summary: 'Mainly clear' },
|
||||||
today: { max: 22, min: 10, weathercode: 1, summary: 'Mainly clear' },
|
today: { maxC: 22, minC: 10, maxF: 72, minF: 50, weathercode: 1, summary: 'Mainly clear' },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{ status: 200 }
|
{ status: 200 }
|
||||||
|
|||||||
@@ -12,8 +12,8 @@ interface CalendarEvent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface WeatherData {
|
interface WeatherData {
|
||||||
current?: { temperature: number; summary: string };
|
current?: { celsius: number; fahrenheit: number; summary: string };
|
||||||
today?: { max: number; min: number; summary: string };
|
today?: { maxC: number; minC: number; maxF: number; minF: number; summary: string };
|
||||||
}
|
}
|
||||||
|
|
||||||
const gold = '#E8A849';
|
const gold = '#E8A849';
|
||||||
@@ -66,9 +66,9 @@ export default function CalendarStrip() {
|
|||||||
{
|
{
|
||||||
id: 9999,
|
id: 9999,
|
||||||
date: new Date().toISOString().split('T')[0],
|
date: new Date().toISOString().split('T')[0],
|
||||||
title: `${weather.current?.temperature ?? '--'}°C ${weather.current?.summary ?? ''}`,
|
title: `${weather.current?.celsius ?? '--'}°C / ${weather.current?.fahrenheit ?? '--'}°F ${weather.current?.summary ?? ''}`,
|
||||||
type: 'weather' as const,
|
type: 'weather' as const,
|
||||||
description: `Today ${weather.today?.max ?? '--'}° / ${weather.today?.min ?? '--'}°`,
|
description: `Today ${weather.today?.maxC ?? '--'}°C / ${weather.today?.maxF ?? '--'}°F · ${weather.today?.minC ?? '--'}°C / ${weather.today?.minF ?? '--'}°F`,
|
||||||
color: '#4FC3F7',
|
color: '#4FC3F7',
|
||||||
isWeather: true,
|
isWeather: true,
|
||||||
},
|
},
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user