Distance of time in days

In rails 3 there is distance_of_time_in_words which works fine, but I
would like to tweak its output a bit.

The thing is that if the dates are exactly the same it will say “Less
Than a Minute” I would like it to show “Today” instead.

Is that possible?

Tiago V.
[email protected]

In rails 3 there is distance_of_time_in_words which works fine, but I would like
to tweak its output a bit.

The thing is that if the dates are exactly the same it will say “Less Than a
Minute” I would like it to show “Today” instead.

Is that possible?

Write your own method that wraps this one. Compare the dates yourself
and if they are < 1 minute spit out “Today” otherwise spit out the
result of the original method…

That’s what I’d do anyway…

-philip

In rails 3 there is distance_of_time_in_words which works fine, but I would
like to tweak its output a bit.

The thing is that if the dates are exactly the same it will say “Less Than a
Minute” I would like it to show “Today” instead.

Is that possible?

Write your own method that wraps this one. Compare the dates yourself and if
they are < 1 minute spit out “Today” otherwise spit out the result of the original
method…

That’s what I’d do anyway…

Or see if that method uses locale files that you can overwrite the value
for “Less Than A Minute”…

-philip

It does indeed. It’s in ActionView:

en:
datetime:
distance_in_words:
half_a_minute: “half a minute”
less_than_x_seconds:
one: “less than 1 second”
other: “less than %{count} seconds”
x_seconds:
one: “1 second”
other: “%{count} seconds”
less_than_x_minutes:
one: “less than a minute”
other: “less than %{count} minutes”

https://github.com/rails/rails/blob/master/actionpack/lib/action_view/locale/en.yml

Thank you.

I have overridden the method. And added a custom key. I prefer not to
change the defaults.

Tiago V.
[email protected]

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs