From e45bd66388e36877ab367c8d9bfddd95dde8980e Mon Sep 17 00:00:00 2001 From: "B.Fatih KOZ" <74361521+FatihKoz@users.noreply.github.com> Date: Mon, 15 Mar 2021 17:41:05 +0300 Subject: [PATCH] Fix Metar Decoding / Wind check for Wind Chill (#1072) * Fix Metar Decoding / Wind check for Wind Chill PR aims to fix the bug #1071 by checking both the wind speed and it's value for starting Wind Chill calculation. --- app/Support/Metar.php | 2 +- tests/MetarTest.php | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/app/Support/Metar.php b/app/Support/Metar.php index 7f5635a2..25c573cf 100644 --- a/app/Support/Metar.php +++ b/app/Support/Metar.php @@ -1772,7 +1772,7 @@ class Metar implements \ArrayAccess */ private function calculate_wind_chill($temperature_f): void { - if ($temperature_f < 51 && $this->result['wind_speed'] !== 0) { + if ($temperature_f < 51 && $this->result['wind_speed'] && $this->result['wind_speed'] !== 0) { $windspeed = $this->result['wind_speed']->toUnit('mph'); if ($windspeed > 3) { $chill_f = 35.74 + 0.6215 * $temperature_f - 35.75 * ($windspeed ** 0.16); diff --git a/tests/MetarTest.php b/tests/MetarTest.php index 1838ef28..43703b9c 100644 --- a/tests/MetarTest.php +++ b/tests/MetarTest.php @@ -151,6 +151,19 @@ class MetarTest extends TestCase $this->assertEquals('Few at 1500 feet; few at 25000 feet', $metar['clouds_report_ft']); } + /** + * https://github.com/nabeelio/phpvms/issues/1071 + */ + public function testMetarWindSpeedChill() + { + $metar = 'EKYT 091020Z /////KT CAVOK 02/M03 Q1019'; + $metar = Metar::parse($metar); + + $this->assertEquals('VFR', $metar['category']); + $this->assertNull($metar['wind_speed']); + $this->assertEquals(6.21, $metar['visibility']['mi']); + } + /** * Visibility in KM not parsed *