Update station type handling and current time logic for quai display
This commit is contained in:
1 parent
e42f6c01ec
commit
503a70bd49
5 files changed
+368
-40
No files matched your search
@@ -86,6 +86,15 @@ export default function ClassiquesArrivees(){
|
||||
|
||||
// État pour alterner l'affichage toutes les 3 secondes
|
||||
const [showStatus, setShowStatus] = useState(false);
|
||||
// État pour l'heure actuelle, mise à jour chaque seconde pour la logique d'affichage du quai
|
||||
const [currentTime, setCurrentTime] = useState(new Date());
|
||||
|
||||
// Met à jour l'heure actuelle chaque seconde
|
||||
useEffect(() => {
|
||||
const id = setInterval(() => setCurrentTime(new Date()), 1000);
|
||||
return () => clearInterval(id);
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
const id = setInterval(() => setShowStatus(s => !s), 3000);
|
||||
return () => clearInterval(id);
|
||||
@@ -186,9 +195,9 @@ export default function ClassiquesArrivees(){
|
||||
// retourne le threshold (en minutes) pour afficher le quai selon le type de gare
|
||||
const thresholdForStationType = useCallback((type) => {
|
||||
if (!type) return 0;
|
||||
const t = String(type).toLowerCase();
|
||||
if (t.includes('interurb') || t.includes('interurbaine')) return 360; // 6 heures
|
||||
if (t.includes('ville')) return 30; // 30 minutes
|
||||
const t = String(type).trim().toLowerCase();
|
||||
if (t === 'interurbaine' || t.includes('interurb')) return 360; // 6 heures
|
||||
if (t === 'ville' || t.includes('ville')) return 30; // 30 minutes
|
||||
return 0;
|
||||
}, []);
|
||||
|
||||
@@ -537,7 +546,41 @@ export default function ClassiquesArrivees(){
|
||||
const i = weekdayIndex(d);
|
||||
switch(i) { case 1: return 'circule_lundi'; case 2: return 'circule_mardi'; case 3: return 'circule_mercredi'; case 4: return 'circule_jeudi'; case 5: return 'circule_vendredi'; case 6: return 'circule_samedi'; case 0: return 'circule_dimanche'; default: return null; }
|
||||
};
|
||||
const isPublicHoliday = (d) => {
|
||||
const y = d.getFullYear();
|
||||
const m = d.getMonth() + 1;
|
||||
const day = d.getDate();
|
||||
const s = `${y}-${String(m).padStart(2, '0')}-${String(day).padStart(2, '0')}`;
|
||||
const holidays = [
|
||||
`${y}-01-01`, // Jour de l'an
|
||||
`${y}-05-01`, // Fête du Travail
|
||||
`${y}-05-08`, // Victoire 1945
|
||||
`${y}-07-14`, // Fête nationale
|
||||
`${y}-08-15`, // Assomption
|
||||
`${y}-11-01`, // Toussaint
|
||||
`${y}-11-11`, // Armistice 1918
|
||||
`${y}-12-25`, // Noël
|
||||
];
|
||||
// Dates variables pour 2026
|
||||
if (y === 2026) {
|
||||
holidays.push('2026-04-06'); // Lundi de Pâques
|
||||
holidays.push('2026-05-14'); // Ascension
|
||||
holidays.push('2026-05-25'); // Lundi de Pentecôte
|
||||
}
|
||||
return holidays.includes(s);
|
||||
};
|
||||
|
||||
const circulatesOn = (h, d) => {
|
||||
if (isPublicHoliday(d)) {
|
||||
const v = h['circule_jours_feries'];
|
||||
if (typeof v === 'boolean') return v;
|
||||
if (typeof v === 'number') return v === 1;
|
||||
if (typeof v === 'string') {
|
||||
const s = v.trim().toLowerCase();
|
||||
return s === 'true' || s === '1' || s === 't' || s === 'y' || s === 'yes';
|
||||
}
|
||||
return (typeof v === 'undefined' || v === null) ? false : Boolean(v);
|
||||
}
|
||||
const col = weekdayNameForColumn(d);
|
||||
if (!col) return true;
|
||||
const v = h[col];
|
||||
@@ -701,8 +744,7 @@ export default function ClassiquesArrivees(){
|
||||
// Ne pas afficher le quai si le train est supprimé ou si aucun quai n'est défini
|
||||
let showPlatform = !(status && status.label === 'supprimé') && Boolean(platform);
|
||||
if (showPlatform) {
|
||||
const now = new Date();
|
||||
const nowHM = now.getHours()*60 + now.getMinutes();
|
||||
const nowHM = currentTime.getHours()*60 + currentTime.getMinutes(); // Use currentTime
|
||||
const sched = (typeof horaire._arrHM === 'number') ? horaire._arrHM : parseTimeHM(horaire.heure_arrivee || horaire.arrival_time || horaire.time || horaire._rawArrTime || '');
|
||||
const threshold = thresholdForStationType(stationType);
|
||||
if (typeof sched === 'number' && typeof threshold === 'number' && threshold > 0) {
|
||||
@@ -742,5 +784,3 @@ export default function ClassiquesArrivees(){
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user