Module: Twitorious
- Defined in:
- lib/twitorious.rb,
lib/twitorious/image.rb,
lib/twitorious/config.rb,
lib/twitorious/notifier.rb,
lib/twitorious/url/isgd.rb,
lib/twitorious/url/bitly.rb,
lib/twitorious/auth/oauth.rb,
lib/twitorious/api/twitter.rb
Defined Under Namespace
Modules: API, Auth, URL Classes: Config, Image, Notifier, TooLongUpdate
Constant Summary collapse
- VERSION =
'0.3.1'
Class Method Summary collapse
-
.time_ago_in_words(from, to, include_seconds = false, options = {}) ⇒ Object
Shamelessly stolen from Rails and stripped of its localization-code.
Class Method Details
.time_ago_in_words(from, to, include_seconds = false, options = {}) ⇒ Object
Shamelessly stolen from Rails and stripped of its localization-code. Hard-coded strings in english!
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/twitorious.rb', line 8 def self.time_ago_in_words(from, to, include_seconds = false, = {}) from_time = Time.mktime(from.year, from.month, from.day, from.hour, from.min, from.sec) to_time = Time.mktime(to.year, to.month, to.day, to.hour, to.min, to.sec) distance_in_minutes = (((to_time - from_time).abs)/60).round distance_in_seconds = ((to_time - from_time).abs).round case distance_in_minutes when 0..1 return distance_in_minutes == 0 ? "less than a minute ago" : "#{distance_in_minutes} minutes ago" unless include_seconds case distance_in_seconds when 0..4 then "less than five seconds ago" when 5..9 then "less than ten seconds ago" when 10..19 then "less than twenty seconds ago" when 20..39 then "half a minute ago" when 40..59 then "less than a minute ago" else "one minute ago" end when 2..44 then "#{distance_in_minutes} minutes ago" when 45..89 then "about one hour ago" when 90..1439 then "about #{(distance_in_minutes.to_f / 60.0).round} hours ago" when 1440..2879 then "about a day ago" when 2880..43199 then "#{(distance_in_minutes / 1440).round} days ago" when 43200..86399 then "about a month ago" when 86400..525599 then "about #{(distance_in_minutes / 43200).round} months ago" when 525600..1051199 then "about a year ago" else "#{(distance_in_minutes / 525600).round} years ago" end end |