Skip to content

Commit

Permalink
Address changes to Carbon::diffIn* methods
Browse files Browse the repository at this point in the history
Signed-off-by: Sam Poyigi <[email protected]>
  • Loading branch information
sampoyigi committed Jun 8, 2024
1 parent 4cf7d49 commit 85a2d7b
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 13 deletions.
5 changes: 5 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
parameters:
ignoreErrors:
-
message: "#^Call to an undefined method Illuminate\\\\Support\\\\Carbon\\:\\:diffInUTCHour\\(\\)\\.$#"
count: 1
path: src/AutomationRules/Conditions/OrderAttribute.php

-
message: "#^Call to an undefined method Illuminate\\\\Contracts\\\\Events\\\\Dispatcher\\:\\:fire\\(\\)\\.$#"
count: 2
Expand Down
8 changes: 4 additions & 4 deletions src/AutomationRules/Conditions/OrderAttribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function getHoursSinceAttribute($value, $order)
$currentDateTime = now();

return $currentDateTime->isAfter($order->order_datetime)
? $order->order_datetime->diffInRealHours($currentDateTime)
? floor($order->order_datetime->diffInUTCHour($currentDateTime))
: 0;
}

Expand All @@ -78,7 +78,7 @@ public function getHoursUntilAttribute($value, $order)
$currentDateTime = now();

return $currentDateTime->isBefore($order->order_datetime)
? $currentDateTime->diffInRealHours($order->order_datetime)
? floor($currentDateTime->diffInUTCHour($order->order_datetime))
: 0;
}

Expand All @@ -87,7 +87,7 @@ public function getDaysSinceAttribute($value, $order)
$currentDateTime = now();

return $currentDateTime->isAfter($order->order_datetime)
? $order->order_datetime->diffInDays($currentDateTime)
? floor($order->order_datetime->diffInDays($currentDateTime))
: 0;
}

Expand All @@ -96,7 +96,7 @@ public function getDaysUntilAttribute($value, $order)
$currentDateTime = now();

return $currentDateTime->isBefore($order->order_datetime)
? $currentDateTime->diffInDays($order->order_datetime)
? floor($currentDateTime->diffInDays($order->order_datetime))
: 0;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Models/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public function isCancelable()
return false;
}

return $this->order_datetime->diffInRealMinutes() > $timeout;
return floor($this->order_datetime->diffInRealMinutes()) > $timeout;
}

/**
Expand Down
16 changes: 8 additions & 8 deletions tests/AutomationRules/Conditions/OrderAttributeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,46 +19,46 @@

it('calculates hours since correctly', function() {
$order = Order::factory()->create([
'order_date' => Carbon::now()->subHours(5)->toDateString(),
'order_date' => Carbon::now()->toDateString(),
'order_time' => Carbon::now()->subHours(5)->toTimeString(),
]);

$orderAttribute = new OrderAttribute();

expect($orderAttribute->getHoursSinceAttribute(null, $order))->toBe(5);
expect($orderAttribute->getHoursSinceAttribute(null, $order))->toBe(5.0);
});

it('calculates hours until correctly', function() {
$order = Order::factory()->create([
'order_date' => Carbon::now()->addHours(5)->toDateString(),
'order_date' => Carbon::now()->toDateString(),
'order_time' => Carbon::now()->addHours(5)->toTimeString(),
]);

$orderAttribute = new OrderAttribute();

expect($orderAttribute->getHoursUntilAttribute(null, $order))->toBe(5);
expect($orderAttribute->getHoursUntilAttribute(null, $order))->toBe(4.0);
});

it('calculates days since correctly', function() {
$order = Order::factory()->create([
'order_date' => Carbon::now()->subDays(3)->toDateString(),
'order_time' => Carbon::now()->subDays(3)->toTimeString(),
'order_time' => Carbon::now()->toTimeString(),
]);

$orderAttribute = new OrderAttribute();

expect($orderAttribute->getDaysSinceAttribute(null, $order))->toBe(3);
expect($orderAttribute->getDaysSinceAttribute(null, $order))->toBe(4.0);
});

it('calculates days until correctly', function() {
$order = Order::factory()->create([
'order_date' => Carbon::now()->addDays(4)->toDateString(),
'order_time' => Carbon::now()->addDays(4)->toTimeString(),
'order_time' => Carbon::now()->toTimeString(),
]);

$orderAttribute = new OrderAttribute();

expect($orderAttribute->getDaysUntilAttribute(null, $order))->toBe(3);
expect($orderAttribute->getDaysUntilAttribute(null, $order))->toBe(3.0);
});

it('gets history status id correctly', function() {
Expand Down

0 comments on commit 85a2d7b

Please sign in to comment.