diff options
-rw-r--r-- | perllib/Page.pm | 21 | ||||
-rwxr-xr-x | web/index.cgi | 7 |
2 files changed, 24 insertions, 4 deletions
diff --git a/perllib/Page.pm b/perllib/Page.pm index 9927a3934..fb6a1a90b 100644 --- a/perllib/Page.pm +++ b/perllib/Page.pm @@ -6,7 +6,7 @@ # Copyright (c) 2006 UK Citizens Online Democracy. All rights reserved. # Email: matthew@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: Page.pm,v 1.41 2007-05-01 16:24:40 matthew Exp $ +# $Id: Page.pm,v 1.42 2007-05-03 09:21:31 matthew Exp $ # package Page; @@ -200,6 +200,25 @@ sub prettify_epoch { return $tt; } +# argument is duration in seconds, rounds to the nearest minute +sub prettify_duration { + my $s = shift; + $s = int(($s+30)/60)*60; + my @out = (); + _part(\$s, 60*60*24, 'day', \@out); + _part(\$s, 60*60, 'hour', \@out); + _part(\$s, 60, 'minute', \@out); + return join(', ', @out); +} +sub _part { + my ($s, $m, $w, $o) = @_; + if ($$s > $m) { + my $i = int($$s / $m); + push @$o, "$i $w" . ($i != 1 ? 's' : ''); + $$s -= $i * $m; + } +} + # Simply so I can gettext the code without making the locale stuff all work sub _ { return $_[0]; diff --git a/web/index.cgi b/web/index.cgi index 180e481db..03690f935 100755 --- a/web/index.cgi +++ b/web/index.cgi @@ -6,7 +6,7 @@ # Copyright (c) 2006 UK Citizens Online Democracy. All rights reserved. # Email: matthew@mysociety.org. WWW: http://www.mysociety.org # -# $Id: index.cgi,v 1.117 2007-05-02 17:30:32 matthew Exp $ +# $Id: index.cgi,v 1.118 2007-05-03 09:21:31 matthew Exp $ # TODO # Nothing is done about the update checkboxes - not stored anywhere on anything! @@ -552,7 +552,7 @@ sub display_problem { # Get all information from database my $problem = dbh()->selectrow_arrayref( "select state, easting, northing, title, detail, name, extract(epoch from created), photo, anonymous, - extract(epoch from whensent), council + extract(epoch from whensent-created), council from problem where id=? and state in ('confirmed','fixed', 'hidden')", {}, $input{id}); return display_location($q, 'Unknown problem ID') unless $problem; my ($state, $easting, $northing, $title, $desc, $name, $time, @@ -586,7 +586,8 @@ EOF my @councils = split /,/, $council; my $areas_info = mySociety::MaPit::get_voting_areas_info(\@councils); $council = join(' and ', map { $areas_info->{$_}->{name} } @councils); - $out .= $q->br() . $q->small('Sent to ' . $council . ' at ' . Page::prettify_epoch($whensent)); + $out .= $q->br() . $q->small('Sent to ' . $council . ' ' . + Page::prettify_duration($whensent) . ' later'); } } else { $out .= $q->br() . $q->small('Not reported to council'); |