From c6a83bac720f79f5ae8947c03ae3f048afcbe3e6 Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 31 Jul 2012 17:17:32 +0100 Subject: [PATCH] Allow callers to prevent span generation. --- Template.pm | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/Template.pm b/Template.pm index dc0e7b2..2d42811 100644 --- a/Template.pm +++ b/Template.pm @@ -798,20 +798,23 @@ sub format_time { } -## @method $ fancy_time($time) +## @method $ fancy_time($time, $nospan) # Generate a string containing a 'fancy' representation of the time - rather than # explicitly showing the time, this will generate things like "just now", "less # than a minute ago", "1 minute ago", "20 minutes ago", etc. The real formatted # time is provided as the title for a span containing the fancy time. # -# @param time The time to generate a string for. +# @param time The time to generate a string for. +# @param nospan Allow the suppression of span generation, in which case only the +# fancy time string is returned. # @return A string containing a span element representing both the fancy time as # the element content, and the formatted time as the title. The span has # the class 'timestr' for css formatting. sub fancy_time { - my $self = shift; - my $time = shift; - my $now = time(); + my $self = shift; + my $time = shift; + my $nospan = shift; + my $now = time(); my $formatted = $self -> format_time($time); my $fancytime; @@ -832,6 +835,8 @@ sub fancy_time { } } + return $fancytime if(!$nospan); + return ''.$fancytime.''; }