Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/Time.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ abstract class Time
'h' => self::Hour,
];

private static Time\Duration $_zeroDuration;

private function __construct()
{
// not designed to be constructed
Expand Down Expand Up @@ -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}");
Expand Down
4 changes: 2 additions & 2 deletions src/Time/Duration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}";
Expand All @@ -159,7 +159,7 @@ private static function _fmtInt(string &$buff, int $v)
}
}

public function jsonSerialize(): mixed
public function jsonSerialize(): int
{
return $this->ns;
}
Expand Down
1 change: 1 addition & 0 deletions src/Time/Time.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down