Sha256: 37a5526366ebf85651317164f45d652e79735842122b60b97c3bd1d1e9ed00dc
Contents?: true
Size: 993 Bytes
Versions: 15
Compression:
Stored size: 993 Bytes
Contents
module CreativeRailsUtilities module ViewHelpers def relative_time_parse(earlier_time, later_time=nil) later_time ||= Time.now difference = (later_time.to_i - earlier_time.to_i).to_i case difference when 0 return {key: "now", count: nil} when 1 return {key: "second", count: nil} when 2..59 return {key: "seconds", count: difference.to_s} when 60..119 return {key: "minute", count: nil} when 120..3540 return {key: "minutes", count: (difference/60).to_i.to_s} when 3541..7100 return {key: "hour", count: nil} when 7101..82800 return {key: "hours", count: ((difference+99)/3600).to_i.to_s} when 82801..172000 return {key: "day", count: nil} else if difference < 0 return {key: "now", count: nil} else return {key: "days", count: ((difference+800)/(60*60*24)).to_i.to_s} end end end end end
Version data entries
15 entries across 15 versions & 1 rubygems