From a49763dd739c3c68c4a8322896d594e926ac8e6b Mon Sep 17 00:00:00 2001 From: Zhineng Li Date: Mon, 5 Jan 2026 16:26:11 +0800 Subject: first commit --- src/Timestamp.php | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/Timestamp.php (limited to 'src/Timestamp.php') diff --git a/src/Timestamp.php b/src/Timestamp.php new file mode 100644 index 0000000..a23ba13 --- /dev/null +++ b/src/Timestamp.php @@ -0,0 +1,38 @@ +epoch = $epoch instanceof \DateTime + ? $epoch->getTimestamp() * 1000 + : ($epoch ?? 0); + + if ($this->epoch < 0) { + throw new \InvalidArgumentException('Epoch must be non-negative.'); + } + } + + public function value(): int + { + $now = (int) floor(microtime(as_float: true) * 1000); + + return $now - $this->epoch; + } +} -- cgit v1.2.3