41 lines
801 B
PHP
41 lines
801 B
PHP
<?php
|
|
|
|
namespace Toalett\Redis\Timeseries\Model;
|
|
|
|
final class Value
|
|
{
|
|
private ?string $timestamp;
|
|
private float $value;
|
|
|
|
public function __construct(?string $timestamp, float $value)
|
|
{
|
|
$this->timestamp = $timestamp;
|
|
$this->value = $value;
|
|
}
|
|
|
|
public static function recordNow(float $value): Value
|
|
{
|
|
return new self(time(), $value);
|
|
}
|
|
|
|
public static function auto(float $value): Value
|
|
{
|
|
return new self(null, $value);
|
|
}
|
|
|
|
public function getTimestamp(): string
|
|
{
|
|
return $this->timestamp ?? '*';
|
|
}
|
|
|
|
public function getValue(): float
|
|
{
|
|
return $this->value;
|
|
}
|
|
|
|
public function __toString(): string
|
|
{
|
|
return sprintf('(' . $this->timestamp . ':' . $this->value . ')');
|
|
}
|
|
}
|