diff --git a/libraries/joomla/date/date.php b/libraries/joomla/date/date.php index 924eb12bbf63c..4a415a932024b 100644 --- a/libraries/joomla/date/date.php +++ b/libraries/joomla/date/date.php @@ -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); diff --git a/tests/unit/suites/libraries/joomla/date/JDateTest.php b/tests/unit/suites/libraries/joomla/date/JDateTest.php index 57de18d5fb9f7..58426f1068e6e 100644 --- a/tests/unit/suites/libraries/joomla/date/JDateTest.php +++ b/tests/unit/suites/libraries/joomla/date/JDateTest.php @@ -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 *