diff options
author | pezholio <pezholio@gmail.com> | 2017-01-24 16:20:48 +0000 |
---|---|---|
committer | Dave Arter <davea@mysociety.org> | 2017-02-27 13:18:03 +0000 |
commit | 587a125c46f229ed23aaf68d3308f6755e2d8299 (patch) | |
tree | c6bff793a2dd44bc249326fdf8b2c187e20ef4ea /perllib/FixMyStreet | |
parent | 36838708a432de937828f6a8ef4aff608654f900 (diff) |
[Oxfordshire] Use 'days ago' format on problem lists
Fixes mysociety/fixmystreetforcouncils#98
Diffstat (limited to 'perllib/FixMyStreet')
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Default.pm | 11 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Oxfordshire.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Problem.pm | 14 |
3 files changed, 27 insertions, 0 deletions
diff --git a/perllib/FixMyStreet/Cobrand/Default.pm b/perllib/FixMyStreet/Cobrand/Default.pm index 63db8b64a..6d9f38d78 100644 --- a/perllib/FixMyStreet/Cobrand/Default.pm +++ b/perllib/FixMyStreet/Cobrand/Default.pm @@ -1204,4 +1204,15 @@ sub traffic_management_options { ]; } + +=head2 display_days_ago_threshold + +Used to control whether a relative 'n days ago' or absolute date is shown +for problems/updates. If a problem/update's `days_ago` value is <= this figure, +the 'n days ago' format is used. By default the absolute date is always used. + +=cut +sub display_days_ago_threshold { 0 } + + 1; diff --git a/perllib/FixMyStreet/Cobrand/Oxfordshire.pm b/perllib/FixMyStreet/Cobrand/Oxfordshire.pm index 7fa548406..2820719b9 100644 --- a/perllib/FixMyStreet/Cobrand/Oxfordshire.pm +++ b/perllib/FixMyStreet/Cobrand/Oxfordshire.pm @@ -165,4 +165,6 @@ sub user_extra_fields { return [ 'initials' ]; } +sub display_days_ago_threshold { 28 } + 1; diff --git a/perllib/FixMyStreet/DB/Result/Problem.pm b/perllib/FixMyStreet/DB/Result/Problem.pm index d78eda78f..4ccad3690 100644 --- a/perllib/FixMyStreet/DB/Result/Problem.pm +++ b/perllib/FixMyStreet/DB/Result/Problem.pm @@ -697,6 +697,20 @@ sub time_ago { return Utils::prettify_duration( $duration ); } +=head2 days_ago + + Returns how many days ago a problem was reported. + +=cut + +sub days_ago { + my ( $self, $date ) = @_; + $date ||= 'confirmed'; + my $now = DateTime->now( time_zone => FixMyStreet->time_zone || FixMyStreet->local_time_zone ); + my $duration = $now->delta_days($self->$date); + return $duration->delta_days; +} + =head2 response_templates Returns all ResponseTemplates attached to this problem's bodies, in alphabetical |