Skip to content
This repository has been archived by the owner on Nov 19, 2021. It is now read-only.

Commit

Permalink
Merge pull request #253 from duckduckgo/duration-units
Browse files Browse the repository at this point in the history
Use a maximum of 2 units when describing comment / thread age.
  • Loading branch information
jbarrett committed Oct 24, 2014
2 parents 25e9a20 + b971d3a commit 9764d30
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions lib/DDGC/Util/DateTime.pm
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,25 @@ use DateTime::Format::Human::Duration;
sub dur {
my ( $date ) = @_;
$date = DateTime->from_epoch( epoch => $date ) unless ref $date;
my $diff = DateTime->now - $date;
my $units = [qw/ hours minutes /];

$units = [qw/ days hours /] if ($diff->days > 0);
$units = [qw/ months days /] if ($diff->months > 0);
$units = [qw/ years /] if ($diff->years > 0);

return DateTime::Format::Human::Duration->new->format_duration(
DateTime->now - $date,
$diff,
'units' => $units,
'past' => '%s ago',
'future' => 'in %s will be',
'no_time' => 'just now',
'precision' => 'minutes',
'significant_units' => 2,
);
}

sub dur_precise {
my ( $date ) = @_;
$date = DateTime->from_epoch( epoch => $date ) unless ref $date;
return DateTime::Format::Human::Duration->new->format_duration(
DateTime->now - $date,
'units' => [qw/years months days hours minutes/],
'past' => '%s ago',
'future' => 'in %s will be',
'no_time' => 'just now',
);
dur( $date );
}

1;

0 comments on commit 9764d30

Please sign in to comment.