diff --git a/www/go/core/util/DateTime.php b/www/go/core/util/DateTime.php index 351e2ace37..ba271eebfb 100644 --- a/www/go/core/util/DateTime.php +++ b/www/go/core/util/DateTime.php @@ -92,4 +92,17 @@ public static function daysInYear(int $year) : int { return date("L", mktime(0, 0, 0, 1, 1, $year)) ? 366 : 365; } + /** + * @param \DateTimeInterface $date + * @return \go\core\util\DateTime + * @throws \Exception + */ + public static function instance(\DateTimeInterface $date): DateTime + { + if ($date instanceof static) { + return clone $date; + } + + return new static($date->format('Y-m-d H:i:s.u'), $date->getTimezone()); + } }