Skip to content
Open
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
8 changes: 4 additions & 4 deletions src/Modifiers/InMonth.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace TransformStudios\Events\Modifiers;

use Illuminate\Support\Carbon;
use Carbon\CarbonImmutable;
use Statamic\Modifiers\Modifier;
use Statamic\Support\Arr;

Expand All @@ -11,11 +11,11 @@ class InMonth extends Modifier
public function index($value, $params, $context)
{
$month = parse_date(
Arr::get($context, 'get.month', Carbon::now()->englishMonth).
Arr::get($context, 'get.month', CarbonImmutable::now()->englishMonth).
' '.
Arr::get($context, 'get.year', Carbon::now()->year)
Arr::get($context, 'get.year', CarbonImmutable::now()->year)
)->month;

return Carbon::parse($value)->month == $month;
return CarbonImmutable::parse($value)->month == $month;
}
}
3 changes: 1 addition & 2 deletions src/Modifiers/IsEndOfWeek.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

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

class IsEndOfWeek extends Modifier
Expand All @@ -14,7 +13,7 @@ public function index($value, $params, $context)
$date = CarbonImmutable::parse($value);

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

return $date->dayOfWeek == now()->endOfWeek()->dayOfWeek;
Expand Down
3 changes: 1 addition & 2 deletions src/Modifiers/IsStartOfWeek.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

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

class IsStartOfWeek extends Modifier
Expand All @@ -14,7 +13,7 @@ public function index($value, $params, $context)
$date = CarbonImmutable::parse($value);

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

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

namespace TransformStudios\Events;

use Carbon\CarbonImmutable;
use Composer\InstalledVersions;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Artisan;
use Statamic\Entries\Entry;
use Statamic\Facades\Collection;
Expand All @@ -30,7 +30,7 @@ public function bootAddon()

private function bootCarbon(): self
{
Carbon::setLocale(Site::current()->locale());
CarbonImmutable::setLocale(Site::current()->locale());

if (InstalledVersions::getVersion('nesbot/carbon') >= '3') {
return $this;
Expand All @@ -44,12 +44,12 @@ private function bootCarbon(): self

*/

if (is_string($weekStartDay = Carbon::getTranslator()->trans(id: 'first_day_of_week', locale: Site::current()->locale()))) {
if (is_string($weekStartDay = CarbonImmutable::getTranslator()->trans(id: 'first_day_of_week', locale: Site::current()->locale()))) {
$weekStartDay = 0;
}

Carbon::setWeekStartsAt(day: $weekStartDay);
Carbon::setWeekEndsAt(day: ($weekStartDay + 6) % 7);
CarbonImmutable::setWeekStartsAt(day: $weekStartDay);
CarbonImmutable::setWeekEndsAt(day: ($weekStartDay + 6) % 7);

return $this;
}
Expand Down
11 changes: 6 additions & 5 deletions src/Tags/Events.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

namespace TransformStudios\Events\Tags;

use Carbon\Carbon;
use Carbon\CarbonImmutable;
use Carbon\CarbonInterface;
use Illuminate\Pagination\Paginator;
use Illuminate\Support\Carbon;
use Illuminate\Support\Collection;
use Statamic\Contracts\Query\Builder;
use Statamic\Contracts\Taxonomies\Term;
Expand All @@ -24,8 +25,8 @@ class Events extends Tags
public function between(): EntryCollection|array
{
return $this->output($this->generator()->between(
from: Carbon::parse($this->params->get('from', now()))->startOfDay(),
to: Carbon::parse($this->params->get('to'))->endOfDay()
from: CarbonImmutable::parse($this->params->get('from', now()))->startOfDay(),
to: CarbonImmutable::parse($this->params->get('to'))->endOfDay()
));
}

Expand All @@ -52,7 +53,7 @@ public function downloadLink(): string
'statamic.events.ics.show',
Arr::removeNullValues([
'collection' => $this->params->get('collection', 'events'),
'date' => $this->params->has('date') ? Carbon::parse($this->params->get('date'))->toDateString() : null,
'date' => $this->params->has('date') ? CarbonImmutable::parse($this->params->get('date'))->toDateString() : null,
'event' => $this->params->get('event'),
])
);
Expand Down Expand Up @@ -165,7 +166,7 @@ private function makeEmptyDates(CarbonInterface $from, CarbonInterface $to): Col
$dates = collect();
$currentDay = $from->copy()->toMutable();

foreach (range(0, Carbon::parse($to)->diffInDays($from)) as $ignore) {
foreach (range(0, CarbonImmutable::parse($to)->diffInDays($from)) as $ignore) {
$date = $currentDay->toDateString();
$dates->put($date, [
'date' => $date,
Expand Down
5 changes: 2 additions & 3 deletions src/Types/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace TransformStudios\Events\Types;

use Carbon\Carbon;
use Carbon\CarbonImmutable;
use Carbon\CarbonInterface;
use DateTimeInterface;
Expand Down Expand Up @@ -167,9 +166,9 @@ protected function supplement(CarbonInterface $date): ?Entry

protected function toCarbonImmutable(string|CarbonInterface $date): CarbonImmutable
{
$carbon = is_string($date) ? Carbon::parse($date) : $date;
$carbon = is_string($date) ? CarbonImmutable::parse($date) : $date;

return $carbon->shiftTimezone($this->timezone['name'])->toImmutable();
return $carbon->shiftTimezone($this->timezone['name']);
}

private function collect(array $dates): Collection
Expand Down
6 changes: 3 additions & 3 deletions src/Types/RecurringEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace TransformStudios\Events\Types;

use Carbon\CarbonImmutable;
use Illuminate\Support\Arr;
use Illuminate\Support\Carbon;
use RRule\RRule;
use RRule\RRuleInterface;
use Spatie\IcalendarGenerator\Components\Event as ICalendarEvent;
Expand Down Expand Up @@ -57,7 +57,7 @@ protected function rule(): RRuleInterface
];

if ($end = $this->end_date) {
$rule['until'] = Carbon::parse($end)->shiftTimezone($this->timezone['name'])->endOfDay();
$rule['until'] = CarbonImmutable::parse($end)->shiftTimezone($this->timezone['name'])->endOfDay();
}

if (! empty($days = $this->onSpecificDays())) {
Expand Down Expand Up @@ -107,7 +107,7 @@ private function spatieRule(): ICalendarRule
->interval($this->interval());

if ($end = $this->end_date) {
$rule->until(Carbon::parse($end)->endOfDay());
$rule->until(CarbonImmutable::parse($end)->endOfDay());
}

return $rule;
Expand Down
4 changes: 2 additions & 2 deletions src/helpers.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

use Carbon\CarbonImmutable;
use Carbon\CarbonInterface;
use Carbon\Exceptions\InvalidFormatException;
use Illuminate\Support\Carbon;

if (! function_exists('parse_date')) {
/**
Expand All @@ -11,7 +11,7 @@
function parse_date(string $date): CarbonInterface
{
try {
$date = Carbon::parse($date);
$date = CarbonImmutable::parse($date);
} catch (InvalidFormatException $e) {
$date = now();
}
Expand Down