Browse Source

fixed time ago优化

pull/313/head
“xxq250” 3 years ago
parent
commit
12cc870dc7
1 changed files with 14 additions and 4 deletions
  1. +14
    -4
      app/helpers/application_helper.rb

+ 14
- 4
app/helpers/application_helper.rb View File

@@ -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


Loading…
Cancel
Save