Skip to content

Commit 1c04fa9

Browse files
authored
Merge pull request #117 from Muetze42/development
feat(carbon): add macro of alternative diff for humans method
2 parents e1c581a + 8ae0cc8 commit 1c04fa9

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace NormanHuth\Library\Support\Macros\Carbon;
4+
5+
use Carbon\CarbonInterface;
6+
use Closure;
7+
use DateTimeInterface;
8+
use Illuminate\Support\Carbon;
9+
10+
/**
11+
* @mixin \Illuminate\Support\Carbon
12+
*/
13+
class DiffForAltHumansMacro
14+
{
15+
public function __invoke(): Closure
16+
{
17+
/**
18+
* Get the difference in a human-readable format in the current locale from a current instance to another instance given (or now if null given).
19+
*/
20+
return function (
21+
array|Carbon|DateTimeInterface|null|string $other = null,
22+
array|int $syntax = CarbonInterface::DIFF_RELATIVE_TO_NOW,
23+
bool $short = false,
24+
int $parts = 1,
25+
?int $options = null
26+
) {
27+
return $this->diffForHumans($other, $syntax, $short, $parts, $options);
28+
};
29+
}
30+
}

0 commit comments

Comments
 (0)