From 45ad1a524ac53144036cbc3b30909d060da64e51 Mon Sep 17 00:00:00 2001 From: Henry Date: Tue, 3 Aug 2021 09:29:53 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3huamn=E5=87=BD=E6=95=B0?= =?UTF-8?q?=E6=97=A0=E6=B3=95=E6=A0=BC=E5=BC=8F=E6=9C=AA=E6=9D=A5=E6=97=B6?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/admin/lang/zh-cn.php | 7 +++++++ extend/fast/Date.php | 29 ++++++++++++++++------------- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/application/admin/lang/zh-cn.php b/application/admin/lang/zh-cn.php index 2d537adb1..337a38a5d 100755 --- a/application/admin/lang/zh-cn.php +++ b/application/admin/lang/zh-cn.php @@ -114,6 +114,13 @@ return [ '%d week%s ago' => '%d周前', '%d month%s ago' => '%d月前', '%d year%s ago' => '%d年前', + '%d second%s after' => '%d秒后', + '%d minute%s after' => '%d分钟后', + '%d hour%s after' => '%d小时后', + '%d day%s after' => '%d天后', + '%d week%s after' => '%d周后', + '%d month%s after' => '%d月后', + '%d year%s after' => '%d年后', 'Set to normal' => '设为正常', 'Set to hidden' => '设为隐藏', 'Recycle bin' => '回收站', diff --git a/extend/fast/Date.php b/extend/fast/Date.php index c4e4c3126..91d3fc382 100644 --- a/extend/fast/Date.php +++ b/extend/fast/Date.php @@ -124,25 +124,28 @@ class Date */ public static function human($remote, $local = null) { - $timediff = (is_null($local) || $local ? time() : $local) - $remote; - $chunks = array( - array(60 * 60 * 24 * 365, 'year'), - array(60 * 60 * 24 * 30, 'month'), - array(60 * 60 * 24 * 7, 'week'), - array(60 * 60 * 24, 'day'), - array(60 * 60, 'hour'), - array(60, 'minute'), - array(1, 'second') - ); - + $time_diff = (is_null($local) || $local ? time() : $local) - $remote; + $tense = $time_diff < 0 ? 'after' : 'ago'; + $time_diff = abs($time_diff); + $chunks = [ + [60 * 60 * 24 * 365, 'year'], + [60 * 60 * 24 * 30, 'month'], + [60 * 60 * 24 * 7, 'week'], + [60 * 60 * 24, 'day'], + [60 * 60, 'hour'], + [60, 'minute'], + [1, 'second'] + ]; + $name = 'second'; + $count = 0; for ($i = 0, $j = count($chunks); $i < $j; $i++) { $seconds = $chunks[$i][0]; $name = $chunks[$i][1]; - if (($count = floor($timediff / $seconds)) != 0) { + if (($count = floor($time_diff / $seconds)) != 0) { break; } } - return __("%d {$name}%s ago", $count, ($count > 1 ? 's' : '')); + return __("%d $name%s $tense", $count, ($count > 1 ? 's' : '')); } /** -- Gitee