Skip to content

Commit

Permalink
#1163 Add instance method to DateTime
Browse files Browse the repository at this point in the history
  • Loading branch information
michalcharvat committed Jul 4, 2024
1 parent 55a47d6 commit 1e158fa
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions www/go/core/util/DateTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

0 comments on commit 1e158fa

Please sign in to comment.