Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions libraries/joomla/date/date.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,6 @@ 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.
// See http://php.net/manual/en/migration71.incompatible.php#migration71.incompatible.datetime-microseconds
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');
}

// Call the DateTime constructor.
parent::__construct($date, $tz);

Expand Down
38 changes: 38 additions & 0 deletions tests/unit/suites/libraries/joomla/date/JDateTest.php
Original file line number Diff line number Diff line change
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