Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <%= time_ago_in_words(timestamp) %>
- module PrettyDate
- def to_pretty
- a = (Time.now-self).to_i
- case a
- when 0 then 'just now'
- when 1 then 'a second ago'
- when 2..59 then a.to_s+' seconds ago'
- when 60..119 then 'a minute ago' #120 = 2 minutes
- when 120..3540 then (a/60).to_i.to_s+' minutes ago'
- when 3541..7100 then 'an hour ago' # 3600 = 1 hour
- when 7101..82800 then ((a+99)/3600).to_i.to_s+' hours ago'
- when 82801..172000 then 'a day ago' # 86400 = 1 day
- when 172001..518400 then ((a+800)/(60*60*24)).to_i.to_s+' days ago'
- when 518400..1036800 then 'a week ago'
- else ((a+180000)/(60*60*24*7)).to_i.to_s+' weeks ago'
- end
- end
- end
- Time.send :include, PrettyDate
- 30.seconds.ago
- 2.days.ago
- <%= time_ago_in_words(Date.today - 1) %>
- include ActionView::Helpers::DateHelper
- def index
- @sexy_date = time_ago_in_words(Date.today - 1)
- end
- Time.now - 2.days
- def relative_time(start_time)
- diff_seconds = Time.now - start_time
- case diff_seconds
- when 0 .. 59
- puts "#{diff_seconds} seconds ago"
- when 60 .. (3600-1)
- puts "#{diff_seconds/60} minutes ago"
- when 3600 .. (3600*24-1)
- puts "#{diff_seconds/3600} hours ago"
- when (3600*24) .. (3600*24*30)
- puts "#{diff_seconds/(3600*24)} days ago"
- else
- puts start_time.strftime("%m/%d/%Y")
- end
- end
- Time.now.yesterday
- Time.now.ago(2.days).end_of_day
- Time.now.next_month.beginning_of_month
- <%= times_ago_in_words(comment.created_at) %>
- <abbr class="timeago" title="<%= comment.created_at.getutc.iso8601 %>">
- <%= comment.created_at.to_s %>
- </abbr>
- $("abbr.timeago").timeago();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement