distance_of_time_in_words_to_now

171 views
Skip to first unread message

Ace Suares

unread,
Jan 2, 2013, 11:35:41 AM1/2/13
to rubyonra...@googlegroups.com
Hi There,

As I have learned the hard way, let me discuss my question, idea or feature here before doing actual work on it...

distance_of_time_in_words_to_now() seems to be unable to tell if this distance is in the future or in the past.

I'd really like to see 'in 5 days' or '5 days ago' depending on, well, if it was 5 days ago or will be in 5 days.

I've googled and saw some gems, one by Radar, but I think this seemingly simple thing shouldn't be in a gem.

I'd be happy to hear your comments.

Cheers

Ace

Gosha Arinich

unread,
Jan 2, 2013, 11:38:50 AM1/2/13
to rubyonra...@googlegroups.com
I support this. I just don't think it should be the only way — there should be an option to set if we're just interested in distance (z days), or if we're interested in one with regard to whether it was in past or will be in the future (in x days, y days ago).

Cheers,
Gosha Arinich

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-core/-/QrBjDIZXelEJ.
To post to this group, send email to rubyonra...@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-co...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.

Ace Suares

unread,
Jan 2, 2013, 2:32:38 PM1/2/13
to rubyonra...@googlegroups.com
I have this now

module ActionView::Helpers::DateHelper

  def distance_of_time_in_words_to_now_with_future(from_time, include_seconds = false)
    if from_time > Time.now()
      'in ' + distance_of_time_in_words_to_now_without_future(from_time, include_seconds)
    else
      distance_of_time_in_words_to_now_without_future(from_time, include_seconds) + ' ago'
    end
  end

  alias_method_chain :distance_of_time_in_words_to_now, :future

end

Gosha Arinich

unread,
Jan 2, 2013, 2:41:25 PM1/2/13
to rubyonra...@googlegroups.com
You don't take i18n into account.

Additionally, I would not use method chain or so for this. Instead, I would just modify `distance_of_time_in_words_to_now` to handle additional boolean option called `:relative`, and just handle it.

Cheers,
Gosha Arinich

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-core/-/cDyUxC3RVwkJ.

Ace Suares

unread,
Jan 2, 2013, 2:46:43 PM1/2/13
to rubyonra...@googlegroups.com
Agree, I am just showing what kind of thing works now and how I'd like 
it to be more like you pointed out.
Reply all
Reply to author
Forward
0 new messages