Попробуйте это:
def my_time_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
Эта функция будет работать так же, как и time_ago_in_words
. Когда from_time
находится между 1 и 3 неделями назад, будет напечатано last week
, two weeks ago
, three weeks ago
, в противном случае будет напечатано обычное значение.