Skip to content

Commit

Permalink
Fix #1173 Check microtime result (#1181)
Browse files Browse the repository at this point in the history
  • Loading branch information
kylekatarnls authored Mar 10, 2018
1 parent 14aef4c commit 0200f98
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/Carbon/Carbon.php
Original file line number Diff line number Diff line change
Expand Up @@ -396,8 +396,11 @@ public function __construct($time = null, $tz = null)
)
) {
$dateTime = new DateTime('now', $timezone);
$microTime = str_pad(strval(microtime(true) * 1000000 % 1000000), 6, '0', STR_PAD_LEFT);
$time = $dateTime->format(static::DEFAULT_TO_STRING_FORMAT).'.'.$microTime;
$microTime = microtime(true) * 1000000 % 1000000;
if ($microTime > 0) {
$microTime = str_pad(strval($microTime), 6, '0', STR_PAD_LEFT);
$time = $dateTime->format(static::DEFAULT_TO_STRING_FORMAT).'.'.$microTime;
}
}
// @codeCoverageIgnoreEnd

Expand Down

0 comments on commit 0200f98

Please sign in to comment.