diff options
author | Byron Jones <bjones@mozilla.com> | 2013-07-24 10:19:49 +0200 |
---|---|---|
committer | Byron Jones <bjones@mozilla.com> | 2013-07-24 10:19:49 +0200 |
commit | 70d8b6fac44065dc879374779f96abb0c488085d (patch) | |
tree | 0735771721ea4da112d1a61d1183453b87cbec4c | |
parent | e5ebce2b90812b88e5f3c8a5b7b7249ac70df9e7 (diff) | |
download | bugzilla-70d8b6fac44065dc879374779f96abb0c488085d.tar.gz bugzilla-70d8b6fac44065dc879374779f96abb0c488085d.tar.xz |
Bug 533878: Allow relative date searches involving date/time custom fields
-rw-r--r-- | Bugzilla/Search.pm | 50 |
1 files changed, 34 insertions, 16 deletions
diff --git a/Bugzilla/Search.pm b/Bugzilla/Search.pm index 46a3cb057..5db8ad3d7 100644 --- a/Bugzilla/Search.pm +++ b/Bugzilla/Search.pm @@ -355,18 +355,29 @@ use constant OPERATOR_FIELD_OVERRIDE => { # These are fields where special action is taken depending on the # *value* passed in to the chart, sometimes. -use constant SPECIAL_PARSING => { - # Pronoun Fields (Ones that can accept %user%, etc.) - assigned_to => \&_contact_pronoun, - cc => \&_cc_pronoun, - commenter => \&_commenter_pronoun, - qa_contact => \&_contact_pronoun, - reporter => \&_contact_pronoun, - - # Date Fields that accept the 1d, 1w, 1m, 1y, etc. format. - creation_ts => \&_timestamp_translate, - deadline => \&_timestamp_translate, - delta_ts => \&_timestamp_translate, +# This is a sub because custom fields are dynamic +sub SPECIAL_PARSING { + my $map = { + # Pronoun Fields (Ones that can accept %user%, etc.) + assigned_to => \&_contact_pronoun, + cc => \&_cc_pronoun, + commenter => \&_commenter_pronoun, + qa_contact => \&_contact_pronoun, + reporter => \&_contact_pronoun, + + # Date Fields that accept the 1d, 1w, 1m, 1y, etc. format. + creation_ts => \&_datetime_translate, + deadline => \&_date_translate, + delta_ts => \&_datetime_translate, + }; + foreach my $field (Bugzilla->active_custom_fields) { + if ($field->type == FIELD_TYPE_DATETIME) { + $map->{$field->name} = \&_datetime_translate; + } elsif ($field->type == FIELD_TYPE_DATE) { + $map->{$field->name} = \&_date_translate; + } + } + return $map; }; # Information about fields that represent "users", used by _user_nonchanged. @@ -2057,22 +2068,29 @@ sub _word_terms { ##################################### sub _timestamp_translate { - my ($self, $args) = @_; + my ($self, $ignore_time, $args) = @_; my $value = $args->{value}; my $dbh = Bugzilla->dbh; return if $value !~ /^(?:[\+\-]?\d+[hdwmy]s?|now)$/i; - # By default, the time is appended to the date, which we don't want - # for deadlines. $value = SqlifyDate($value); - if ($args->{field} eq 'deadline') { + # By default, the time is appended to the date, which we don't always want. + if ($ignore_time) { ($value) = split(/\s/, $value); } $args->{value} = $value; $args->{quoted} = $dbh->quote($value); } +sub _datetime_translate { + return shift->_timestamp_translate(0, @_); +} + +sub _date_translate { + return shift->_timestamp_translate(1, @_); +} + sub SqlifyDate { my ($str) = @_; my $fmt = "%Y-%m-%d %H:%M:%S"; |