Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"require": {
"php": "^8.2",
"edalzell/forma": "^2.0 || ^3.0",
"nesbot/carbon": "^2.0",
"nesbot/carbon": "^2.0 || ^3.0",
"rlanvin/php-rrule": "^2.3.1",
"spatie/calendar-links": "^1.0",
"spatie/icalendar-generator": "^2.3.3",
Expand Down
10 changes: 9 additions & 1 deletion src/Modifiers/IsEndOfWeek.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,21 @@

namespace TransformStudios\Events\Modifiers;

use Carbon\CarbonImmutable;
use Composer\InstalledVersions;
use Illuminate\Support\Carbon;
use Statamic\Modifiers\Modifier;

class IsEndOfWeek extends Modifier
{
public function index($value, $params, $context)
{
return Carbon::parse($value)->dayOfWeek == now()->endOfWeek()->dayOfWeek;
$date = CarbonImmutable::parse($value);

if (InstalledVersions::getVersion('nesbot/carbon') >= '3') {
$date->isSameDay($date->locale(Carbon::getLocale())->startOfWeek());
}

return $date->dayOfWeek == now()->endOfWeek()->dayOfWeek;
}
}
10 changes: 9 additions & 1 deletion src/Modifiers/IsStartOfWeek.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,21 @@

namespace TransformStudios\Events\Modifiers;

use Carbon\CarbonImmutable;
use Composer\InstalledVersions;
use Illuminate\Support\Carbon;
use Statamic\Modifiers\Modifier;

class IsStartOfWeek extends Modifier
{
public function index($value, $params, $context)
{
return Carbon::parse($value)->dayOfWeek == now()->startOfWeek()->dayOfWeek;
$date = CarbonImmutable::parse($value);

if (InstalledVersions::getVersion('nesbot/carbon') >= '3') {
$date->isSameDay($date->locale(Carbon::getLocale())->startOfWeek());
}

return $date->dayOfWeek == now()->startOfWeek()->dayOfWeek;
}
}
5 changes: 5 additions & 0 deletions src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace TransformStudios\Events;

use Composer\InstalledVersions;
use Edalzell\Forma\Forma;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Artisan;
Expand Down Expand Up @@ -56,6 +57,10 @@ private function bootCarbon(): self
{
Carbon::setLocale(Site::current()->locale());

if (InstalledVersions::getVersion('nesbot/carbon') >= '3') {
return $this;
}

/*
Using these deprecated methods because I couldn't figure out another way to
have the weekstart set based on the current locale.
Expand Down