Fix time difference summaries
This commit is contained in:
parent
ee75bc6976
commit
064cf0642c
1 changed files with 21 additions and 21 deletions
|
@ -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 = '<span title="' . date('j M Y (G:H)', strtotime($start_time)) . '">';
|
||||
$end_tag = "ago</span>";
|
||||
$start_tag = '<span title="' . date('G:H, j M Y', strtotime($start_time)) . '">';
|
||||
$end_tag = '</span>';
|
||||
$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
|
||||
|
|
Loading…
Reference in a new issue