aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStruan Donald <struan@exo.org.uk>2018-06-08 11:37:26 +0100
committerStruan Donald <struan@exo.org.uk>2018-06-08 14:17:33 +0100
commitee64aab278b76c69436a560e05242a833c1b7d6d (patch)
treefcb657c9f7b3bd5fd3c6bff608d906387720938e
parentbb5a526e700d9f9f4568a0defc0241d7999f79ee (diff)
[Oxfordshire] use localtime in open311 get update call
As Oxfordshire uses local time and not UTC use that when calling the get update script. Also handle a date with a timezone being passed on the server side. And add some tests in for the oxfordshire open311 endpoint Fixes mysociety/fixmystreet-commercial#1062
-rw-r--r--perllib/Open311/GetServiceRequestUpdates.pm2
-rw-r--r--t/open311/oxfordshire/open311_services.t37
2 files changed, 39 insertions, 0 deletions
diff --git a/perllib/Open311/GetServiceRequestUpdates.pm b/perllib/Open311/GetServiceRequestUpdates.pm
index b4d7c6347..7cbfc7192 100644
--- a/perllib/Open311/GetServiceRequestUpdates.pm
+++ b/perllib/Open311/GetServiceRequestUpdates.pm
@@ -69,6 +69,8 @@ sub update_comments {
# default to asking for last 2 hours worth if not Bromley
} elsif ( ! $body->areas->{$AREA_ID_BROMLEY} ) {
my $end_dt = DateTime->now();
+ # Oxfordshire uses local time and not UTC for dates
+ FixMyStreet->set_time_zone($end_dt) if ( $body->areas->{$AREA_ID_OXFORDSHIRE} );
my $start_dt = $end_dt->clone;
$start_dt->add( hours => -2 );
diff --git a/t/open311/oxfordshire/open311_services.t b/t/open311/oxfordshire/open311_services.t
new file mode 100644
index 000000000..c12ce9f43
--- /dev/null
+++ b/t/open311/oxfordshire/open311_services.t
@@ -0,0 +1,37 @@
+use FixMyStreet::Test;
+use POSIX qw(tzset);
+
+my $d;
+
+BEGIN {
+ use File::Basename qw(dirname);
+ use File::Spec;
+ $d = dirname(File::Spec->rel2abs(__FILE__));
+}
+
+use lib "$d/../../../bin/oxfordshire";
+
+use_ok 'open311_services';
+
+my $old_tz = $ENV{TZ};
+$ENV{TZ} = 'Europe/London';
+tzset;
+
+is get_utc_iso8601_string('2018-06-01 13:37:42'), '2018-06-01T12:37:42Z', 'convert local to iso UTC';
+
+is get_date_or_nothing('2018-06-01T12:37:42Z'), '2018-06-01 12:37:42', 'convert date format';
+is get_date_or_nothing('2018-06-01T12:37Z'), '2018-06-01 12:37:00', 'convert date format add seconds';
+is get_date_or_nothing('2018-06-01T12:37:42Z', 1), '2018-06-01', 'convert date format and ignore time';
+is get_date_or_nothing('2018/06/01 12:37:42'), '', 'convert date returns nothing if no match';
+
+is get_date_or_nothing('2018-06-07T12:35:08+01:00'), '2018-06-07 12:35:08', 'convert date format with TZ';
+
+$ENV{TZ} = 'Europe/Rome';
+tzset;
+
+is get_utc_iso8601_string('2018-06-01 14:37:42'), '2018-06-01T12:37:42Z', 'convert local to iso UTC alt TZ';
+
+$ENV{TZ} = $old_tz;
+tzset;
+
+done_testing();