1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- <?php
- namespace App\Yr\Forecast\Tabular\Time;
- class WindSpeed extends AbstractUnit {
- const DEFAULT_VARIANCE = (4.9 / 3.5);
- const UNIT_MPS = 'mp/s';
- const UNIT_FTS = 'ft/s';
- const UNIT_KMH = 'km/h';
- const UNIT_KNOTS = 'knots';
- private $name;
- public function __construct(\SimpleXMLElement $xml){
- parent::__construct(
- (float)$xml['mps'], self::UNIT_MPS
- );
- $this->name = (string)$xml['name'];
- }
- public function convertTo(string $unit): int {
- switch ($unit) {
- case self::UNIT_KNOTS:
- return $this->getValue() * 1.9438445;
- case self::UNIT_FTS:
- return $this->getValue() * 3.28084;
- case self::UNIT_KMH:
- return $this->getValue() * 3.6;
- }
- }
- public function getName(): string {
- return $this->name;
- }
- public function __toString(): string {
- return sprintf(
- '%s (%s)', parent::__toString(), $this->name
- );
- }
- }
|