Muchas gracias jmviper, cosas que se me van ocurriendo.
Como siempre tienes una buena forma de hacer las cosas mas sencillas
Pues es algo que se me paso por la cabeza y ya que lo dices, pues no esta de mas...
Pero cada vez que incluyes algo para mejorar al mismo tiempo salen otros problemas.
Veamos
Al añadir dicha comprobación, lo he dejado en 65 minutos se puede dar el caso aunque es improbable pero no imposible que las 2 lineas metar no se actualicen, entonces sobre todo de noche se mostraban los iconos de día.
Tras unas modificaciones en ese caso mostrara "Noche" al igual que solo mostrara Amanecer o Anochecer, si no están disponible ninguno de los 2 metar.
Luego tengo el desface de UTC a hora local, que también creo que lo solucione.
También añadí mas restricciones en la linea que muestra Despejado si en las estaciones Metar existen códigos "Despejados" para intentar que sea lo mas preciso posible dada las circunstancias.
<?php
$filegetmetar = ("/var/www/html/script/condicionesmx/getmetar.txt");
$filemetar = ("/var/www/html/script/condicionesmx/metar.txt");
$metar0 = file_get_contents("https://tgftp.nws.noaa.gov/data/observations/metar/stations/LEZL.TXT");
$metar1 = file_get_contents("https://tgftp.nws.noaa.gov/data/observations/metar/stations/LEMO.TXT");
$nometarfile = file_get_contents($filemetar);
$nometarfileok = substr($nometarfile,0,27);
$fecha0utc = substr($metar0,0,16);
$fecha1utc = substr($metar1,0,16);
$fechaactual= date("Y/m/d H:i");
echo $fecha0utc."<br>";
echo $fecha1utc."<br>";
$utc_date0 = DateTime::createFromFormat(
'Y/m/d H:i',
$fecha0utc,
new DateTimeZone('UTC'));
$acst_date0 = clone $utc_date0;
$acst_date0->setTimeZone(new DateTimeZone('Europe/Madrid'));
echo $acst_date0->format('Y/m/d H:i');
echo "<br>";
$fecha0= $acst_date0->format('Y/m/d H:i');
$utc_date1 = DateTime::createFromFormat(
'Y/m/d H:i',
$fecha1utc,
new DateTimeZone('UTC'));
$acst_date1 = clone $utc_date1;
$acst_date1->setTimeZone(new DateTimeZone('Europe/Madrid'));
echo $acst_date1->format('Y/m/d H:i');
echo "<br>";
$fecha1= $acst_date1->format('Y/m/d H:i');
function diferencia($fecha_1,$fecha_2)
{
$minutos = (strtotime($fecha_1)-strtotime($fecha_2))/60;
$minutos = abs($minutos); $minutos = floor($minutos);
return $minutos;
}
$metarti0 = diferencia($fecha0,$fechaactual);
$metarti1 = diferencia($fecha1,$fechaactual);
echo $metarti0;
echo "<br>";
echo $metarti1;
if ($metarti0 >= 65) {
$NOMETAR0 = "0.5";
$metar0 = $fecha0." \nMetar no actualizado\n";}
if ($metarti1 >= 65) {
$NOMETAR1 = "0.5";
$metar1 = $fecha1." \nMetar no actualizado\n";}
$NOMETAR = $NOMETAR0+$NOMETAR1;
$Metar = $metar0."\n".$metar1;
//Codigos
$SKC = strpos($Metar , 'SKC') !== false ? 1 : 0;
$CAVOK = strpos($Metar , 'CAVOK') !== false ? 1 : 0;
$NSC = strpos($Metar , 'NSC') !== false ? 1 : 0;
$NCD = strpos($Metar , 'NCD') !== false ? 1 : 0;
$FEW = strpos($Metar , 'FEW') !== false ? 1 : 0;
$SCT = strpos($Metar , 'SCT') !== false ? 1 : 0;
$BKN = strpos($Metar , 'BKN') !== false ? 1 : 0;
$OVC = strpos($Metar , 'OVC') !== false ? 1 : 0;
$FG = strpos($Metar , 'FG') !== false ? 1 : 0;
$BR = strpos($Metar , 'BR') !== false ? 1 : 0;
$VV = strpos($Metar , 'VV') !== false ? 1 : 0;
$DZ = strpos($Metar , 'DZ') !== false ? 1 : 0;
$SH = strpos($Metar , 'SH') !== false ? 1 : 0;
$RA = strpos($Metar , 'RA') !== false ? 1 : 0;
file_put_contents($filemetar, $CAVOK." ".$NSC." ".$NCD." ".$SKC." ".$FEW." ".$SCT." ".$BKN." ".$OVC." ".$FG." ".$BR." ".$VV." ".$DZ." ".$SH." ".$RA." ".$NOMETAR);
file_put_contents($filegetmetar, $Metar);
?>