Skip to content

Commit

Permalink
Merge a671786 into 1e3bff0
Browse files Browse the repository at this point in the history
  • Loading branch information
hughgrigg committed Nov 17, 2018
2 parents 1e3bff0 + a671786 commit bae90f3
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Expand Up @@ -3,4 +3,4 @@ reports/
build/
coverage/
.idea/

composer.lock
2 changes: 1 addition & 1 deletion composer.json
@@ -1,7 +1,7 @@
{
"name": "hughgrigg/php-business-time",
"description": "Business time / working days extension for Carbon dates",
"version": "1.1.1",
"version": "1.1.2",
"type": "library",
"require": {
"php": "^7.0",
Expand Down
29 changes: 22 additions & 7 deletions src/Interval.php
Expand Up @@ -81,21 +81,36 @@ public function forHumans($short = false): string
* Normalise instance creation to seconds.
*
* @param DateInterval $dateInterval
* @param bool $trimMicroseconds
*
* @return static
*/
public static function instance(DateInterval $dateInterval): self
{
return self::seconds(self::intervalToSeconds($dateInterval));
public static function instance(
DateInterval $dateInterval,
$trimMicroseconds = true
): self {
return self::seconds(
self::intervalToSeconds($dateInterval, $trimMicroseconds)
);
}

/**
* @param DateInterval $interval
* @param DateInterval $dateInterval
* @param bool $trimMicroseconds
*
* @return int
*/
public static function intervalToSeconds(DateInterval $interval): int
{
return (new Carbon())->add($interval)->diffInRealSeconds(new Carbon());
public static function intervalToSeconds(
DateInterval $dateInterval,
$trimMicroseconds = true
): int {
$dateInterval->f =
$trimMicroseconds ||
version_compare(PHP_VERSION, '7.1.0-dev', '<') ? 0 :
$dateInterval->f;

return (new Carbon())->add($dateInterval)->diffInRealSeconds(
new Carbon()
);
}
}

0 comments on commit bae90f3

Please sign in to comment.