fix(vigilance): écheance dynamique selon l'heure courante
Some checks are pending
Deploy info-canicule / deploy (push) Waiting to run

Le bulletin MF est publié 2× par jour (~6h et ~16h Paris). Pendant la nuit
(de minuit au prochain bulletin ~6h), on est techniquement dans le J+1 du
bulletin courant, qui correspond pour l'utilisateur à "aujourd'hui réel".

Avant : on affichait toujours J → la nuit, la carte montrait les alertes
"d'hier" alors que l'utilisateur cherche "celles d'aujourd'hui réel".
Symptôme : Florian voit du orange sur vigilance.meteofrance.fr (qui prend
la bonne écheance) mais pas chez nous (qui restait collé sur J).

Fix :
- currentEcheance(snapshot) compare now au end_time du J : si dépassé, J1.
- index.astro + departement.astro utilisent cette écheance pour
  "aujourd'hui". Page dept : "demain" = J1 si on est sur J, vide sinon.
- Labels rendus dynamiques : "Niveau par département — mardi 26 mai" au
  lieu de "(aujourd'hui)" générique.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Florian 2026-05-26 02:22:19 +02:00
parent 27441cdbb8
commit 0b418bd031
3 changed files with 69 additions and 12 deletions

View file

@ -2,7 +2,7 @@
import Base from '../../layouts/Base.astro';
import VigilanceChip from '../../components/VigilanceChip.astro';
import VigilanceLegend from '../../components/VigilanceLegend.astro';
import { getVigilanceSnapshot, alertsForDepartement } from '../../lib/vigilance';
import { getVigilanceSnapshot, alertsForDepartement, currentEcheance } from '../../lib/vigilance';
import { getDepartement, isDrom } from '../../lib/departements';
import { PHENOMENA, COLOR_LABEL } from '../../lib/phenomena';
import { ADVICE, EMERGENCY_NUMBERS } from '../../lib/advice';
@ -73,10 +73,19 @@ if (!drom) {
const stationLabel = hourly ? `${hourly.stationName} (${hourly.distKm} km)` : null;
const today = snapshot ? alertsForDepartement(snapshot, dept.code, 'J') : [];
const tomorrow = snapshot ? alertsForDepartement(snapshot, dept.code, 'J1') : [];
// "Aujourd'hui" = écheance courante (J ou J1 selon l'heure)
// "Demain" = J1 si on est encore sur J, sinon pas dispo (bulletin n'a pas J2)
const ech = snapshot ? currentEcheance(snapshot) : 'J';
const today = snapshot ? alertsForDepartement(snapshot, dept.code, ech) : [];
const tomorrow = (snapshot && ech === 'J') ? alertsForDepartement(snapshot, dept.code, 'J1') : [];
const highest = today[0];
const adviceFor = highest && ADVICE[highest.phenomenonId];
const labelDate = (iso: string) => new Date(iso).toLocaleDateString('fr-FR', {
weekday: 'long', day: 'numeric', month: 'long', timeZone: 'Europe/Paris',
});
const todayLabel = today[0] ? labelDate(today[0].beginTime) : '';
const tomorrowLabel = tomorrow[0] ? labelDate(tomorrow[0].beginTime) : '';
---
<Base
@ -117,7 +126,9 @@ const adviceFor = highest && ADVICE[highest.phenomenonId];
{
!drom && !error && today.length === 0 && (
<div class="rounded border border-green-200 bg-green-50 p-4">
<p class="font-semibold text-green-800">Aucune vigilance particulière aujourd'hui.</p>
<p class="font-semibold text-green-800">
Aucune vigilance particulière {todayLabel ? `pour ${todayLabel}` : "aujourd'hui"}.
</p>
<p class="text-sm text-green-700">Le département est en niveau vert pour tous les phénomènes.</p>
</div>
)
@ -126,7 +137,9 @@ const adviceFor = highest && ADVICE[highest.phenomenonId];
{
!drom && !error && today.length > 0 && (
<>
<h2 class="mb-3 text-xl font-semibold">Alertes en cours</h2>
<h2 class="mb-3 text-xl font-semibold capitalize">
Alertes en cours {todayLabel ? `— ${todayLabel}` : ''}
</h2>
<ul class="space-y-3">
{today.map((a) => {
const phen = PHENOMENA[a.phenomenonId];
@ -162,7 +175,9 @@ const adviceFor = highest && ADVICE[highest.phenomenonId];
{
!drom && !error && tomorrow.length > 0 && (
<div class="mt-8">
<h2 class="mb-3 text-xl font-semibold">Prévision pour demain</h2>
<h2 class="mb-3 text-xl font-semibold capitalize">
Prévision {tomorrowLabel ? `— ${tomorrowLabel}` : 'pour demain'}
</h2>
<ul class="space-y-2">
{tomorrow.map((a) => (
<li class="flex flex-wrap items-center justify-between gap-3 rounded border border-slate-200 px-3 py-2">