Yes, I had seen that. It looked very similar to Time::Duration except that it's based on DateTime.

Here's a script comparing Time::Duration, DateTime::Format::Human::Duration, and Time::Ago for various durations.

#!/usr/bin/env perl use strict; use warnings; use lib 'lib'; use DateTime; use DateTime::Format::Human::Duration; use Time::Ago; use Time::Duration; my $hour = 60 * 60; my $day = $hour * 24; my $month = $day * 30; my @durations = ( 0, 38, 60 * 4, $hour * 3.8, $month * 7, $month * 23, $month * 28, ); my $class = 'Human::Duration'; foreach (@durations) { my $dt1 = DateTime->from_epoch(epoch => time - $_); my $dt2 = DateTime->from_epoch(epoch => time); my $diff = $dt2 - $dt1; print "Seconds: $_\n"; printf "%-25s %s\n", ' Time::Ago', Time::Ago->in_words($diff); print "\n"; my $class = ' Human::Duration'; printf "%-25s %s\n", "$class #1", DateTime::Format::Human::Duration->new->format_duration($diff); printf "%-25s %s\n", "$class #2", DateTime::Format::Human::Duration->new->format_duration( $diff, units => [qw/ years months /], ); printf "%-25s %s\n", "$class #3", DateTime::Format::Human::Duration->new->format_duration( $diff, precision => 'years', ); print "\n"; $class = ' Time::Duration'; printf "%-25s %s\n", "$class #1", Time::Duration::ago($_); printf "%-25s %s\n", "$class #1", Time::Duration::ago($_, 1); print "\n\n"; }

Output:

Seconds: 0 Time::Ago less than a minute Human::Duration #1 no time Human::Duration #2 no time Human::Duration #3 no time Time::Duration #1 right now Time::Duration #2 right now Seconds: 38 Time::Ago 1 minute Human::Duration #1 38 seconds Human::Duration #2 no time Human::Duration #3 no time Time::Duration #1 38 seconds ago Time::Duration #2 38 seconds ago Seconds: 240 Time::Ago 4 minutes Human::Duration #1 4 minutes Human::Duration #2 no time Human::Duration #3 no time Time::Duration #1 4 minutes ago Time::Duration #2 4 minutes ago Seconds: 13680 Time::Ago about 4 hours Human::Duration #1 3 hours and 48 minutes Human::Duration #2 no time Human::Duration #3 no time Time::Duration #1 3 hours and 48 minutes ago Time::Duration #2 4 hours ago Seconds: 18144000 Time::Ago 7 months Human::Duration #1 6 months, 4 weeks, and 1 day Human::Duration #2 6 months Human::Duration #3 no time Time::Duration #1 210 days ago Time::Duration #2 210 days ago Seconds: 59616000 Time::Ago almost 2 years Human::Duration #1 1 year, 10 months, 3 weeks, and 1 day Human::Duration #2 1 year and 10 months Human::Duration #3 1 year Time::Duration #1 1 year and 325 days ago Time::Duration #2 2 years ago Seconds: 72576000 Time::Ago over 2 years Human::Duration #1 2 years, 3 months, 2 weeks, and 5 days Human::Duration #2 2 years and 3 months Human::Duration #3 2 years Time::Duration #1 2 years and 110 days ago Time::Duration #2 2 years ago

You can see that Time::Ago is much more lax in it's approximation, always returning just a single, rounded unit.

The use-case for this is when precision is not especially important. e.g., for when a comment was made on a website, etc.

The latest version of T::A on github is now using Locale::TextDomain for localization, and support has been added for handling DateTime::Duration objects directly.


In reply to Re^2: Perl Time Ago in Words by mla12
in thread Perl Time Ago in Words by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.