diff options
author | Matthew Somerville <matthew@mysociety.org> | 2011-06-07 17:26:01 +0100 |
---|---|---|
committer | Matthew Somerville <matthew@mysociety.org> | 2011-06-07 17:26:01 +0100 |
commit | b5a218792a7bcf477c930205b6a7c341a90d3efd (patch) | |
tree | 0de28f29f7d1210258838ac0f9be4226f4aac627 | |
parent | 891428159dd27e5648676b7b9b51c5a2fe2f83ed (diff) |
Final bits of Page.pm gone.
-rw-r--r-- | perllib/FixMyStreet/App/View/Web.pm | 5 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Problem.pm | 5 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm | 4 | ||||
-rw-r--r-- | perllib/FixMyStreet/Geocode.pm | 1 | ||||
-rw-r--r-- | perllib/Page.pm | 67 | ||||
-rw-r--r-- | perllib/Standard.pm | 2 | ||||
-rw-r--r-- | perllib/Utils.pm | 50 | ||||
-rwxr-xr-x | t/Cobrand.t | 7 | ||||
-rw-r--r-- | t/Cobrands/Mysite/Util.pm | 1 |
9 files changed, 65 insertions, 77 deletions
diff --git a/perllib/FixMyStreet/App/View/Web.pm b/perllib/FixMyStreet/App/View/Web.pm index b5f6e341d..5b20e286b 100644 --- a/perllib/FixMyStreet/App/View/Web.pm +++ b/perllib/FixMyStreet/App/View/Web.pm @@ -8,6 +8,7 @@ use mySociety::Locale; use mySociety::Web qw(ent); use FixMyStreet; use CrossSell; +use Utils; __PACKAGE__->config( TEMPLATE_EXTENSION => '.html', @@ -91,7 +92,7 @@ sub display_crosssell_advert { return CrossSell::display_advert( $q, $email, $name, %data ); } -=head2 Page::prettify_epoch +=head2 Utils::prettify_epoch [% pretty = prettify_epoch( $epoch, $short_bool ) %] @@ -104,7 +105,7 @@ Return a pretty version of the epoch. sub prettify_epoch { my ( $self, $c, $epoch, $short_bool ) = @_; - return Page::prettify_epoch( $epoch, $short_bool ); + return Utils::prettify_epoch( $epoch, $short_bool ); } =head2 add_links diff --git a/perllib/FixMyStreet/DB/Result/Problem.pm b/perllib/FixMyStreet/DB/Result/Problem.pm index c3475e31c..f496fb062 100644 --- a/perllib/FixMyStreet/DB/Result/Problem.pm +++ b/perllib/FixMyStreet/DB/Result/Problem.pm @@ -107,6 +107,7 @@ use DateTime::TimeZone; use Image::Size; use Moose; use namespace::clean -except => [ 'meta' ]; +use Utils; with 'FixMyStreet::Roles::Abuser'; @@ -279,7 +280,7 @@ sub meta_line { my ( $problem, $c ) = @_; my $date_time = - Page::prettify_epoch( $problem->confirmed_local->epoch ); + Utils::prettify_epoch( $problem->confirmed_local->epoch ); my $meta = ''; # FIXME Should be in cobrand @@ -360,7 +361,7 @@ sub duration_string { $body = join(' and ', map { $areas_info->{$_}->{name} } @councils); } return sprintf(_('Sent to %s %s later'), $body, - Page::prettify_duration($problem->whensent_local->epoch - $problem->confirmed_local->epoch, 'minute') + Utils::prettify_duration($problem->whensent_local->epoch - $problem->confirmed_local->epoch, 'minute') ); } diff --git a/perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm b/perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm index 1f5e26197..f197cfc95 100644 --- a/perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm +++ b/perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm @@ -4,7 +4,7 @@ use base 'DBIx::Class::ResultSet'; use strict; use warnings; use File::Slurp; -use Page; +use Utils; use mySociety::EmailUtil; sub send_questionnaires { @@ -63,7 +63,7 @@ sub send_questionnaires_period { } my %h = map { $_ => $row->$_ } qw/name title detail category/; - $h{created} = Page::prettify_duration( time() - $row->confirmed->epoch, 'week' ); + $h{created} = Utils::prettify_duration( time() - $row->confirmed->epoch, 'week' ); my $questionnaire = FixMyStreet::App->model('DB::Questionnaire')->create( { problem_id => $row->id, diff --git a/perllib/FixMyStreet/Geocode.pm b/perllib/FixMyStreet/Geocode.pm index 9419a91f7..50a7ba339 100644 --- a/perllib/FixMyStreet/Geocode.pm +++ b/perllib/FixMyStreet/Geocode.pm @@ -18,7 +18,6 @@ use Digest::MD5 qw(md5_hex); use URI::Escape; use Cobrand; -use Page; use Utils; use mySociety::Config; use mySociety::Locale; diff --git a/perllib/Page.pm b/perllib/Page.pm deleted file mode 100644 index c2a4bb38f..000000000 --- a/perllib/Page.pm +++ /dev/null @@ -1,67 +0,0 @@ -#!/usr/bin/perl - -package Page; - -use strict; -use Encode; -use POSIX qw(strftime); -use Memcached; -use Problems; -use Cobrand; -use mySociety::Config; -use mySociety::Locale; - -BEGIN { - (my $dir = __FILE__) =~ s{/[^/]*?$}{}; - mySociety::Config::set_file("$dir/../conf/general"); -} - -sub prettify_epoch { - my ($s, $short) = @_; - my @s = localtime($s); - my $tt = strftime('%H:%M', @s); - my @t = localtime(); - if (strftime('%Y%m%d', @s) eq strftime('%Y%m%d', @t)) { - $tt = "$tt " . _('today'); - } elsif (strftime('%Y %U', @s) eq strftime('%Y %U', @t)) { - $tt = "$tt, " . decode_utf8(strftime('%A', @s)); - } elsif ($short) { - $tt = "$tt, " . decode_utf8(strftime('%e %b %Y', @s)); - } elsif (strftime('%Y', @s) eq strftime('%Y', @t)) { - $tt = "$tt, " . decode_utf8(strftime('%A %e %B %Y', @s)); - } else { - $tt = "$tt, " . decode_utf8(strftime('%a %e %B %Y', @s)); - } - return $tt; -} - -# argument is duration in seconds, rounds to the nearest minute -sub prettify_duration { - my ($s, $nearest) = @_; - if ($nearest eq 'week') { - $s = int(($s+60*60*24*3.5)/60/60/24/7)*60*60*24*7; - } elsif ($nearest eq 'day') { - $s = int(($s+60*60*12)/60/60/24)*60*60*24; - } elsif ($nearest eq 'hour') { - $s = int(($s+60*30)/60/60)*60*60; - } elsif ($nearest eq 'minute') { - $s = int(($s+30)/60)*60; - return _('less than a minute') if $s == 0; - } - my @out = (); - _part(\$s, 60*60*24*7, _('%d week'), _('%d weeks'), \@out); - _part(\$s, 60*60*24, _('%d day'), _('%d days'), \@out); - _part(\$s, 60*60, _('%d hour'), _('%d hours'), \@out); - _part(\$s, 60, _('%d minute'), _('%d minutes'), \@out); - return join(', ', @out); -} -sub _part { - my ($s, $m, $w1, $w2, $o) = @_; - if ($$s >= $m) { - my $i = int($$s / $m); - push @$o, sprintf(mySociety::Locale::nget($w1, $w2, $i), $i); - $$s -= $i * $m; - } -} - -1; diff --git a/perllib/Standard.pm b/perllib/Standard.pm index 571065c14..0a6f27490 100644 --- a/perllib/Standard.pm +++ b/perllib/Standard.pm @@ -18,8 +18,6 @@ use FindBin; use lib "$FindBin::Bin/../perllib"; use lib "$FindBin::Bin/../commonlib/perllib"; -use Page; - package Standard; sub import { diff --git a/perllib/Utils.pm b/perllib/Utils.pm index c267bbea0..bf8ac2805 100644 --- a/perllib/Utils.pm +++ b/perllib/Utils.pm @@ -12,6 +12,8 @@ package Utils; use strict; +use Encode; +use POSIX qw(strftime); use mySociety::DBHandle qw(dbh); use mySociety::GeoUtil; use mySociety::Locale; @@ -206,4 +208,52 @@ sub cleanup_text { return $input; } +sub prettify_epoch { + my ($s, $short) = @_; + my @s = localtime($s); + my $tt = strftime('%H:%M', @s); + my @t = localtime(); + if (strftime('%Y%m%d', @s) eq strftime('%Y%m%d', @t)) { + $tt = "$tt " . _('today'); + } elsif (strftime('%Y %U', @s) eq strftime('%Y %U', @t)) { + $tt = "$tt, " . decode_utf8(strftime('%A', @s)); + } elsif ($short) { + $tt = "$tt, " . decode_utf8(strftime('%e %b %Y', @s)); + } elsif (strftime('%Y', @s) eq strftime('%Y', @t)) { + $tt = "$tt, " . decode_utf8(strftime('%A %e %B %Y', @s)); + } else { + $tt = "$tt, " . decode_utf8(strftime('%a %e %B %Y', @s)); + } + return $tt; +} + +# argument is duration in seconds, rounds to the nearest minute +sub prettify_duration { + my ($s, $nearest) = @_; + if ($nearest eq 'week') { + $s = int(($s+60*60*24*3.5)/60/60/24/7)*60*60*24*7; + } elsif ($nearest eq 'day') { + $s = int(($s+60*60*12)/60/60/24)*60*60*24; + } elsif ($nearest eq 'hour') { + $s = int(($s+60*30)/60/60)*60*60; + } elsif ($nearest eq 'minute') { + $s = int(($s+30)/60)*60; + return _('less than a minute') if $s == 0; + } + my @out = (); + _part(\$s, 60*60*24*7, _('%d week'), _('%d weeks'), \@out); + _part(\$s, 60*60*24, _('%d day'), _('%d days'), \@out); + _part(\$s, 60*60, _('%d hour'), _('%d hours'), \@out); + _part(\$s, 60, _('%d minute'), _('%d minutes'), \@out); + return join(', ', @out); +} +sub _part { + my ($s, $m, $w1, $w2, $o) = @_; + if ($$s >= $m) { + my $i = int($$s / $m); + push @$o, sprintf(mySociety::Locale::nget($w1, $w2, $i), $i); + $$s -= $i * $m; + } +} + 1; diff --git a/t/Cobrand.t b/t/Cobrand.t index d3857e523..047fcc71c 100755 --- a/t/Cobrand.t +++ b/t/Cobrand.t @@ -21,7 +21,14 @@ use lib "$FindBin::Bin/../perllib"; use lib "$FindBin::Bin/../commonlib/perllib"; use Cobrand; +use Problems; use mySociety::MockQuery; +use mySociety::Config; + +BEGIN { + (my $dir = __FILE__) =~ s{/[^/]*?$}{}; + mySociety::Config::set_file("$dir/../conf/general"); +} sub test_site_restriction { my ($site_restriction, $site_id) = Cobrand::site_restriction('mysite', 'test'); diff --git a/t/Cobrands/Mysite/Util.pm b/t/Cobrands/Mysite/Util.pm index 65591528f..b733cb5b7 100644 --- a/t/Cobrands/Mysite/Util.pm +++ b/t/Cobrands/Mysite/Util.pm @@ -10,7 +10,6 @@ # $Id: Util.pm,v 1.20 2009-12-16 12:43:13 matthew Exp $ package Cobrands::Mysite::Util; -use Page; use strict; use Carp; use mySociety::Web qw(ent); |