diff options
author | Dave Lawrence <dlawrence@mozilla.com> | 2014-03-05 00:12:58 +0100 |
---|---|---|
committer | Dave Lawrence <dlawrence@mozilla.com> | 2014-03-05 00:12:58 +0100 |
commit | 5d54de990280d2b3536b0737dc262329d243d543 (patch) | |
tree | 5ede7aa00bc1ed391be61f71c9e5a5c019a855e4 /extensions/MyDashboard | |
parent | faf2fc5dbead69f0de0df51af85561f1203dee45 (diff) | |
download | bugzilla-5d54de990280d2b3536b0737dc262329d243d543.tar.gz bugzilla-5d54de990280d2b3536b0737dc262329d243d543.tar.xz |
Bug 979092 - changing timezone breaks MyDashboard
Diffstat (limited to 'extensions/MyDashboard')
-rw-r--r-- | extensions/MyDashboard/lib/Queries.pm | 36 | ||||
-rw-r--r-- | extensions/MyDashboard/lib/WebService.pm | 19 |
2 files changed, 31 insertions, 24 deletions
diff --git a/extensions/MyDashboard/lib/Queries.pm b/extensions/MyDashboard/lib/Queries.pm index 435aa7ef4..566b5b340 100644 --- a/extensions/MyDashboard/lib/Queries.pm +++ b/extensions/MyDashboard/lib/Queries.pm @@ -131,10 +131,10 @@ sub QUERY_DEFS { } sub query_bugs { - my $qdef = shift; - my $dbh = Bugzilla->dbh; - my $user = Bugzilla->user; - my $date_now = DateTime->now(time_zone => $user->timezone); + my $qdef = shift; + my $dbh = Bugzilla->dbh; + my $user = Bugzilla->user; + my $datetime_now = DateTime->now(time_zone => $user->timezone); ## HACK to remove POST delete $ENV{REQUEST_METHOD}; @@ -152,9 +152,16 @@ sub query_bugs { foreach my $column (SELECT_COLUMNS) { $bug->{$column} = shift @$row; if ($column eq 'changeddate') { - $bug->{$column} = format_time($bug->{$column}); - my $date_then = datetime_from($bug->{$column}); - $bug->{'changeddate_fancy'} = time_ago($date_then, $date_now); + my $datetime = datetime_from($bug->{$column}); + $datetime->set_time_zone($user->timezone); + $bug->{$column} = $datetime->strftime('%Y-%m-%d %T %Z'); + $bug->{'changeddate_fancy'} = time_ago($datetime, $datetime_now); + + # Provide a version for use by Bug.history and also for looking up last comment. + # We have to set to server's timezone and also subtract one second. + $datetime->set_time_zone(Bugzilla->local_timezone); + $datetime->subtract(seconds => 1); + $bug->{changeddate_api} = $datetime->strftime('%Y-%m-%d %T'); } } push(@bugs, $bug); @@ -165,9 +172,9 @@ sub query_bugs { sub query_flags { my ($type) = @_; - my $user = Bugzilla->user; - my $dbh = Bugzilla->dbh; - my $date_now = DateTime->now(time_zone => $user->timezone); + my $user = Bugzilla->user; + my $dbh = Bugzilla->dbh; + my $datetime_now = DateTime->now(time_zone => $user->timezone); ($type ne 'requestee' || $type ne 'requester') || ThrowCodeError('param_required', { param => 'type' }); @@ -238,10 +245,11 @@ sub query_flags { # Format the updated date specific to the user's timezone # and add the fancy human readable version - $flag->{'updated'} = format_time($flag->{'updated'}); - my $date_then = datetime_from($flag->{'updated'}); - $flag->{'updated_epoch'} = $date_then->epoch; - $flag->{'updated_fancy'} = time_ago($date_then, $date_now); + my $datetime = datetime_from($flag->{'updated'}); + $datetime->set_time_zone($user->timezone); + $flag->{'updated'} = $datetime->strftime('%Y-%m-%d %T %Z'); + $flag->{'updated_epoch'} = $datetime->epoch; + $flag->{'updated_fancy'} = time_ago($datetime, $datetime_now); push(@filtered_flags, $flag); } diff --git a/extensions/MyDashboard/lib/WebService.pm b/extensions/MyDashboard/lib/WebService.pm index 806976372..c98525429 100644 --- a/extensions/MyDashboard/lib/WebService.pm +++ b/extensions/MyDashboard/lib/WebService.pm @@ -45,17 +45,14 @@ sub run_bug_query { if (!$user->is_insider) { $last_comment_sql .= " AND isprivate = 0"; } + $last_comment_sql .= " LIMIT 1"; my $last_comment_sth = $dbh->prepare($last_comment_sql); # Add last changes to each bug foreach my $b (@$bugs) { my $last_changes = {}; - # Remove one second so we get the changes made at $change_date (>=) - my $changed_date = datetime_from($b->{changeddate}); - next if !$changed_date; - $changed_date->subtract(seconds => 1); my $activity = $self->history({ ids => [ $b->{bug_id} ], - new_since => $changed_date }); + new_since => $b->{changeddate_api} }); if (@{$activity->{bugs}[0]{history}}) { my $change_set = $activity->{bugs}[0]{history}[0]; $last_changes->{activity} = $change_set->{changes}; @@ -64,18 +61,20 @@ sub run_bug_query { = template_var('field_descs')->{$change->{field_name}} || $change->{field_name}; } $last_changes->{email} = $change_set->{who}; - $last_changes->{when} = $self->datetime_format_inbound($change_set->{when}); + my $datetime = datetime_from($change_set->{when}); + $datetime->set_time_zone($user->timezone); + $last_changes->{when} = $datetime->strftime('%Y-%m-%d %T %Z'); } my $last_comment_id = $dbh->selectrow_array( - $last_comment_sth, - undef, $b->{bug_id}, $changed_date); + $last_comment_sth, undef, $b->{bug_id}, $b->{changeddate_api}); if ($last_comment_id) { my $comments = $self->comments({ comment_ids => [ $last_comment_id ] }); my $comment = $comments->{comments}{$last_comment_id}; $last_changes->{comment} = $comment->{text}; $last_changes->{email} = $comment->{creator} if !$last_changes->{email}; - $last_changes->{when} - = $self->datetime_format_inbound($comment->{creation_time}) if !$last_changes->{when}; + my $datetime = datetime_from($comment->{creation_time}); + $datetime->set_time_zone($user->timezone); + $last_changes->{when} = $datetime->strftime('%Y-%m-%d %T %Z'); } $b->{last_changes} = $last_changes; |