Methods

Inversion::Template::TimeDeltaTag

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.

Syntax

Updated <?timedelta entry.update_date ?>.

Public Instance Methods

render( renderstate ) click to toggle source

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

[Validate]

Generated with the Darkfish Rdoc Generator 2.