add test for timezone in instance from DateTime object
temporary fix for php 8.1 warning
This commit is contained in:
1 parent
84b7bf87a1
commit
4db4b98065
3 files changed
+22
-6
No files matched your search
@@ -31,10 +31,11 @@ trait Creator
|
||||
}
|
||||
|
||||
try {
|
||||
$tz = static::createTimeZone($timezone);
|
||||
parent::__construct($dt, $tz);
|
||||
if ($datetime instanceof DateTime) {
|
||||
parent::setTimezone($tz);
|
||||
parent::__construct($dt);
|
||||
parent::setTimezone($datetime->getTimezone());
|
||||
} else {
|
||||
parent::__construct($dt, static::createTimeZone($timezone));
|
||||
}
|
||||
self::loadMessages();
|
||||
} catch (Exception $exception) {
|
||||
@@ -130,7 +131,9 @@ trait Creator
|
||||
*/
|
||||
public function datetime()
|
||||
{
|
||||
return new DateTime(date('Y-m-d H:i:s', $this->getTimestamp()), $this->getTimezone());
|
||||
$dt = new DateTime(date('Y-m-d H:i:s', $this->getTimestamp()));
|
||||
$dt->setTimezone($this->getTimezone());
|
||||
return $dt;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace Hekmatinasser\Verta\Traits;
|
||||
|
||||
use Hekmatinasser\Notowo\Notowo;
|
||||
use Hekmatinasser\Verta\Verta;
|
||||
use ReturnTypeWillChange;
|
||||
|
||||
trait Formatting
|
||||
{
|
||||
@@ -325,7 +326,8 @@ trait Formatting
|
||||
* @param string $format
|
||||
* @return string
|
||||
*/
|
||||
public function format(string $format): string
|
||||
#[ReturnTypeWillChange]
|
||||
public function format($format)
|
||||
{
|
||||
return $this->date($this->strftime($format));
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user