diff options
author | Andrew Black <andrewdblack@googlemail.com> | 2013-08-30 15:50:46 +0100 |
---|---|---|
committer | Dave Whiteland <dave@mysociety.org> | 2013-11-07 12:41:12 +0000 |
commit | c992dc56317554b2fb698cc91bc815f40a273e30 (patch) | |
tree | b811936ac58892d3402b98a884d119ea2733ebfc /perllib/FixMyStreet/App/Controller/Admin.pm | |
parent | 5263ca87456f7d5d39b500731499ad20c6dd8636 (diff) |
Create a single date fields and parse as DD/MM/YYYY
Diffstat (limited to 'perllib/FixMyStreet/App/Controller/Admin.pm')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Admin.pm | 25 |
1 files changed, 8 insertions, 17 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index 07bd61cbb..e88c780fd 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -9,6 +9,8 @@ use POSIX qw(strftime strcoll); use Digest::SHA qw(sha1_hex); use mySociety::EmailUtil qw(is_valid_email); use if !$ENV{TRAVIS}, 'Image::Magick'; +use DateTime::Format::Strptime; + use FixMyStreet::SendReport; @@ -1076,26 +1078,15 @@ sub stats : Path('stats') : Args(0) { if ( $c->req->param('getcounts') ) { my ( $start_date, $end_date, @errors ); + my $parser = DateTime::Format::Strptime->new( pattern => '%d/%m/%Y' ); + + $start_date = $parser-> parse_datetime ( $c->req->param('start_date') ); - eval { - $start_date = DateTime->new( - year => $c->req->param('start_date_year'), - month => $c->req->param('start_date_month'), - day => $c->req->param('start_date_day'), - ); - }; - - push @errors, _('Invalid start date') if $@; + push @errors, _('Invalid start date') unless defined $start_date; - eval { - $end_date = DateTime->new( - year => $c->req->param('end_date_year'), - month => $c->req->param('end_date_month'), - day => $c->req->param('end_date_day'), - ); - }; + $end_date = $parser-> parse_datetime ( $c->req->param('end_date') ) ; - push @errors, _('Invalid end date') if $@; + push @errors, _('Invalid end date') unless defined $end_date; $c->stash->{errors} = \@errors; $c->stash->{start_date} = $start_date; |