From 12cc870dc78660dca3ee5eb3fe0ffc25435378fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cxxq250=E2=80=9D?= <“xxq250@qq.com”> Date: Mon, 15 Aug 2022 15:47:30 +0800 Subject: [PATCH] =?UTF-8?q?fixed=20time=20ago=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/application_helper.rb | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 25b642d73..936452470 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -95,21 +95,31 @@ module ApplicationHelper timePassed = currentTime - lastUpdateTime timeIntoFormat = 0 updateAtValue = "" - if timePassed < 0 + + if timePassed <= 0 updateAtValue = "刚刚" + elsif timePassed < 2 * 1000 + updateAtValue = "1秒前" elsif timePassed < ONE_MINUTE updateAtValue = "1分钟前" elsif timePassed < ONE_HOUR timeIntoFormat = timePassed / ONE_MINUTE updateAtValue = timeIntoFormat.to_s + "分钟前" elsif (timePassed < ONE_DAY) - timeIntoFormat = (timePassed.to_f / ONE_HOUR).ceil + timeIntoFormat = (timePassed.to_f / ONE_HOUR).round + timeIntoFormat == 1 if timeIntoFormat.to_i == 0 updateAtValue = timeIntoFormat.to_s + "小时前" elsif (timePassed < ONE_MONTH) - timeIntoFormat = (timePassed.to_f / ONE_DAY).ceil + timeIntoFormat = (timePassed.to_f / ONE_DAY).round + timeIntoFormat == 1 if timeIntoFormat.to_i == 0 + updateAtValue = timeIntoFormat.to_s + "天前" + elsif (timePassed < ONE_MONTH) + timeIntoFormat = (timePassed.to_f / ONE_DAY).round + timeIntoFormat == 1 if timeIntoFormat.to_i == 0 updateAtValue = timeIntoFormat.to_s + "天前" elsif (timePassed < ONE_YEAR) - timeIntoFormat = (timePassed.to_f / ONE_MONTH).ceil + timeIntoFormat = (timePassed.to_f / ONE_MONTH).round + timeIntoFormat == 1 if timeIntoFormat.to_i == 0 updateAtValue = timeIntoFormat.to_s + "个月前" else timeIntoFormat = timePassed / ONE_YEAR