Supported Versions: PHP 5 >= 5.1.0, PHP 7, PHP 8
Sets the default timezone used by all date/time functions in a script
<?php date_default_timezone_set(string $timezoneId): bool
<?php $app->detectEnvironment(fn () => $config->get('app.env', 'production'));
date_default_timezone_set($config->get('app.timezone', 'UTC'));
mb_internal_encoding('UTF-8');
}
<?php protected function setUp(): void
{
$this->defaultTimezone = date_default_timezone_get();
date_default_timezone_set('UTC');
}
protected function tearDown(): void
<?php protected function tearDown(): void
{
date_default_timezone_set($this->defaultTimezone);
Carbon::setTestNow(null);
m::close();
}
<?php public function testValidateDateAndFormat()
{
date_default_timezone_set('UTC');
$trans = $this->getIlluminateArrayTranslator();
$v = new Validator($trans, ['x' => '2000-01-01'], ['x' => 'date']);
$this->assertTrue($v->passes());
<?php public function testDateEquals()
{
date_default_timezone_set('UTC');
$trans = $this->getIlluminateArrayTranslator();
$v = new Validator($trans, ['x' => '2000-01-01'], ['x' => 'date_equals:2000-01-01']);
$this->assertTrue($v->passes());
<?php public function testDateEqualsRespectsCarbonTestNowWhenParameterIsRelative()
{
date_default_timezone_set('UTC');
$trans = $this->getIlluminateArrayTranslator();
Carbon::setTestNow(new Carbon('2018-01-01'));
<?php public function testBeforeAndAfter()
{
date_default_timezone_set('UTC');
$trans = $this->getIlluminateArrayTranslator();
$v = new Validator($trans, ['x' => '2000-01-01'], ['x' => 'Before:2012-01-01']);
$this->assertTrue($v->passes());
<?php public function testBeforeAndAfterWithFormat()
{
date_default_timezone_set('UTC');
$trans = $this->getIlluminateArrayTranslator();
$v = new Validator($trans, ['x' => '31/12/2000'], ['x' => 'before:31/02/2012']);
$this->assertTrue($v->fails());
<?php public function testWeakBeforeAndAfter()
{
date_default_timezone_set('UTC');
$trans = $this->getIlluminateArrayTranslator();
$v = new Validator($trans, ['x' => '2012-01-15'], ['x' => 'before_or_equal:2012-01-15']);
$this->assertTrue($v->passes());