From b14319e75b61ce1ee21ebb7d6fa924ebe18ceee9 Mon Sep 17 00:00:00 2001 From: pezholio Date: Tue, 17 Jan 2017 16:44:50 +0000 Subject: Add Problem->time_ago for pretty-printed duration --- perllib/FixMyStreet/DB/Result/Problem.pm | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'perllib/FixMyStreet/DB/Result/Problem.pm') diff --git a/perllib/FixMyStreet/DB/Result/Problem.pm b/perllib/FixMyStreet/DB/Result/Problem.pm index 0092dd8b5..d0a5a3a4f 100644 --- a/perllib/FixMyStreet/DB/Result/Problem.pm +++ b/perllib/FixMyStreet/DB/Result/Problem.pm @@ -659,6 +659,20 @@ sub body { return $body; } + +=head2 time_ago + Returns how long ago a problem was reported in an appropriately + prettified duration, depending on the duration. +=cut + +sub time_ago { + my ( $self, $date ) = @_; + $date ||= 'confirmed'; + my $duration = time() - $self->$date->epoch; + + return Utils::prettify_duration( $duration ); +} + =head2 response_templates Returns all ResponseTemplates attached to this problem's bodies, in alphabetical -- cgit v1.2.3