Skip to content

Commit 06aca06

Browse files
authored
Handle Carbon v3 (#116)
1 parent 21f370a commit 06aca06

4 files changed

Lines changed: 24 additions & 3 deletions

File tree

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"require": {
3838
"php": "^8.2",
3939
"edalzell/forma": "^2.0 || ^3.0",
40-
"nesbot/carbon": "^2.0",
40+
"nesbot/carbon": "^2.0 || ^3.0",
4141
"rlanvin/php-rrule": "^2.3.1",
4242
"spatie/calendar-links": "^1.0",
4343
"spatie/icalendar-generator": "^2.3.3",

src/Modifiers/IsEndOfWeek.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,21 @@
22

33
namespace TransformStudios\Events\Modifiers;
44

5+
use Carbon\CarbonImmutable;
6+
use Composer\InstalledVersions;
57
use Illuminate\Support\Carbon;
68
use Statamic\Modifiers\Modifier;
79

810
class IsEndOfWeek extends Modifier
911
{
1012
public function index($value, $params, $context)
1113
{
12-
return Carbon::parse($value)->dayOfWeek == now()->endOfWeek()->dayOfWeek;
14+
$date = CarbonImmutable::parse($value);
15+
16+
if (InstalledVersions::getVersion('nesbot/carbon') >= '3') {
17+
$date->isSameDay($date->locale(Carbon::getLocale())->startOfWeek());
18+
}
19+
20+
return $date->dayOfWeek == now()->endOfWeek()->dayOfWeek;
1321
}
1422
}

src/Modifiers/IsStartOfWeek.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,21 @@
22

33
namespace TransformStudios\Events\Modifiers;
44

5+
use Carbon\CarbonImmutable;
6+
use Composer\InstalledVersions;
57
use Illuminate\Support\Carbon;
68
use Statamic\Modifiers\Modifier;
79

810
class IsStartOfWeek extends Modifier
911
{
1012
public function index($value, $params, $context)
1113
{
12-
return Carbon::parse($value)->dayOfWeek == now()->startOfWeek()->dayOfWeek;
14+
$date = CarbonImmutable::parse($value);
15+
16+
if (InstalledVersions::getVersion('nesbot/carbon') >= '3') {
17+
$date->isSameDay($date->locale(Carbon::getLocale())->startOfWeek());
18+
}
19+
20+
return $date->dayOfWeek == now()->startOfWeek()->dayOfWeek;
1321
}
1422
}

src/ServiceProvider.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace TransformStudios\Events;
44

5+
use Composer\InstalledVersions;
56
use Edalzell\Forma\Forma;
67
use Illuminate\Support\Carbon;
78
use Illuminate\Support\Facades\Artisan;
@@ -56,6 +57,10 @@ private function bootCarbon(): self
5657
{
5758
Carbon::setLocale(Site::current()->locale());
5859

60+
if (InstalledVersions::getVersion('nesbot/carbon') >= '3') {
61+
return $this;
62+
}
63+
5964
/*
6065
Using these deprecated methods because I couldn't figure out another way to
6166
have the weekstart set based on the current locale.

0 commit comments

Comments
 (0)