diff --git a/resources/views/tracker.blade.php b/resources/views/tracker.blade.php
index ee0767c..b27577e 100644
--- a/resources/views/tracker.blade.php
+++ b/resources/views/tracker.blade.php
@@ -168,43 +168,43 @@
@php
function render_date_difference ($start_time) {
$minute = 60;
- $hour = 60 * 60;
- $day = 3600 * 24;
- $week = 86400 * 7;
- $month = 604800 * 4;
- $year = 2629800 * 12;
+ $hour = $minute * 60;
+ $day = $hour * 24;
+ $week = $day * 7;
+ $month = $week * 4;
+ $year = $month * 12;
$start_time_dt = new DateTime($start_time);
$now = new DateTime();
$trip_start_difference = intval(($now->getTimestamp() - $start_time_dt->getTimestamp()));
- $start_tag = '';
- $end_tag = "ago";
+ $start_tag = '';
+ $end_tag = '';
$unit = null;
$div = 1;
if ($trip_start_difference < $minute) {
- $unit = ' seconds ';
+ $unit = 'second';
} else if ($trip_start_difference < $hour) {
- $div = 60;
- $unit = ' minutes ';
+ $div = $minute;
+ $unit = 'minute';
} else if ($trip_start_difference < $day) {
- $div = 3600;
- $unit = ' hours ';
+ $div = $hour;
+ $unit = 'hour';
} else if ($trip_start_difference < $week) {
- $div = 86400;
- $unit = ' days ';
+ $div = $day;
+ $unit = 'day';
} else if ($trip_start_difference < $month) {
- $div = 604800;
- $unit = ' weeks ';
+ $div = $week;
+ $unit = 'week';
} else if ($trip_start_difference < $year) {
- $div = 2629800;
- $unit = ' months ';
+ $div = $month;
+ $unit = 'month';
} else {
- $div = 31557600;
- $unit = ' years ';
+ $div = $year;
+ $unit = 'year';
}
- return $start_tag . (floor( $trip_start_difference / $div )) . $unit . $end_tag;
+ return "{$start_tag}" . ( floor ( $trip_start_difference / $div ) ) . " {$unit}" . ( ( floor ( $trip_start_difference / $div ) > 1 ) ? 's' : '' ) . " ago{$end_tag}";
}
@endphp