diff options
author | pezholio <pezholio@gmail.com> | 2017-01-17 16:44:50 +0000 |
---|---|---|
committer | Dave Arter <davea@mysociety.org> | 2017-02-15 13:28:04 +0000 |
commit | b14319e75b61ce1ee21ebb7d6fa924ebe18ceee9 (patch) | |
tree | a127709b1254de587fadce5f3b7aa82decffc09a /perllib/FixMyStreet | |
parent | 0b1ab9fb1145ca32dced46b4faefe49da5c76768 (diff) |
Add Problem->time_ago for pretty-printed duration
Diffstat (limited to 'perllib/FixMyStreet')
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Problem.pm | 14 |
1 files changed, 14 insertions, 0 deletions
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 |