Browse Source

英文显示时间单位加空格

master
wanghongjun 2 days ago
parent
commit
501c88d3c9
  1. 26
      app/common.php

26
app/common.php

@ -1,5 +1,6 @@
<?php
use Carbon\Carbon;
use Illuminate\Support\Facades\App;
if (!function_exists('generate_tree')) {
function generate_tree(
@ -155,20 +156,30 @@ if (!function_exists('get_time_difference')) {
if (!function_exists('get_time_difference_str')) {
function get_time_difference_str($date, $now_date = ''): string
{
$locale = App::getLocale();
$str = $locale == 'en' ? ' ' : '';
$value = '';
$difference = get_time_difference($date, $now_date);
if (!isset($difference['error'])) {
if (!empty($difference['days'])) {
$value .= $difference['days'] . __('controller.parking_space.days');
$value .= $difference['days'] . $str . __(
'controller.parking_space.days'
);
}
if (!empty($difference['hours']) || !empty($value)) {
$value .= $difference['hours'] . __('controller.parking_space.hours');
$value .= $difference['hours'] . $str . __(
'controller.parking_space.hours'
);
}
if (!empty($difference['minutes']) || !empty($value)) {
$value .= $difference['minutes'] . __('controller.parking_space.minutes');
$value .= $difference['minutes'] . $str . __(
'controller.parking_space.minutes'
);
}
if (!empty($difference['seconds']) || !empty($value)) {
$value .= $difference['seconds'] . __('controller.parking_space.seconds');
$value .= $difference['seconds'] . $str . __(
'controller.parking_space.seconds'
);
}
}
return $value;
@ -190,6 +201,9 @@ if (!function_exists('get_diff_in_minutes')) {
if (!function_exists('get_minutes')) {
function get_minutes($totalSeconds): string
{
$locale = App::getLocale();
$str = $locale == 'en' ? ' ' : '';
// 2. 根据规则计算分钟数:超过1秒按1分钟算,即向上取整
$minutes = (int)ceil($totalSeconds / 60);
@ -204,10 +218,10 @@ if (!function_exists('get_minutes')) {
// 超过一小时,显示X小时X分钟
$hours = intdiv($minutes, 60);
$remainingMinutes = $minutes % 60;
$minutesStr = $remainingMinutes . __(
$minutesStr = $remainingMinutes . $str . __(
'controller.parking_space.minutes'
);
$hoursStr = $hours . __('controller.parking_space.hours');
$hoursStr = $hours . $str . __('controller.parking_space.hours');
return $hoursStr . $minutesStr;
}
}

Loading…
Cancel
Save