Inversion time delta tag.
This tag is a derivative of the 'attr' tag that transforms the results of its method call to a Time object (if it isn't already), and then generates an English description of the different between it and the current time.
Updated <?timedelta entry.update_date ?>.
Render the tag.
# File lib/inversion/template/timedeltatag.rb, line 37 def render( renderstate ) val = super( renderstate ) time = nil if val.respond_to?( :to_time ) time = val.to_time elsif val.is_a?( Numeric ) time = Time.at( val ) else time = Time.parse( val.to_s ) end now = Time.now if now > time seconds = now - time return "%s ago" % [ timeperiod(seconds) ] else seconds = time - now return "%s from now" % [ timeperiod(seconds) ] end end
Generated with the Darkfish Rdoc Generator 2.