我试图显示从周数“x 周前”计算的周数,这应该只是在一周前、两周前、三周前、1 个月前、2 个月前、1 年前......等
我使用方法助手:
def weeks_ago_in_words(from_time, include_seconds = false)
to_time = Time.now
weeks_ago = ((to_time - from_time)/1.week).abs
[nil, "last week", "two weeks ago", "three weeks ago"][weeks_ago] ||
distance_of_time_in_words(from_time, to_time, include_seconds)
end
鉴于:
= weeks_ago_in_words(Time.local(2013) + week.to_i)
week = a week number like 1,10,28,52 etc
这并没有给我正确的结果,有没有更好的方法来根据 weeknumer 计算“x 周前”?