Pressure.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace App\Yr\Forecast\Tabular\Time;
  3. /**
  4. * Airpressure
  5. *
  6. * @author Joachim M. Giæver (joachim[]giaever.org)
  7. */
  8. class Pressure extends AbstractUnit {
  9. const NORMAL_PRESSURE = 1015.0;
  10. /**
  11. * @param \SimpleXMLElement $xml XML containing the pressure
  12. */
  13. public function __construct(\SimpleXMLElement $xml) {
  14. parent::__construct(
  15. (float)$xml['value'],
  16. (string)$xml['unit']
  17. );
  18. }
  19. /**
  20. * Check if the pressure is below normal pressure
  21. *
  22. * @return bool
  23. */
  24. public function isLowPressure(): bool {
  25. return $this->getValue() < self::NORMAL_PRESSURE;
  26. }
  27. /**
  28. * Check if the pressure is above normal pressure
  29. *
  30. * @return bool
  31. */
  32. public function isHighPressure(): bool {
  33. return $this->getValue() > self::NORMAL_PRESSURE;
  34. }
  35. /**
  36. * {@inheritDoc}
  37. */
  38. public function diff(DiffInterface $d): int {
  39. if ($diff = parent::diff($d))
  40. return $this->isLowPressure() == $d->isLowPressure() ? 0 : 1;
  41. return 0;
  42. }
  43. }