Skip to content

Commit

Permalink
fix: Time::setTestNow() does not work with fa Locale
Browse files Browse the repository at this point in the history
ErrorException : DateTime::modify(): Failed to parse time string (۲۰۱۷-۰۳-۱۰ ۰۰:۰۰:۰۰) at position 0 (�): Unexpected character
 .../CodeIgniter4/system/I18n/Time.php:96
  • Loading branch information
kenjis committed Jun 14, 2022
1 parent e4414c8 commit 7f7e7cf
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion system/I18n/Time.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function __construct(?string $time = null, $timezone = null, ?string $loc
// If a test instance has been provided, use it instead.
if ($time === '' && static::$testNow instanceof self) {
$timezone = $timezone ?: static::$testNow->getTimezone();
$time = (string) static::$testNow->toDateTimeString();
$time = static::$testNow->format('Y-m-d H:i:s');
}

$timezone = $timezone ?: date_default_timezone_get();
Expand Down
14 changes: 14 additions & 0 deletions tests/system/I18n/TimeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1058,4 +1058,18 @@ public function testUnserializeTimeObject()
$this->assertTrue($time2->equals($time1));
$this->assertNotSame($time1, $time2);
}

public function testSetTestNowWithFaLocale()
{
$currentLocale = Locale::getDefault();
Locale::setDefault('fa');

Time::setTestNow('2017/03/10 12:00', 'Asia/Tokyo');

$now = Time::now()->format('c');

$this->assertSame('2017-03-10T12:00:00+09:00', $now);

Locale::setDefault($currentLocale);
}
}

0 comments on commit 7f7e7cf

Please sign in to comment.