Skip to content

Commit

Permalink
Merge 7c33919 into 7e77b7d
Browse files Browse the repository at this point in the history
  • Loading branch information
othercorey committed Apr 23, 2020
2 parents 7e77b7d + 7c33919 commit 600df25
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 18 deletions.
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -56,7 +56,7 @@
"cs-check": "phpcs",
"cs-fix": "phpcbf",
"benchmark": "phpbench run --report=chronos",
"phpstan": "phpstan analyze -c phpstan.neon -l 3 src/",
"phpstan": "phpstan analyze -c phpstan.neon src/",
"phpstan-setup": "cp composer.json composer.backup && composer require --dev phpstan/phpstan:^0.12 && mv composer.backup composer.json"
}
}
2 changes: 1 addition & 1 deletion phpstan.neon
@@ -1,5 +1,5 @@
parameters:
level: 4
level: 5
ignoreErrors:
- '#Access to an undefined property Cake\\Chronos\\ChronosInterface::\$tz#'
- '#Unsafe usage of new static().#'
9 changes: 5 additions & 4 deletions src/Chronos.php
Expand Up @@ -84,7 +84,7 @@ class Chronos extends DateTimeImmutable implements ChronosInterface
* Please see the testing aids section (specifically static::setTestNow())
* for more on the possibility of this constructor returning a test instance.
*
* @param string|int|null $time Fixed or relative time
* @param \DateTime|\DateTimeImmutable|string|int|null $time Fixed or relative time
* @param \DateTimeZone|string|null $tz The timezone for the instance
*/
public function __construct($time = 'now', $tz = null)
Expand All @@ -93,12 +93,13 @@ public function __construct($time = 'now', $tz = null)
$tz = $tz instanceof DateTimeZone ? $tz : new DateTimeZone($tz);
}

if ($time instanceof \DateTimeInterface) {
$time = $time->format('Y-m-d H:i:s.u');
}

static::$_lastErrors = [];
$testNow = static::getTestNow();
if ($testNow === null) {
if ($time instanceof \DateTimeInterface) {
$time = $time->format('Y-m-d H:i:s.u');
}
parent::__construct($time ?? 'now', $tz);

return;
Expand Down
9 changes: 5 additions & 4 deletions src/MutableDateTime.php
Expand Up @@ -76,7 +76,7 @@ class MutableDateTime extends DateTime implements ChronosInterface
* Please see the testing aids section (specifically static::setTestNow())
* for more on the possibility of this constructor returning a test instance.
*
* @param string|int|null $time Fixed or relative time
* @param \DateTime|\DateTimeImmutable|string|int|null $time Fixed or relative time
* @param \DateTimeZone|string|null $tz The timezone for the instance
*/
public function __construct($time = 'now', $tz = null)
Expand All @@ -85,11 +85,12 @@ public function __construct($time = 'now', $tz = null)
$tz = $tz instanceof DateTimeZone ? $tz : new DateTimeZone($tz);
}

if ($time instanceof \DateTimeInterface) {
$time = $time->format('Y-m-d H:i:s.u');
}

$testNow = Chronos::getTestNow();
if ($testNow === null) {
if ($time instanceof \DateTimeInterface) {
$time = $time->format('Y-m-d H:i:s.u');
}
parent::__construct($time ?? 'now', $tz);

return;
Expand Down
9 changes: 1 addition & 8 deletions src/Traits/TimezoneTrait.php
Expand Up @@ -52,13 +52,6 @@ public function tz($value): ChronosInterface
*/
public function setTimezone($value): ChronosInterface
{
$date = parent::setTimezone(static::safeCreateDateTimeZone($value));

// https://bugs.php.net/bug.php?id=72338
// this is workaround for this bug
// Needed for PHP below 7.0 version
$date->getTimestamp();

return $date;
return parent::setTimezone(static::safeCreateDateTimeZone($value));
}
}

0 comments on commit 600df25

Please sign in to comment.