diff options
author | Matthew Somerville <matthew@mysociety.org> | 2014-04-07 15:51:49 +0100 |
---|---|---|
committer | Matthew Somerville <matthew@mysociety.org> | 2014-04-07 15:51:49 +0100 |
commit | bd79f43d6a2f77b09dab73be3f0ff4d24a800d4a (patch) | |
tree | 7164e8ecf5559da98e00f7b56461c33e4a9c35b6 /perllib | |
parent | 23da5da5f3a64d34e9fd961122e44ff6b4dc913b (diff) |
Use local DateTimes in dashboard and its tests.
Otherwise oddities arise due to summer time differences
putting a BST now-6d23h time behind a UTC now+1s-1w.
Diffstat (limited to 'perllib')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Dashboard.pm | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Dashboard.pm b/perllib/FixMyStreet/App/Controller/Dashboard.pm index b47a1f54b..b5f65d8c8 100644 --- a/perllib/FixMyStreet/App/Controller/Dashboard.pm +++ b/perllib/FixMyStreet/App/Controller/Dashboard.pm @@ -128,15 +128,16 @@ sub index : Path : Args(0) { my $dtf = $c->model('DB')->storage->datetime_parser; my %counts; - my $t = DateTime->today; + my $now = DateTime->now( time_zone => 'local' ); + my $t = $now->clone->truncate( to => 'day' ); $counts{wtd} = $c->forward( 'updates_search', - [ $dtf->format_datetime( $t->subtract( days => $t->dow - 1 ) ) ] ); + [ $dtf->format_datetime( $t->clone->subtract( days => $t->dow - 1 ) ) ] ); $counts{week} = $c->forward( 'updates_search', - [ $dtf->format_datetime( DateTime->now->subtract( weeks => 1 ) ) ] ); + [ $dtf->format_datetime( $now->clone->subtract( weeks => 1 ) ) ] ); $counts{weeks} = $c->forward( 'updates_search', - [ $dtf->format_datetime( DateTime->now->subtract( weeks => 4 ) ) ] ); + [ $dtf->format_datetime( $now->clone->subtract( weeks => 4 ) ) ] ); $counts{ytd} = $c->forward( 'updates_search', - [ $dtf->format_datetime( DateTime->today->set( day => 1, month => 1 ) ) ] ); + [ $dtf->format_datetime( $t->clone->set( day => 1, month => 1 ) ) ] ); $c->stash->{problems} = \%counts; @@ -152,16 +153,16 @@ sub index : Path : Args(0) { } my $params = { %$prob_where, - 'me.confirmed' => { '>=', $dtf->format_datetime( DateTime->now->subtract( days => 30 ) ) }, + 'me.confirmed' => { '>=', $dtf->format_datetime( $now->clone->subtract( days => 30 ) ) }, }; my $problems_rs = $c->cobrand->problems->search( $params ); my @problems = $problems_rs->all; my %problems; foreach (@problems) { - if ($_->confirmed >= DateTime->now->subtract(days => 7)) { + if ($_->confirmed >= $now->clone->subtract(days => 7)) { push @{$problems{1}}, $_; - } elsif ($_->confirmed >= DateTime->now->subtract(days => 14)) { + } elsif ($_->confirmed >= $now->clone->subtract(days => 14)) { push @{$problems{2}}, $_; } else { push @{$problems{3}}, $_; |