summaryrefslogtreecommitdiffstats
path: root/extensions/BugModal/lib
diff options
context:
space:
mode:
authorByron Jones <glob@mozilla.com>2015-04-14 07:20:00 +0200
committerByron Jones <glob@mozilla.com>2015-04-14 07:20:00 +0200
commite5131c86c22c5577c0e27db04481084caf635dc5 (patch)
tree897a6ef2d1314a1c442e9e8b8ff14a4dd2cf3eb2 /extensions/BugModal/lib
parent6116f2f7cf32f40c1f943cef3f523ed5955f968d (diff)
downloadbugzilla-e5131c86c22c5577c0e27db04481084caf635dc5.tar.gz
bugzilla-e5131c86c22c5577c0e27db04481084caf635dc5.tar.xz
Bug 1146767: update relative dates without refreshing the page
Diffstat (limited to 'extensions/BugModal/lib')
-rw-r--r--extensions/BugModal/lib/ActivityStream.pm15
-rw-r--r--extensions/BugModal/lib/Util.pm31
2 files changed, 35 insertions, 11 deletions
diff --git a/extensions/BugModal/lib/ActivityStream.pm b/extensions/BugModal/lib/ActivityStream.pm
index dae6b8ba2..97edf2ee6 100644
--- a/extensions/BugModal/lib/ActivityStream.pm
+++ b/extensions/BugModal/lib/ActivityStream.pm
@@ -12,9 +12,9 @@ package Bugzilla::Bug;
use strict;
use warnings;
+use Bugzilla::Extension::BugModal::Util qw(date_str_to_time);
use Bugzilla::User;
use Bugzilla::Constants;
-use Time::Local;
# returns an arrayref containing all changes to the bug - comments, field
# changes, and duplicates
@@ -51,7 +51,7 @@ sub activity_stream {
_add_activities_to_stream($self, $stream);
_add_duplicates_to_stream($self, $stream);
- my $base_time = _sql_date_to_time($self->creation_ts);
+ my $base_time = date_str_to_time($self->creation_ts);
foreach my $change_set (@$stream) {
$change_set->{id} = $change_set->{comment}
? 'c' . $change_set->{comment}->count
@@ -101,7 +101,7 @@ sub _add_comments_to_stream {
next if $comment->type == CMT_HAS_DUPE;
next if $comment->is_private && !($user->is_insider || $user->id == $comment->author->id);
next if $comment->body eq '' && ($comment->work_time - 0) != 0 && !$user->is_timetracker;
- _add_comment_to_stream($stream, _sql_date_to_time($comment->creation_ts), $comment->author->id, $comment);
+ _add_comment_to_stream($stream, date_str_to_time($comment->creation_ts), $comment->author->id, $comment);
}
}
@@ -237,7 +237,7 @@ sub _add_activities_to_stream {
}
}
- _add_activity_to_stream($stream, _sql_date_to_time($operation->{when}), $operation->{who}->id, $operation);
+ _add_activity_to_stream($stream, date_str_to_time($operation->{when}), $operation->{who}->id, $operation);
}
# prime the visible-bugs cache
@@ -274,11 +274,4 @@ sub _add_duplicates_to_stream {
}
}
-sub _sql_date_to_time {
- my ($date) = @_;
- $date =~ /^(\d{4})[\.\-](\d{2})[\.\-](\d{2}) (\d{2}):(\d{2}):(\d{2})$/
- or die "internal error: invalid date '$date'";
- return timelocal($6, $5, $4, $3, $2 - 1, $1 - 1900);
-}
-
1;
diff --git a/extensions/BugModal/lib/Util.pm b/extensions/BugModal/lib/Util.pm
new file mode 100644
index 000000000..daca86518
--- /dev/null
+++ b/extensions/BugModal/lib/Util.pm
@@ -0,0 +1,31 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+# This Source Code Form is "Incompatible With Secondary Licenses", as
+# defined by the Mozilla Public License, v. 2.0.
+
+package Bugzilla::Extension::BugModal::Util;
+use strict;
+use warnings;
+
+use base qw(Exporter);
+our @EXPORT_OK = qw(date_str_to_time);
+
+use feature 'state';
+
+use Bugzilla::Util qw(datetime_from);
+use DateTime::TimeZone;
+use Time::Local qw(timelocal);
+
+sub date_str_to_time {
+ my ($date) = @_;
+ # avoid creating a DateTime object
+ if ($date =~ /^(\d{4})[\.\-](\d{2})[\.\-](\d{2}) (\d{2}):(\d{2}):(\d{2})$/) {
+ return timelocal($6, $5, $4, $3, $2 - 1, $1 - 1900);
+ }
+ state $tz //= DateTime::TimeZone->new( name => 'local' );
+ return datetime_from($date, $tz)->epoch;
+}
+
+1;