Skip to content

Commit

Permalink
Houston, bug fixed!
Browse files Browse the repository at this point in the history
  • Loading branch information
osbre committed Sep 16, 2018
1 parent 294cdda commit 5927df3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
8 changes: 6 additions & 2 deletions app/Http/Controllers/TrackController.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,12 @@ public function show(Request $request)
$duration['value'] = $api->routes[0]->legs[0]->duration->value;

$minutes = $distance['text'] / 45 * 60;
$time_to_arrival = Track::convertToHoursMins($minutes, '%02d days %02d hours %02d minutes');
$estimated_time_to_delivery = Carbon::now()->addMinutes($minutes)->format('m-d-Y H:i');
$time_to_arrival = Track::convertToHoursMins($minutes);
$estimated_time_to_delivery = Carbon::now()
->addDay($time_to_arrival['days'])
->addHour($time_to_arrival['hours'])
->addMinute($time_to_arrival['minutes'])
->format('m-d-Y H:i');

return view('show', ['track' => $track, 'start' => $start, 'end' => $end, 'time_to_arrival' => $time_to_arrival, 'estimated_time_to_delivery' => $estimated_time_to_delivery, 'distance' => $distance, 'duration' => $duration]);
}
Expand Down
15 changes: 7 additions & 8 deletions app/Track.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,19 +95,18 @@ public function insertPhotos($request)

/**
* Convert minutes to time
* @param $time
* @param string $format
* @return string|void
* @param integer $time
* @return array $value
*/
static function convertToHoursMins($time, $format = '%02d:%02d')
static function convertToHoursMins($time)
{
if ($time < 1) {
return;
}
$hours = floor($time / 60);
$days = floor($hours / 24);
$minutes = ($time % 60);
return sprintf($format, $days, $hours, $minutes);
$value['hours'] = floor($time / 60);
$value['days'] = floor($value['hours'] / 24);
$value['minutes'] = ($time % 60);
return $value;
}

static function calcDirections($from, $to)
Expand Down
4 changes: 2 additions & 2 deletions resources/views/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@
Current location:
<br><b>{{ $track->current_location }}</b>
<br><b>{{ $track->current_location_date ? $track->current_location_date->format('m-d-Y H:i') : '' }}</b>

</li>
@endif
@if($track->locations->where('type', 'destination')->isNotEmpty())
Expand All @@ -98,7 +97,8 @@
@endif

<li class="list-group-item">
Time to arrival:<br> <b>{{ $time_to_arrival }}</b>
Time to arrival:<br>
<b>{{ $time_to_arrival['days'].' days '.$time_to_arrival['hours'].' hours '.$time_to_arrival['minutes'].' minutes' }}</b>
</li>
<li class="list-group-item">
Estimated time to delivery:<br> <b>{{ $estimated_time_to_delivery }}</b>
Expand Down

0 comments on commit 5927df3

Please sign in to comment.