Skip to content

Commit

Permalink
add nesbot/carbon to composer, adapt to new version (#555)
Browse files Browse the repository at this point in the history
* add nesbot/carbon to composer, adapt to new version

* revert now() adaption

* fix carbon

* fix php version
  • Loading branch information
alexz707 authored Feb 13, 2025
1 parent 71bc8f3 commit 5367c74
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 13 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@
"prefer-stable": true,
"minimum-stability": "dev",
"require": {
"php": "~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0",
"php": "~8.3.0 || ~8.4.0",
"doctrine/dbal": "^3.4.2",
"doctrine/migrations": "^3.0.2",
"dragonmantank/cron-expression": "^3.0.2",
"drewm/mailchimp-api": "^2.2",
"guzzlehttp/guzzle": "^7.2",
"knplabs/knp-components": "^5.0",
"knplabs/knp-paginator-bundle": "^6.0.0",
"nesbot/carbon": "^3.8.4",
"openspout/openspout": "^4.0",
"pear/archive_tar": "^1.4.14",
"pimcore/newsletter-bundle": "^1.0",
Expand Down
2 changes: 1 addition & 1 deletion src/CustomerView/Customer/Maintenance.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function cleanUpTemporaryCustomers()
// check each customer if it should be deleted
foreach ($tempCustomers as $customer) {
// fetch modification date
$date = Carbon::createFromTimestamp($customer->getModificationDate());
$date = Carbon::createFromTimestamp($customer->getModificationDate(), date_default_timezone_get());
// if contact is unpublished and last modification was more then 1 day ago
if (!$customer->isPublished() && $date->diffInDays(Carbon::now()) > 1) {
// delete the customer
Expand Down
2 changes: 1 addition & 1 deletion src/DataTransformer/Date/TimestampToAge.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class TimestampToAge implements DataTransformerInterface
{
public function transform($data, $options = [])
{
$date = Carbon::createFromTimestamp(strtotime(date('Y-m-d', $data)));
$date = Carbon::createFromTimestamp(strtotime(date('Y-m-d', $data)), date_default_timezone_get());
$today = new Carbon();

return $today->diffInYears($date);
Expand Down
2 changes: 1 addition & 1 deletion src/Model/AbstractObjectActivity.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function cmfIsActive()

public function cmfGetActivityDate()
{
return Carbon::createFromTimestamp($this->getCreationDate());
return Carbon::createFromTimestamp($this->getCreationDate(), date_default_timezone_get());
}

public function cmfUpdateOnSave()
Expand Down
2 changes: 1 addition & 1 deletion src/Model/Activity/GenericActivity.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function cmfGetActivityDate()
}

if (is_int($this->data['activityDate'])) {
return Carbon::createFromTimestamp($this->data['activityDate']);
return Carbon::createFromTimestamp($this->data['activityDate'], date_default_timezone_get());
}

return new Carbon();
Expand Down
2 changes: 1 addition & 1 deletion src/Model/ActivityStoreEntry/DefaultActivityStoreEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public function getActivityDate()
*/
public function setActivityDate($activityDate)
{
$this->activityDate = Carbon::createFromTimestamp($activityDate);
$this->activityDate = Carbon::createFromTimestamp($activityDate, date_default_timezone_get());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function syncStatusChanges()
$client = $exportService->getApiClient();

// get updates from the last 30 days
$date = Carbon::createFromTimestamp(time() - (60 * 60 * 24 * 30));
$date = Carbon::createFromTimestamp(time() - (60 * 60 * 24 * 30), date_default_timezone_get());
$date = $date->toAtomString();

$count = 20;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,6 @@ public function getMd5($data)
*/
protected function getNoteDateTime(Note $note)
{
return Carbon::createFromTimestamp($note->getDate());
return Carbon::createFromTimestamp($note->getDate(), date_default_timezone_get());
}
}
28 changes: 23 additions & 5 deletions tests/Model/Customer/CustomerListTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,9 @@ protected function createCustomers()
$customer->setLastname($customerData['lastname']);
$customer->setEmail($customerData['email']);
$customer->setZip($customerData['zip']);
$customer->setBirthdate(Carbon::createFromFormat('Y-m-d', $customerData['date']));
$customer->setBirthdate(
Carbon::createFromFormat('Y-m-d', $customerData['date'])
);

$segments = [];
foreach ($customerData['segments']['manual'] as $segmentReference) {
Expand Down Expand Up @@ -321,7 +323,11 @@ public function testDateBetweenFilter()
$listing = new Customer\Listing();
$handler = new FilterHandler($listing);

$dateFilter = new DateBetween('birthdate', Carbon::createFromFormat('Y-m-d', '1970-01-01'), Carbon::now());
$dateFilter = new DateBetween(
'birthdate',
Carbon::createFromFormat('Y-m-d', '1970-01-01'),
Carbon::now()
);
$handler->addFilter($dateFilter);

$modifiedListing = $handler->getListing();
Expand All @@ -330,7 +336,11 @@ public function testDateBetweenFilter()
$listing = new Customer\Listing();
$handler = new FilterHandler($listing);

$dateFilter = new DateBetween('birthdate', Carbon::createFromFormat('Y-m-d', '1980-05-01'), Carbon::createFromFormat('Y-m-d', '1980-05-31'));
$dateFilter = new DateBetween(
'birthdate',
Carbon::createFromFormat('Y-m-d', '1980-05-01'),
Carbon::createFromFormat('Y-m-d', '1980-05-31')
);
$handler->addFilter($dateFilter);

$modifiedListing = $handler->getListing();
Expand All @@ -340,10 +350,18 @@ public function testDateBetweenFilter()
$listing = new Customer\Listing();
$handler = new FilterHandler($listing);

$dateFilter = new DateBetween('birthdate', Carbon::createFromFormat('Y-m-d', '1980-05-01'), Carbon::createFromFormat('Y-m-d', '1980-05-31'));
$dateFilter = new DateBetween(
'birthdate',
Carbon::createFromFormat('Y-m-d', '1980-05-01'),
Carbon::createFromFormat('Y-m-d', '1980-05-31')
);
$handler->addFilter($dateFilter);

$dateFilter = new DateBetween('birthdate', Carbon::createFromFormat('Y-m-d', '1980-01-01'), Carbon::createFromFormat('Y-m-d', '1980-08-31'));
$dateFilter = new DateBetween(
'birthdate',
Carbon::createFromFormat('Y-m-d', '1980-01-01'),
Carbon::createFromFormat('Y-m-d', '1980-08-31')
);
$handler->addFilter($dateFilter);

$modifiedListing = $handler->getListing();
Expand Down

0 comments on commit 5367c74

Please sign in to comment.