diff --git a/src/Time.php b/src/Time.php index fecd7a0..b24ad1f 100644 --- a/src/Time.php +++ b/src/Time.php @@ -32,6 +32,8 @@ abstract class Time 'h' => self::Hour, ]; + private static Time\Duration $_zeroDuration; + private function __construct() { // not designed to be constructed @@ -254,6 +256,17 @@ public static function Duration(null|string|int|float|Time\Duration|\DateInterva } } + /** + * Returns a zero duration instance. + */ + public static function ZeroDuration(): Time\Duration + { + if (!isset(self::$_zeroDuration)) { + self::$_zeroDuration = new Time\Duration(0); + } + return self::$_zeroDuration; + } + private static function _invalidDurationException(string $orig): \InvalidArgumentException { return new \InvalidArgumentException("Invalid duration: {$orig}"); diff --git a/src/Time/Duration.php b/src/Time/Duration.php index 417e9b8..a901eb9 100644 --- a/src/Time/Duration.php +++ b/src/Time/Duration.php @@ -147,7 +147,7 @@ private static function _fmtFrac(string &$buff, int $v, int $prec): int return $v; } - private static function _fmtInt(string &$buff, int $v) + private static function _fmtInt(string &$buff, int $v): void { if (0 === $v) { $buff = "0{$buff}"; @@ -159,7 +159,7 @@ private static function _fmtInt(string &$buff, int $v) } } - public function jsonSerialize(): mixed + public function jsonSerialize(): int { return $this->ns; } diff --git a/src/Time/Time.php b/src/Time/Time.php index f4fef08..2ab143c 100644 --- a/src/Time/Time.php +++ b/src/Time/Time.php @@ -13,6 +13,7 @@ class Time extends \DateTime /** * @throws \DateMalformedStringException + * @throws \Exception */ #[\ReturnTypeWillChange] public static function createFromFormat(string $format, string $datetime, \DateTimeZone $timezone = null): bool|static