123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- <?php
- namespace App\Yr\Forecast\Tabular\Time;
- /**
- * Time-object entity should inherit this
- */
- abstract class AbstractUnit implements DiffInterface {
- const DEFAULT_VARIANCE = 2;
- private $value;
- private $unit;
- /**
- * @param float The value
- * @param float The unit
- */
- public function __construct(float $value, string $unit) {
- $this->value = $value;
- $this->unit = $unit;
- }
- /**
- * Get the value
- *
- * @return float
- */
- public function getValue(): float {
- return $this->value;
- }
- /**
- * Return the unit (e.g «degree»)
- *
- * @return string
- */
- public function getUnit(): string {
- return $this->unit;
- }
- /**
- * {@inheritDoc}
- */
- public function diff(DiffInterface $d): int {
- if ($d instanceof $this)
- return $this->value - $d->getValue();
- return 0;
- }
- public function __toString(): string {
- return sprintf(
- "%s: %f %s", basename(str_replace(
- '\\', DIRECTORY_SEPARATOR, get_class($this)
- )), $this->value, $this->unit);
- }
- }
|