Skip to content

Commit 3470621

Browse files
committed
fix(weather): night sunrise label uses the same strict HH:MM validator as the sky math (codex)
1 parent 160c6f9 commit 3470621

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

‎src/components/WeatherHero.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useEffect, useMemo, useRef, useState } from "react";
22
import type { Weather } from "../lib/api";
33
import { bkkClock } from "../lib/format";
4-
import { condText, feelsLike, skyPhase, skyWx, sunPos, solarInfo, type SkyPhase, type SkyWx } from "../lib/weather";
4+
import { hm, condText, feelsLike, skyPhase, skyWx, sunPos, solarInfo, type SkyPhase, type SkyWx } from "../lib/weather";
55

66
/* Live sky for the weather tab: the real time of day (from the location's sunrise/sunset),
77
the sun on its actual arc, the moon + stars at night, and clouds / rain / lightning that
@@ -119,7 +119,7 @@ export function WeatherHero({ weather: w, force }: { weather: Weather; force?: {
119119
</div>
120120

121121
{night ? (
122-
<div className="wh-pv"><span>กลางคืน · แผงพักการผลิต</span><span className="dim">รอแดด {/^\d{1,2}:\d{2}$/.test(w.sun?.rise || "") ? `${w.sun!.rise} น.` : "พรุ่งนี้"}</span></div>
122+
<div className="wh-pv"><span>กลางคืน · แผงพักการผลิต</span><span className="dim">รอแดด {hm(w.sun?.rise) != null ? `${w.sun!.rise!.trim()} น.` : "พรุ่งนี้"}</span></div>
123123
) : (
124124
<div className="wh-pv">
125125
<span>แสงแดดวันนี้ · {solar.label}</span><span>{solar.pct}%</span>

‎src/lib/weather.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export const siteMinutes = (now: Date) => {
4242
return ((m % 1440) + 1440) % 1440;
4343
};
4444
// strict "HH:MM" → minutes; anything else (e.g. the "—" placeholder) → null, never 00:00
45-
const hm = (s?: string | null): number | null => {
45+
export const hm = (s?: string | null): number | null => {
4646
const m = /^(\d{1,2}):(\d{2})$/.exec(String(s ?? "").trim());
4747
if (!m) return null;
4848
const h = +m[1], mi = +m[2];

0 commit comments

Comments
 (0)