Skip to content

Commit b1f8faf

Browse files
authored
Merge pull request #67 from iftar/fix-timezone-issues
Fix timezone issues
2 parents f481cea + d3d24cf commit b1f8faf

11 files changed

Lines changed: 14 additions & 14 deletions

File tree

app/Http/Controllers/API/User/OrderController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function index(AuthenticatedRequest $request, OrderService $orderService)
2828
public function today(AuthenticatedRequest $request, OrderService $orderService)
2929
{
3030
$filters = [
31-
'required_date' => today()
31+
'required_date' => today('Europe/London')
3232
];
3333

3434
return response()->json([

app/Models/CollectionPoint.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function batches()
7171

7272
public function getAvailableCapacityAttribute()
7373
{
74-
return $this->max_daily_capacity - $this->orders()->whereDate('created_at', Carbon::today())->sum('quantity');
74+
return $this->max_daily_capacity - $this->orders()->whereDate('created_at', today('Europe/London'))->sum('quantity');
7575
}
7676

7777
public function getAcceptingOrdersAttribute()

app/Models/CollectionPointTimeSlot.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function orders()
4949

5050
public function getAvailableCapacityAttribute()
5151
{
52-
return $this->max_capacity - $this->orders()->whereDate('created_at', Carbon::today())->sum('quantity');
52+
return $this->max_capacity - $this->orders()->whereDate('created_at', today('Europe/London'))->sum('quantity');
5353
}
5454

5555
public function getAcceptingOrdersAttribute()

app/Notifications/Charity/OrdersToday.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public function toArray($notifiable)
8686

8787
protected function getCsvFileName()
8888
{
89-
return now()->format('Y-m-d') . "_charity_" . $this->batch->charity->id . "_batch_" . $this->batch->id . ".csv";
89+
return now('Europe/London')->format('Y-m-d') . "_charity_" . $this->batch->charity->id . "_batch_" . $this->batch->id . ".csv";
9090
}
9191

9292
protected function getTotalMeals()

app/Notifications/CollectionPoint/OrdersToday.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function toArray($notifiable)
8181

8282
protected function getCsvFileName()
8383
{
84-
return now()->format('Y-m-d') . "_collection-point_" . $this->batch->collectionPoint->id . "_batch_" . $this->batch->id . ".csv";
84+
return now('Europe/London')->format('Y-m-d') . "_collection-point_" . $this->batch->collectionPoint->id . "_batch_" . $this->batch->id . ".csv";
8585
}
8686

8787
protected function getTotalMeals()

app/Services/Admin/OrderService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class OrderService
88
{
99
public function getOrdersToday()
1010
{
11-
return Order::where('required_date', today())
11+
return Order::where('required_date', today('Europe/London'))
1212
->with(['collectionPoint','collectionPointTimeSlot'])
1313
->get();
1414
}

app/Services/Charity/OrderService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public function get()
1818
$query->where('type', 'charity_pickup');
1919
},
2020
'collectionPoints.collectionPointTimeSlots.orders' => function ($query) {
21-
$query->whereDate('required_date', today()->format('Y-m-d'));
21+
$query->whereDate('required_date', today('Europe/London')->format('Y-m-d'));
2222
},
2323
])
2424
->whereIn('id', $user->charities->pluck('id'))

app/Services/CollectionPoint/OrderService.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public function get()
2020
$collectionTimeSlots = CollectionPointTimeSlot::where('collection_point_id', $userCollectionPoint->id)
2121
->with([
2222
'orders' => function ($query) {
23-
$query->whereDate('required_date', today()->format('Y-m-d'));
23+
$query->whereDate('required_date', today('Europe/London')->format('Y-m-d'));
2424
}
2525
])
2626
->orderBy('start_time')
@@ -38,7 +38,7 @@ public function getOrdersToday(CollectionPoint $collectionPoint)
3838
return CollectionPointTimeSlot::where('collection_point_id', $collectionPoint->id)
3939
->with([
4040
'orders' => function ($query) {
41-
$query->whereDate('required_date', today()->format('Y-m-d'))
41+
$query->whereDate('required_date', today('Europe/London')->format('Y-m-d'))
4242
->whereStatus('accepted');
4343
}
4444
])

app/Services/User/OrderService.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function create($data)
3232
{
3333
$user = auth()->user();
3434

35-
$data['required_date'] = now();
35+
$data['required_date'] = now('Europe/London');
3636

3737
$order = $user->orders()->create($data);
3838

@@ -91,13 +91,13 @@ public function canOrder()
9191

9292
// check if user has already ordered today
9393
$todaysOrderCount = $user->orders()
94-
->whereDate('created_at', Carbon::today())
94+
->whereDate('created_at', Carbon::today('Europe/London'))
9595
->count();
9696

9797
if ( $todaysOrderCount == 0 ) $result['user_has_ordered_today'] = false;
9898
else $result['messages'][] = "User has already ordered today.";
9999

100-
// check if between 12am and 2pm
100+
// check if between 12am and 3pm
101101
$now = Carbon::now('Europe/London');
102102
$start = Carbon::createFromTimeString('00:00', 'Europe/London');
103103
$end = Carbon::createFromTimeString('15:00', 'Europe/London');

database/factories/BatchFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77

88
$factory->define(Batch::class, function (Faker $faker) {
99
return [
10-
'created_at' => now()->startOfDay()->hour(14)
10+
'created_at' => now('Europe/London')->startOfDay()->hour(14)
1111
];
1212
});

0 commit comments

Comments
 (0)