Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test and fix for date_constructor for PHP Versions lower 7.1.0 #15853

Merged
merged 2 commits into from May 10, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions libraries/joomla/date/date.php
Expand Up @@ -107,11 +107,11 @@ public function __construct($date = 'now', $tz = null)
date_default_timezone_set('UTC');
$date = is_numeric($date) ? date('c', $date) : $date;

// If php version below 7.1 and current time, add the microseconds to date.
// From php version 7.1 use an integer to initialise the datatime object.
// See http://php.net/manual/en/migration71.incompatible.php#migration71.incompatible.datetime-microseconds
if ($date === 'now' && version_compare(PHP_VERSION, '7.1.0', '<'))
if ($date === 'now' && version_compare(PHP_VERSION, '7.1.0', '>='))
{
$date = parent::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''), $tz)->format('Y-m-d H:i:s.u');
$data = time();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$data or $date ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shit

}

// Call the DateTime constructor.
Expand Down
38 changes: 38 additions & 0 deletions tests/unit/suites/libraries/joomla/date/JDateTest.php
Expand Up @@ -541,6 +541,44 @@ public function test__construct($date, $tz, $expectedTime)
);
}

/**
* Testing the Constructor for now when not using UTC
*
* @return void
*
* @since __DEPLOY_VERSION__
* @covers JDate::__construct
*/
public function test__constructForNowWhenNotUsingUTC()
{
$jdate = new JDate('now', new DateTimeZone('US/Central'));
$phpdate = new DateTime('now', new DateTimeZone('US/Central'));

$this->assertSame(
$jdate->format('D m/d/Y H:i', true),
$phpdate->format('D m/d/Y H:i')
);
}

/**
* Testing the Constructor for now when using UTC
*
* @return void
*
* @since __DEPLOY_VERSION__
* @covers JDate::__construct
*/
public function test__constructForNowWhenUsingUTC()
{
$jdate = new JDate('now', new DateTimeZone('UTC'));
$phpdate = new DateTime('now', new DateTimeZone('UTC'));

$this->assertSame(
$jdate->format('D m/d/Y H:i'),
$phpdate->format('D m/d/Y H:i')
);
}

/**
* Testing the Constructor
*
Expand Down