aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/Open311/GetServiceRequestUpdates.pm
diff options
context:
space:
mode:
authorMatthew Somerville <matthew-github@dracos.co.uk>2019-04-25 17:09:31 +0100
committerMatthew Somerville <matthew-github@dracos.co.uk>2019-05-02 22:07:26 +0100
commit54cad1e4d2474fba55485731ca9e2fd1779c524a (patch)
tree0b1e765b8bac8b50953038cf6ae25b1aa312e0d1 /perllib/Open311/GetServiceRequestUpdates.pm
parent4b4da81ffec527df9741c960d79294b48bb4dcaa (diff)
Fix some incorrect timezone code.
Times in the database should be stored in the application server's local timezone, by e.g. using `current_timestamp`, or by setting that timezone explicitly before storage (the database columns are all without timezone so any timezone info is silently ignored). Reports & updates fetched via Open311 and offline updates were being put into the TIME_ZONE setting if present, meaning they were stored incorrectly for future usage.
Diffstat (limited to 'perllib/Open311/GetServiceRequestUpdates.pm')
-rw-r--r--perllib/Open311/GetServiceRequestUpdates.pm10
1 files changed, 8 insertions, 2 deletions
diff --git a/perllib/Open311/GetServiceRequestUpdates.pm b/perllib/Open311/GetServiceRequestUpdates.pm
index 263877e0a..3b436aaa7 100644
--- a/perllib/Open311/GetServiceRequestUpdates.pm
+++ b/perllib/Open311/GetServiceRequestUpdates.pm
@@ -94,7 +94,8 @@ sub update_comments {
next unless $request_id || $request->{fixmystreet_id};
my $comment_time = eval {
- DateTime::Format::W3CDTF->parse_datetime( $request->{updated_datetime} || "" );
+ DateTime::Format::W3CDTF->parse_datetime( $request->{updated_datetime} || "" )
+ ->set_time_zone(FixMyStreet->local_time_zone);
};
next if $@;
my $updated = DateTime::Format::W3CDTF->format_datetime($comment_time->clone->set_time_zone('UTC'));
@@ -190,7 +191,12 @@ sub update_comments {
$comment->state('hidden') unless $comment->text || $comment->photo
|| ($comment->problem_state && $state ne $old_state);
- $p->lastupdate( $comment->created );
+ # As comment->created has been looked at above, its time zone has been shifted
+ # to TIME_ZONE (if set). We therefore need to set it back to local before
+ # insertion. We also then need a clone, otherwise the setting of lastupdate
+ # will *also* reshift comment->created's time zone to TIME_ZONE.
+ my $created = $comment->created->set_time_zone(FixMyStreet->local_time_zone);
+ $p->lastupdate($created->clone);
$p->update;
$comment->insert();