Skip to content

Commit

Permalink
Add Microseconds to JDate('now') (#11890)
Browse files Browse the repository at this point in the history
* Update date.php

* Update date.php

* cleaner code

* simplify

* Update date.php
  • Loading branch information
andrepereiradasilva authored and wilsonge committed Sep 6, 2016
1 parent d41e779 commit 417a6a6
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions libraries/joomla/date/date.php
Expand Up @@ -24,6 +24,7 @@
* @property-read string $hour H - 24-hour format of an hour with leading zeros.
* @property-read string $minute i - Minutes with leading zeros.
* @property-read string $second s - Seconds with leading zeros.
* @property-read string $microsecond u - Microseconds with leading zeros.
* @property-read string $month m - Numeric representation of a month, with leading zeros.
* @property-read string $ordinal S - English ordinal suffix for the day of the month, 2 characters.
* @property-read string $week W - Numeric representation of the day of the week.
Expand Down Expand Up @@ -105,6 +106,9 @@ public function __construct($date = 'now', $tz = null)
date_default_timezone_set('UTC');
$date = is_numeric($date) ? date('c', $date) : $date;

// If now, add the microseconds to date.
$date = $date === 'now' ? parent::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''), $tz)->format('Y-m-d H:i:s.u') : $date;

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

Expand Down

0 comments on commit 417a6a6

Please sign in to comment.