[projects/buildlogs] Nicer age and '-' in failed rpm section.

arekm arekm at pld-linux.org
Tue Apr 21 00:26:11 CEST 2026


commit d5598f48bcb2bfe8a5ca668d6baadc76beb5fd7a
Author: Arkadiusz Miśkiewicz <arekm at maven.pl>
Date:   Tue Apr 21 00:06:18 2026 +0200

    Nicer age and '-' in failed rpm section.

 index.php | 75 ++++++++-------------------------------------------------------
 lib.php   | 12 ++++++++++
 2 files changed, 21 insertions(+), 66 deletions(-)
---
diff --git a/index.php b/index.php
index 8523a21..5008436 100644
--- a/index.php
+++ b/index.php
@@ -501,30 +501,10 @@ function list_logs()
 		$f = $name;
 		$name_url = urlencode($name);
 		$mtime = (int)$row["mtime"];
-		$t = $now - $mtime;
+		$t = format_age($now - $mtime);
 		$date_str = date("Y/m/d H:i:s", $mtime);
 		$s = $row["size"];
 		$h = $row["log_id"];
-
-		if ($t < 0) {
-			$t = _("in future");
-		} else {
-			$t /= 60;
-			if ($t >= 60) {
-				$t /= 60;
-				if ($t >= 24) {
-					$t /= 24;
-					$t = (int)round($t);
-					$t = $t . " " . ngettext("day","days",$t);
-				} else {
-					$t = (int)round($t);
-					$t = $t . " " . ngettext("hour","hours",$t);
-				}
-			} else {
-				$t = (int)round($t);
-				$t = $t . " " . ngettext("minute","minutes",$t);
-			}
-		}
 		$url_data = array(
 			'dist' => $dist,
 			'arch' => $arch,
@@ -544,8 +524,8 @@ function list_logs()
 			echo "<td bgcolor=\"#CCCCCC\" align=\"center\" valign=\"middle\" nowrap=\"nowrap\">".h($row["arch"])."</td>";
 		}
 		$rt = format_runtime($row["runtime"] ?? null);
-		$section = ($row_ok == 0 && !empty($row["build_rpm_section"]))
-			? "<code>".h($row["build_rpm_section"])."</code>" : "";
+		$section = !empty($row["build_rpm_section"])
+			? "<code>".h($row["build_rpm_section"])."</code>" : "-";
 		echo "<td bgcolor=\"#CCCCCC\" valign=\"middle\"><a href=\"$u\">" . h($f) . "</a> ".
 		     "[<a href=\"$u&action=text\">"._("text")."</a> | ".
 		      "<a href=\"$u&action=tail\">"._("tail")."</a>]".
@@ -736,26 +716,7 @@ function list_package_history($pkg_name, $cur_dist, $cur_arch, $cur_ok, $cur_id)
 		$r_ok   = (int)$row["ok"];
 		$r_size = (int)$row["size"];
 		$r_mtime = (int)$row["mtime"];
-
-		if (($now - $r_mtime) < 0) {
-			$t_str = _("in future");
-		} else {
-			$t = ($now - $r_mtime) / 60;
-			if ($t >= 60) {
-				$t /= 60;
-				if ($t >= 24) {
-					$t /= 24;
-					$t = (int)round($t);
-					$t_str = $t . " " . ngettext("day","days",$t);
-				} else {
-					$t = (int)round($t);
-					$t_str = $t . " " . ngettext("hour","hours",$t);
-				}
-			} else {
-				$t = (int)round($t);
-				$t_str = $t . " " . ngettext("minute","minutes",$t);
-			}
-		}
+		$t_str = format_age($now - $r_mtime);
 		$date_str = date("Y/m/d H:i:s", $r_mtime);
 
 		$u = h($url . '?' . http_build_query([
@@ -770,8 +731,8 @@ function list_package_history($pkg_name, $cur_dist, $cur_arch, $cur_ok, $cur_id)
 			: "<font color=\"red\"><b>"._("FAIL")."</b></font>";
 
 		$rt = format_runtime($row["runtime"] ?? null);
-		$section = ($r_ok == 0 && !empty($row["build_rpm_section"]))
-			? "<code>".h($row["build_rpm_section"])."</code>" : "";
+		$section = !empty($row["build_rpm_section"])
+			? "<code>".h($row["build_rpm_section"])."</code>" : "-";
 		echo "<tr>".
 		     $first_cell.
 		     "<td bgcolor=\"#CCCCCC\" align=\"center\" valign=\"middle\">$status</td>".
@@ -1557,25 +1518,7 @@ function adv_search()
 		$r_ok   = (int)$row["ok"];
 		$r_size = (int)$row["size"];
 		$r_mtime = (int)$row["mtime"];
-
-		if (($now - $r_mtime) < 0) {
-			$t_str = _("in future");
-		} else {
-			$t = ($now - $r_mtime) / 60;
-			if ($t >= 60) {
-				$t /= 60;
-				if ($t >= 24) {
-					$t /= 24; $t = (int)round($t);
-					$t_str = $t . " " . ngettext("day","days",$t);
-				} else {
-					$t = (int)round($t);
-					$t_str = $t . " " . ngettext("hour","hours",$t);
-				}
-			} else {
-				$t = (int)round($t);
-				$t_str = $t . " " . ngettext("minute","minutes",$t);
-			}
-		}
+		$t_str = format_age($now - $r_mtime);
 		$date_str = date("Y/m/d H:i:s", $r_mtime);
 
 		$u = h($url . '?' . http_build_query([
@@ -1593,8 +1536,8 @@ function adv_search()
 		echo "<td bgcolor=\"#CCCCCC\" valign=\"middle\"><a href=\"$u\">".h($r_name)."</a> ".
 			"[<a href=\"$u&action=text\">"._("text")."</a> | ".
 			"<a href=\"$u&action=tail\">"._("tail")."</a>]</td>";
-		$section = ($r_ok == 0 && !empty($row["build_rpm_section"]))
-			? "<code>".h($row["build_rpm_section"])."</code>" : "";
+		$section = !empty($row["build_rpm_section"])
+			? "<code>".h($row["build_rpm_section"])."</code>" : "-";
 		echo "<td bgcolor=\"#CCCCCC\" align=\"center\" valign=\"middle\" nowrap=\"nowrap\">$section</td>";
 		echo "<td bgcolor=\"#CCCCCC\" align=\"center\" valign=\"middle\" nowrap=\"nowrap\">".format_runtime($row["runtime"] ?? null)."</td>";
 		echo "<td bgcolor=\"#CCCCCC\" align=\"center\" valign=\"middle\">".h((string)$r_size)."</td>";
diff --git a/lib.php b/lib.php
index 8a27b92..fc9c954 100644
--- a/lib.php
+++ b/lib.php
@@ -34,3 +34,15 @@ function close_log_stream(array $h): void {
     fclose($h['fd']);
     proc_close($h['proc']);
 }
+
+function format_age(int $seconds): string {
+    if ($seconds < 0)   return _("in future");
+    if ($seconds < 60)  return $seconds . "s";
+    $m = intdiv($seconds, 60);
+    if ($m < 60)        return $m . "m";
+    $h = intdiv($m, 60); $m %= 60;
+    if ($h < 24)        return $m ? $h . "h " . $m . "m" : $h . "h";
+    $d = intdiv($h, 24); $h %= 24;
+    if ($d < 30)        return $h ? $d . "d " . $h . "h" : $d . "d";
+    return $d . "d";
+}
================================================================

---- gitweb:

http://git.pld-linux.org/gitweb.cgi/projects/buildlogs.git/commitdiff/fe8b28769062ee67003b5958b532da86655f181e



More information about the pld-cvs-commit mailing list