From 1e158fa61436dc88db1fab63fd80a977ccf7a957 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Charva=CC=81t?= Date: Thu, 4 Jul 2024 15:43:31 +0200 Subject: [PATCH] #1163 Add instance method to DateTime --- www/go/core/util/DateTime.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) 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()); + } }