=back
-=head2 search_timestamp_translate
+=head2 search_date_pronoun
-This happens in L<Bugzilla::Search/_timestamp_translate> and allows you to
-support pronouns for specific dates, such as a product release date. Check the
-`value` argument and replace it with actual date where needed.
+This happens in L<Bugzilla::Search/SqlifyDate> and allows you to support
+pronouns for specific dates, such as a product release date. Pronouns must be
+quoted with percent signs like C<%LAST_RELEASE_DATE%>.
Params:
=over
-=item C<search> - The L<Bugzilla::Search> object.
-
-=item C<args> - The original arguments including C<value>.
+=item C<pronoun> - A capitalized pronoun without percent signs can be found in
+the C<name>. Add an actual date back to the C<date> if it's a supported pronoun.
=back
my $value = $args->{value};
my $dbh = Bugzilla->dbh;
- # Allow to support custom date pronouns
- Bugzilla::Hook::process('search_timestamp_translate',
- {search => $self, args => $args});
-
- return if $value !~ /^(?:[\+\-]?\d+[hdwmy]s?|now)$/i;
+ return if $value !~ /^(?:[\+\-]?\d+[hdwmy]s?|now)$/i && $value !~ /^%\w+%$/;
$value = SqlifyDate($value);
return sprintf("%4d-%02d-%02d 00:00:00", $year + 1900, $month + 1, $mday);
}
+ # Allow to support custom date pronouns
+ if ($str =~ /^%(\w+)%$/) {
+ my $pronoun = {name => uc($1)};
+ Bugzilla::Hook::process('search_date_pronoun', {pronoun => $pronoun});
+ unless ($pronoun->{date}) {
+ ThrowUserError('illegal_date_pronoun', {pronoun => $str});
+ }
+ return $pronoun->{date};
+ }
+
if ($str =~ /^(-|\+)?(\d+)([hdwmy])(s?)$/i) { # relative date
my ($sign, $amount, $unit, $startof, $date) = ($1, $2, lc $3, lc $4, time);
my ($sec, $min, $hour, $mday, $month, $year, $wday) = localtime($date);
number_too_large => 54,
number_too_small => 55,
illegal_date => 56,
+ illegal_date_pronoun => 57,
# Bug errors usually occupy the 100-200 range.
improper_bug_id_field_value => 100,
# Allow to use Firefox release date pronouns, including `%LAST_MERGE_DATE%`,
# `%LAST_RELEASE_DATE%` and `%LAST_SOFTFREEZE_DATE%`.
-sub search_timestamp_translate {
+sub search_date_pronoun {
my ($self, $args) = @_;
- $args = $args->{args};
- my $key = uc($args->{value});
- $key =~ s/^%([A-Z_]+)%$/$1/;
+ my $pronoun = $args->{pronoun};
+ my $key = $pronoun->{name};
my $keys = ['LAST_MERGE_DATE', 'LAST_RELEASE_DATE', 'LAST_SOFTFREEZE_DATE'];
return unless grep(/^$key$/, @$keys);
my $date = _fetch_product_version_file('firefox')->{$key};
ThrowUserError('product_date_pronouns_unavailable') unless $date;
- $args->{value} = $date;
- $args->{quoted} = Bugzilla->dbh->quote($date);
+ $pronoun->{date} = $date;
}
sub tf_buglist_columns {
Please use the format '<tt>[% format FILTER html %]</tt>'.
[% END %]
+ [% ELSIF error == "illegal_date_pronoun" %]
+ [% title = "Illegal Date Pronoun" %]
+ '<code>[% pronoun FILTER html %]</code>' is not a legal date pronoun.
+
[% ELSIF error == "illegal_email_address" %]
[% title = "Invalid Email Address" %]
The e-mail address you entered (<b>[% addr FILTER html %]</b>)