diff --git a/composer.json b/composer.json index bdd1d70..bd906a7 100644 --- a/composer.json +++ b/composer.json @@ -33,6 +33,7 @@ "drupal/xmlsitemap": "^1.0", "drush/drush": "^9", "illuminate/support": "^7.10", + "nesbot/carbon": "^2.33", "tightenco/collect": "^6.15" }, "require-dev": { diff --git a/composer.lock b/composer.lock index 6c458eb..cdfc035 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "89691b515b3a79b86272092c47301edd", + "content-hash": "9bfa466922e45768b4123877e46728c6", "packages": [ { "name": "asm89/stack-cors", diff --git a/web/modules/custom/custom/src/EventSubscriber/UpdateTalkCreatedDateOnSave.php b/web/modules/custom/custom/src/EventSubscriber/UpdateTalkCreatedDateOnSave.php index 3dc01e9..fa8e0cf 100644 --- a/web/modules/custom/custom/src/EventSubscriber/UpdateTalkCreatedDateOnSave.php +++ b/web/modules/custom/custom/src/EventSubscriber/UpdateTalkCreatedDateOnSave.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace Drupal\custom\EventSubscriber; +use Carbon\Carbon; use Drupal\Core\Entity\EntityInterface; use Drupal\hook_event_dispatcher\Event\Entity\BaseEntityEvent; use Drupal\hook_event_dispatcher\HookEventDispatcherInterface; @@ -40,7 +41,7 @@ final class UpdateTalkCreatedDateOnSave implements EventSubscriberInterface { return; } - $talkDate = (new \DateTime($eventDate))->getTimestamp(); + $talkDate = Carbon::parse($eventDate)->getTimestamp(); if ($talkDate == $talk->get('created')->getString()) { return; diff --git a/web/modules/custom/custom/tests/src/Kernel/UpdatesTalkCreatedDateTest.php b/web/modules/custom/custom/tests/src/Kernel/UpdatesTalkCreatedDateTest.php index 5ceee42..9f4e42d 100644 --- a/web/modules/custom/custom/tests/src/Kernel/UpdatesTalkCreatedDateTest.php +++ b/web/modules/custom/custom/tests/src/Kernel/UpdatesTalkCreatedDateTest.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace Drupal\Tests\custom\Kernel; +use Carbon\Carbon; use Drupal\Core\Entity\EntityInterface; use Drupal\datetime\Plugin\Field\FieldType\DateTimeItemInterface; use Drupal\KernelTests\Core\Entity\EntityKernelTestBase; @@ -33,7 +34,7 @@ final class UpdatesTalkCreatedDateTest extends EntityKernelTestBase { ]; public function testCreatingNode() { - $eventDate = (new \DateTime('today'))->modify('+1 week'); + $eventDate = Carbon::today()->addWeek(); $eventDateToFormat = $eventDate->format(DateTimeItemInterface::DATE_STORAGE_FORMAT); $eventDateToTimestamp = $eventDate->getTimestamp(); @@ -46,7 +47,7 @@ final class UpdatesTalkCreatedDateTest extends EntityKernelTestBase { public function testUpdatingNode() { $talk = $this->createTalk(); - $eventDate = (new \DateTime('today'))->modify('+1 week'); + $eventDate = Carbon::today()->addWeek(); $eventDateToFormat = $eventDate->format(DateTimeItemInterface::DATE_STORAGE_FORMAT); $eventDateToTimestamp = $eventDate->getTimestamp();