fixed time ago优化
This commit is contained in:
parent
e5989b219f
commit
12cc870dc7
|
@ -95,21 +95,31 @@ module ApplicationHelper
|
||||||
timePassed = currentTime - lastUpdateTime
|
timePassed = currentTime - lastUpdateTime
|
||||||
timeIntoFormat = 0
|
timeIntoFormat = 0
|
||||||
updateAtValue = ""
|
updateAtValue = ""
|
||||||
if timePassed < 0
|
|
||||||
|
if timePassed <= 0
|
||||||
updateAtValue = "刚刚"
|
updateAtValue = "刚刚"
|
||||||
|
elsif timePassed < 2 * 1000
|
||||||
|
updateAtValue = "1秒前"
|
||||||
elsif timePassed < ONE_MINUTE
|
elsif timePassed < ONE_MINUTE
|
||||||
updateAtValue = "1分钟前"
|
updateAtValue = "1分钟前"
|
||||||
elsif timePassed < ONE_HOUR
|
elsif timePassed < ONE_HOUR
|
||||||
timeIntoFormat = timePassed / ONE_MINUTE
|
timeIntoFormat = timePassed / ONE_MINUTE
|
||||||
updateAtValue = timeIntoFormat.to_s + "分钟前"
|
updateAtValue = timeIntoFormat.to_s + "分钟前"
|
||||||
elsif (timePassed < ONE_DAY)
|
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 + "小时前"
|
updateAtValue = timeIntoFormat.to_s + "小时前"
|
||||||
elsif (timePassed < ONE_MONTH)
|
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 + "天前"
|
updateAtValue = timeIntoFormat.to_s + "天前"
|
||||||
elsif (timePassed < ONE_YEAR)
|
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 + "个月前"
|
updateAtValue = timeIntoFormat.to_s + "个月前"
|
||||||
else
|
else
|
||||||
timeIntoFormat = timePassed / ONE_YEAR
|
timeIntoFormat = timePassed / ONE_YEAR
|
||||||
|
|
Loading…
Reference in New Issue