tomazos has asked for the wisdom of the Perl Monks concerning the following question:
sub timediff($;$) { my $then = $_[0]; my $now; if (defined $_[1]) { $now = $_[1]; } else { # set $now from system clock } my $diff; # $diff = relative time between $now and $then return $diff; }
$diff should be something like '30 seconds ago', '4 years from now', 'last month', '4 hours from now', 'yesterday', '2 days ago', etc.
Is there a CPAN module out there that does it?
sub timediff($) { use Time::Piece; use Time::Piece::MySQL; use Time::Duration; my $time = Time::Piece->from_mysql_timestamp( $_[0] ); my $now = localtime; my $diff = ago ($now->epoch() - $time->epoch(), 1); return $diff; }
Any improvements on the above would be greatly appreciated.
-Andrew.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Descriptive Relative Time
by Limbic~Region (Chancellor) on Aug 02, 2005 at 14:46 UTC | |
by xdg (Monsignor) on Aug 02, 2005 at 15:08 UTC | |
by Limbic~Region (Chancellor) on Aug 02, 2005 at 15:14 UTC | |
|
Re: Descriptive Relative Time
by kwaping (Priest) on Aug 02, 2005 at 14:43 UTC | |
|
Re: Descriptive Relative Time
by blazar (Canon) on Aug 02, 2005 at 14:46 UTC |