summaryrefslogtreecommitdiffstats
path: root/buglist.cgi
diff options
context:
space:
mode:
authorjouni%heikniemi.net <>2002-07-09 19:58:10 +0200
committerjouni%heikniemi.net <>2002-07-09 19:58:10 +0200
commit75082eeb8e619fdd839593f1e74053ccd7d58137 (patch)
tree23d4d7b30c5135e641f4dfacff271f0878684f79 /buglist.cgi
parent336bf13a0a34b33f4977770128bdea4da81fa486 (diff)
downloadbugzilla-75082eeb8e619fdd839593f1e74053ccd7d58137.tar.gz
bugzilla-75082eeb8e619fdd839593f1e74053ccd7d58137.tar.xz
Bug 149246: Allow use of relative time units in query screen.
Patch by Michael Schindler <michael@compressconsult.com>, 2xr=jouni
Diffstat (limited to 'buglist.cgi')
-rwxr-xr-xbuglist.cgi22
1 files changed, 22 insertions, 0 deletions
diff --git a/buglist.cgi b/buglist.cgi
index 9638d9c0f..46c26fd16 100755
--- a/buglist.cgi
+++ b/buglist.cgi
@@ -23,6 +23,7 @@
# Stephan Niemz <st.n@gmx.net>
# Andreas Franke <afranke@mathweb.org>
# Myk Melez <myk@mozilla.org>
+# Michael Schindler <michael@compressconsult.com>
################################################################################
# Script Initialization
@@ -158,6 +159,27 @@ if ($::FORM{'cmdtype'} eq 'runnamed') {
sub SqlifyDate {
my ($str) = @_;
$str = "" if !defined $str;
+ if ($str =~ /^-?(\d+)([dDwWmMyY])$/) { # relative date
+ my ($amount, $unit, $date) = ($1, lc $2, time);
+ my ($sec, $min, $hour, $mday, $month, $year, $wday) = localtime($date);
+ if ($unit eq 'w') { # convert weeks to days
+ $amount = 7*$amount + $wday;
+ $unit = 'd';
+ }
+ if ($unit eq 'd') {
+ $date -= $sec + 60*$min + 3600*$hour + 24*3600*$amount;
+ return time2str("%Y-%m-%d %H:%M:%S", $date);
+ }
+ elsif ($unit eq 'y') {
+ return sprintf("%4d-01-01 00:00:00", $year+1900-$amount);
+ }
+ elsif ($unit eq 'm') {
+ $month -= $amount;
+ while ($month<0) { $year--; $month += 12; }
+ return sprintf("%4d-%02d-01 00:00:00", $year+1900, $month+1);
+ }
+ return undef; # should not happen due to regexp at top
+ }
my $date = str2time($str);
if (!defined($date)) {
my $htmlstr = html_quote($str);