]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 308663: Cryptic "'' is not a legal date" error from time summaries (missing start...
authorlpsolit%gmail.com <>
Sun, 12 Apr 2009 12:10:08 +0000 (12:10 +0000)
committerlpsolit%gmail.com <>
Sun, 12 Apr 2009 12:10:08 +0000 (12:10 +0000)
summarize_time.cgi

index 0330f9dcff17a590ed98800e89d23755e3c0135d..35ef5f33f10c01aa7228e080d56dafb105b99f35 100755 (executable)
@@ -232,6 +232,20 @@ sub get_inactive_bugs {
     return $bugs;
 }
 
+# Return 1st day of the month of the earliest activity date for a given list of bugs.
+sub get_earliest_activity_date {
+    my ($bugids) = @_;
+    my $dbh = Bugzilla->dbh;
+
+    my ($date) = $dbh->selectrow_array(
+        'SELECT ' . $dbh->sql_date_format('MIN(bug_when)', '%Y-%m-01')
+       . ' FROM longdescs
+          WHERE ' . $dbh->sql_in('bug_id', $bugids)
+                  . ' AND work_time > 0');
+
+    return $date;
+}
+
 #
 # Template code starts here
 #
@@ -301,16 +315,14 @@ if ($do_report) {
     # Break dates apart into months if necessary; if not, we use the
     # same @parts list to allow us to use a common codepath.
     if ($monthly) {
-        # unfortunately it's not too easy to guess a start date, since
-        # it depends on what bugs we're looking at. We risk bothering
-        # the user here. XXX: perhaps run a query to see what the
-        # earliest activity in longdescs for all bugs and use that as a
-        # start date.
-        $start_date || ThrowUserError("illegal_date", {'date' => $start_date});
-        # we can, however, provide a default end date. Note that this
-        # differs in semantics from the open-ended queries we use when
-        # start/end_date aren't provided -- and clock skews will make
-        # this evident!
+        # Calculate the earliest activity date if the user doesn't
+        # specify a start date.
+        if (!$start_date) {
+            $start_date = get_earliest_activity_date(\@bugs);
+        }
+        # Provide a default end date. Note that this differs in semantics
+        # from the open-ended queries we use when start/end_date aren't
+        # provided -- and clock skews will make this evident!
         @parts = split_by_month($start_date, 
                                 $end_date || format_time(scalar localtime(time()), '%Y-%m-%d'));
     } else {