Skip to content

Commit

Permalink
🐛 Add timezone to trip creation (#1985)
Browse files Browse the repository at this point in the history
  • Loading branch information
HerrLevin authored Oct 15, 2023
1 parent 393a217 commit ff85ea4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
19 changes: 12 additions & 7 deletions app/Http/Controllers/Frontend/Admin/TripController.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ public function createTrip(Request $request): RedirectResponse {
'journey_number' => ['required', 'numeric'],
]);

$departure = str_contains($validated['departure'], '+') && str_contains($validated['departure'], '-')
? $validated['departure'] : $validated['departure'] . '+00:00';
$arrival = str_contains($validated['arrival'], '+') && str_contains($validated['arrival'], '-')
? $validated['arrival'] : $validated['arrival'] . '+00:00';

$originStation = TrainStation::where('ibnr', $validated['origin'])->firstOrFail();
$destinationStation = TrainStation::where('ibnr', $validated['destination'])->firstOrFail();

Expand All @@ -63,29 +68,29 @@ public function createTrip(Request $request): RedirectResponse {
'operator_id' => $validated['operator_id'],
'origin' => $validated['origin'],
'destination' => $validated['destination'],
'departure' => $validated['departure'],
'arrival' => $validated['arrival'],
'departure' => $departure,
'arrival' => $arrival,
]);
//Origin stopover
TrainStopover::create([
'trip_id' => $trip->trip_id,
'train_station_id' => $originStation->id,
'arrival_planned' => $validated['departure'],
'departure_planned' => $validated['departure'],
'arrival_planned' => $departure,
'departure_planned' => $departure,
]);
//Destination stopover
TrainStopover::create([
'trip_id' => $trip->trip_id,
'train_station_id' => $destinationStation->id,
'arrival_planned' => $validated['arrival'],
'departure_planned' => $validated['arrival'],
'arrival_planned' => $arrival,
'departure_planned' => $arrival,
]);

return redirect()->route('trains.trip', [
'tripID' => $trip->trip_id,
'lineName' => $trip->linename,
'start' => $trip->origin,
'departure' => $validated['departure'],
'departure' => $departure,
]);
}
}
4 changes: 2 additions & 2 deletions resources/views/admin/trip/create.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
</div>

<div class="form-group">
<label for="departure">Departure</label>
<label for="departure">Departure (UTC)</label>
<input type="datetime-local" class="form-control" id="departure" name="departure" placeholder="Departure"
required>
</div>
Expand All @@ -35,7 +35,7 @@
</div>

<div class="form-group">
<label for="arrival">Arrival</label>
<label for="arrival">Arrival (UTC)</label>
<input type="datetime-local" class="form-control" id="arrival" name="arrival" placeholder="Arrival"
required>
</div>
Expand Down

0 comments on commit ff85ea4

Please sign in to comment.