Skip to content

Commit

Permalink
Merge pull request #274 from cakephp/date-create-test
Browse files Browse the repository at this point in the history
Add timezone to Date::createFromFormat() test
  • Loading branch information
markstory committed Aug 22, 2020
2 parents 04a3cd6 + 2ec6bd6 commit 30baea5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/Traits/FactoryTrait.php
Expand Up @@ -239,11 +239,11 @@ public static function createFromFormat($format, $time, $tz = null): ChronosInte
}

$errors = parent::getLastErrors();
if ($dt == false) {
if (!$dt) {
throw new InvalidArgumentException(implode(PHP_EOL, $errors['errors']));
}

$dt = static::instance($dt);
$dt = new static($dt->format('Y-m-d H:i:s.u'), $dt->getTimezone());
static::$_lastErrors = $errors;

return $dt;
Expand Down
4 changes: 2 additions & 2 deletions tests/TestCase/Date/ConstructTest.php
Expand Up @@ -416,7 +416,7 @@ public function testCreateFromDateTimeInterface($class)
*/
public function testCreateFromFormat($class)
{
$date = $class::createFromFormat('Y-m-d', '2014-02-01');
$this->assertSame('2014-02-01 00:00:00', $date->format('Y-m-d H:i:s'));
$date = $class::createFromFormat('Y-m-d P', '2014-02-01 Asia/Tokyo');
$this->assertSame('2014-02-01 00:00:00 America/Toronto', $date->format('Y-m-d H:i:s e'));
}
}

0 comments on commit 30baea5

Please sign in to comment.