diff options
Diffstat (limited to 'extensions/BugModal')
-rw-r--r-- | extensions/BugModal/Config.pm | 8 | ||||
-rw-r--r-- | extensions/BugModal/Extension.pm | 7 | ||||
-rw-r--r-- | extensions/BugModal/template/en/default/bug_modal/header.html.tmpl | 2 | ||||
-rw-r--r-- | extensions/BugModal/web/bug_modal.js | 11 | ||||
-rw-r--r-- | extensions/BugModal/web/time_ago.js | 142 |
5 files changed, 16 insertions, 154 deletions
diff --git a/extensions/BugModal/Config.pm b/extensions/BugModal/Config.pm index b4242753a..a60a99a7a 100644 --- a/extensions/BugModal/Config.pm +++ b/extensions/BugModal/Config.pm @@ -9,13 +9,7 @@ package Bugzilla::Extension::BugModal; use strict; use constant NAME => 'BugModal'; -use constant REQUIRED_MODULES => [ - { - package => 'Time-Duration', - module => 'Time::Duration', - version => 0 - }, -]; +use constant REQUIRED_MODULES => [ ]; use constant OPTIONAL_MODULES => [ ]; __PACKAGE__->NAME; diff --git a/extensions/BugModal/Extension.pm b/extensions/BugModal/Extension.pm index 0bc96e730..f09a53425 100644 --- a/extensions/BugModal/Extension.pm +++ b/extensions/BugModal/Extension.pm @@ -17,10 +17,9 @@ use Bugzilla::Extension::BugModal::MonkeyPatches; use Bugzilla::Extension::BugModal::Util qw(date_str_to_time); use Bugzilla::Constants; use Bugzilla::User::Setting; -use Bugzilla::Util qw(trick_taint datetime_from html_quote); +use Bugzilla::Util qw(trick_taint datetime_from html_quote time_ago); use List::MoreUtils qw(any); use Template::Stash; -use Time::Duration qw(ago); our $VERSION = '1'; @@ -55,7 +54,7 @@ sub template_after_create { my ($self, $args) = @_; my $context = $args->{template}->context; - # wrapper around Time::Duration::ago() + # wrapper around time_ago() $context->define_filter( time_duration => sub { my ($context) = @_; @@ -63,7 +62,7 @@ sub template_after_create { my ($timestamp) = @_; my $datetime = datetime_from($timestamp) // return $timestamp; - return ago(abs(time() - $datetime->epoch)); + return time_ago($datetime); }; }, 1 ); diff --git a/extensions/BugModal/template/en/default/bug_modal/header.html.tmpl b/extensions/BugModal/template/en/default/bug_modal/header.html.tmpl index 13ec7d567..13c146ed5 100644 --- a/extensions/BugModal/template/en/default/bug_modal/header.html.tmpl +++ b/extensions/BugModal/template/en/default/bug_modal/header.html.tmpl @@ -49,11 +49,11 @@ # assets javascript_urls.push( "extensions/ProdCompSearch/web/js/prod_comp_search.js", - "extensions/BugModal/web/time_ago.js", "extensions/BugModal/web/bug_modal.js", "extensions/BugModal/web/ZeroClipboard/ZeroClipboard.min.js", "js/field.js", "js/comments.js", + "js/util.js" ); jquery.push( "datetimepicker", diff --git a/extensions/BugModal/web/bug_modal.js b/extensions/BugModal/web/bug_modal.js index 66e214ad6..32949828f 100644 --- a/extensions/BugModal/web/bug_modal.js +++ b/extensions/BugModal/web/bug_modal.js @@ -8,6 +8,17 @@ $(function() { 'use strict'; + // update relative dates + window.setInterval(function() { + var now = Math.floor(new Date().getTime() / 1000); + $('.rel-time').each(function() { + $(this).text(timeAgo(now - $(this).data('time'))); + }); + $('.rel-time-title').each(function() { + $(this).attr('title', timeAgo(now - $(this).data('time'))); + }); + }, 60000); + // all keywords for autocompletion (lazy-loaded on edit) var keywords = []; diff --git a/extensions/BugModal/web/time_ago.js b/extensions/BugModal/web/time_ago.js deleted file mode 100644 index 59f12692a..000000000 --- a/extensions/BugModal/web/time_ago.js +++ /dev/null @@ -1,142 +0,0 @@ -/* - * this is a port of perl's Time::Duration module, which has the following - * license: - * - * Copyright 2006, Sean M. Burke C<sburke@cpan.org>, all rights reserved. This - * program is free software; you can redistribute it and/or modify it under the - * same terms as Perl itself. - * - * This program is distributed in the hope that it will be useful, but without - * any warranty; without even the implied warranty of merchantability or - * fitness for a particular purpose. - */ - -$(function() { - 'use strict'; - - function separate(seconds) { - // breakdown of seconds into units, starting with the most significant - - var remainder = seconds; - var tmp; - var wheel = []; - - // years - tmp = Math.floor(remainder / (365 * 24 * 60 * 60)); - wheel.push([ 'year', tmp, 1000000000 ]); - remainder -= tmp * (365 * 24 * 60 * 60); - - // days - tmp = Math.floor(remainder / (24 * 60 * 60)); - wheel.push([ 'day', tmp, 365 ]); - remainder -= tmp * (24 * 60 * 60); - - // hours - tmp = Math.floor(remainder / (60 * 60)); - wheel.push([ 'hour', tmp, 24 ]); - remainder -= tmp * (60 * 60); - - // minutes - tmp = Math.floor(remainder / 60); - wheel.push([ 'minute', tmp, 60 ]); - remainder -= tmp * 60; - - // seconds - wheel.push([ 'second', Math.floor(remainder), 60 ]); - return wheel; - } - - function approximate(precision, wheel) { - // now nudge the wheels into an acceptably (im)precise configuration - FIX: do { - // constraints for leaving this block: - // 1) number of nonzero wheels must be <= precision - // 2) no wheels can be improperly expressed (like having "60" for mins) - - var nonzero_count = 0; - var improperly_expressed = -1; - - for (var i = 0; i < wheel.length; i++) { - var tmp = wheel[i]; - if (tmp[1] == 0) { - continue; - } - ++nonzero_count; - if (i == 0) { - // the years wheel is never improper or over any limit; skip - continue; - } - - if (nonzero_count > precision) { - // this is one nonzero wheel too many - - // incr previous wheel if we're big enough - if (tmp[1] >= (tmp[tmp.length - 1] / 2)) { - ++wheel[i - 1][1]; - } - - // reset this and subsequent wheels to 0 - for (var j = i; j < wheel.length; j++) { - wheel[j][1] = 0; - } - - // start over - continue FIX; - - } else if (tmp[1] >= tmp[tmp.length - 1]) { - // it's an improperly expressed wheel (like "60" on the mins wheel) - improperly_expressed = i; - } - } - - if (improperly_expressed != -1) { - // only fix the least-significant improperly expressed wheel (at a time) - ++wheel[improperly_expressed - 1][1]; - wheel[improperly_expressed][1] = 0; - - // start over - continue FIX; - } - - // otherwise there's not too many nonzero wheels, and there's no - //improperly expressed wheels, so fall thru... - } while(0); - - return wheel; - } - - function render(wheel) { - var parts = []; - wheel.forEach(function(element, index) { - if (element[1] > 0) { - parts.push(element[1] + ' ' + element[0]); - if (element[1] != 1) { - parts[parts.length - 1] += 's'; - } - } - }); - - if (parts.length == 0) { - return "just now"; - } - parts[parts.length - 1] += ' ago'; - if (parts.length == 1) { - return parts[0]; - } - if (parts.length == 2) { - return parts[0] + ' and ' + parts[1]; - } - parts[parts.length - 1] = 'and ' + parts[parts.length - 1]; - return parts.join(', '); - } - - window.setInterval(function() { - var now = Math.floor(new Date().getTime() / 1000); - $('.rel-time').each(function() { - $(this).text(render(approximate(2, separate(now - $(this).data('time'))))); - }); - $('.rel-time-title').each(function() { - $(this).attr('title', render(approximate(2, separate(now - $(this).data('time'))))); - }); - }, 60000); -}); |