Home : Products : Gossamer Links : Development, Plugins and Globals :

Products: Gossamer Links: Development, Plugins and Globals: Re: [anthonyweston] Displaying the age of a link: Edit Log

Here is the list of edits for this post
Re: [anthonyweston] Displaying the age of a link
Okay, before I catch the tube here is little something Smile
It should give you the desired result.

I called this global link_age to reflect it's purpose.

Code:
sub {
my $added = GT::Date::date_get($_[0]);
my $old = GT::Date::date_diff(GT::Date::date_get(), $added);

my $output;

if ($old == 0 ) {
$output = "Today";
}
elsif ( int ($old / 7) > 0 && int ($old / 7) < 4 ) {
my $weeks = int ($old / 7);
$output = $weeks == 1 ? "Week ago" : $weeks . " weeks ago";
}
elsif ( $old < 30 ) {
$output = $old == 1 ? "Yesterday" : $old . " days ago";
}
elsif ( $old < 365 ) {
my $months = int ($old / 30 );
$output = $months == 1 ? "Month ago" : $months . " months ago";
}
else {
my $years = int ($old / 365 );
$output = $years == 1 ? "Year ago" : $years . " years ago";
}

return $output;
}

Call it the same way as before <%link_age($Add_Date_time)%>, and it'll produce the age of the link: Today, Week ago, 3 weeks ago, Month ago ... etc.

Cheers,
Boris

Facebook, Twitter and Google+ Auth for GLinks and GCommunity | reCAPTCHA for GLinks | Free GLinks Plugins

Last edited by:

eupos: Oct 18, 2012, 9:58 AM

Edit Log: