Example #1
0
    public function render()
    {
        $template = <<<TEMPLATE
METAR: %s

Location: %s
Day of month: %s Time: %sZ

Temperature: %.1fC Dew point: %.1fC

QNH: %d hPa (%.2f inHg)

Wind:
Direction: %s
Speed: %skt

Visibility: %s

TEMPLATE;
        $weather = sprintf($template, $this->message->getAsText(), $this->message->getLocation(), $this->message->getDayOfMonth(), $this->message->getZuluTime(), $this->message->getTemperature()->toUnit('C'), $this->message->getDewPoint()->toUnit('C'), (int) $this->message->getQNH()->toUnit('hPa'), $this->message->getQNH()->toUnit('inHg'), $this->message->getWindDirection(), $this->message->getWindSpeed()->toUnit('kt'), $this->message->getVisibility());
        if ($clouds = $this->message->getCloudCover()) {
            $weather .= "Clouds:\n";
            foreach ($clouds as $cloudCover) {
                $weather .= sprintf("- %s at %sft\n", $cloudCover['type'], $cloudCover['level']);
            }
            $weather .= "\n";
        }
        if ($info = $this->message->getWeather()) {
            $weather .= "Weather:";
            foreach ($info as $row) {
                $weather .= sprintf("\n- %s", $row);
            }
        }
        return $weather;
    }
Example #2
0
 public function testEPMO()
 {
     $metar = new METAR("EPMO 170930Z 03006KT 1200 R08/1400D -DZ BR BKN003 OVC036 12/12 Q1009");
     $this->assertEquals("EPMO", $metar->getLocation());
     $this->assertEquals(17, $metar->getDayOfMonth());
     $this->assertEquals("0930", $metar->getZuluTime());
     $this->assertEquals("030", $metar->getWindDirection());
     $this->assertEquals(6, $metar->getWindSpeed()->toUnit('kt'));
     $this->assertEquals(12, $metar->getTemperature()->toUnit('C'));
     $this->assertEquals(12, $metar->getDewPoint()->toUnit('C'));
     $this->assertEquals(1200, $metar->getVisibility());
     $this->assertEquals(array(array('type' => 'BKN', 'level' => 300, 'significant' => ''), array('type' => 'OVC', 'level' => 3600, 'significant' => '')), $metar->getCloudCover());
     $this->assertEquals(array(0 => 'Light Drizzle', 1 => 'Mist'), $metar->getWeather());
     $this->assertEquals(1009, $metar->getQNH()->toUnit('hPa'));
 }