Skip to contentSkip to conversation

fix indentation problem and simplify a function

PATCH New Victor Huesca 2 participants 4 messages Aug 12, 2019

lore
Share & tools
lore
#0 lore raw

cover fix indentation problem and simplify a function

Commit changes are self-explains.

Victor Huesca (2):
web/funcs.inc.php: fix 'bab_format_sql_filter' indentation web/index.php: reword the 'format_duration' function

 web/funcs.inc.php | 42 +++++++++++++++++++++---------------------
 web/index.php     | 22 ++--------------------
 2 files changed, 23 insertions(+), 41 deletions(-)
Signature · 1 line
2.21.0
#1 lore raw

PATCH 1/2 web/funcs.inc.php: fix 'bab_format_sql_filter' indentation

The 'bab_format_sql_filter' function uses tabs indentation whereas the overall file uses two spaces. This patch simply replace those tabs by spaces for consistency.

---
 web/funcs.inc.php | 42 +++++++++++++++++++++---------------------
 1 file changed, 21 insertions(+), 21 deletions(-)
web/funcs.inc.php +21 -21
index 7e912c1..9582e50 100644
@@ -32,29 +32,29 @@ function bab_footer()
 
 function bab_format_sql_filter($db, $filters)
 {
-	$status_map = array(
-		"OK" => 0,
-		"NOK" => 1,
-		"TIMEOUT" => 2,
-	);
+  $status_map = array(
+    "OK" => 0,
+    "NOK" => 1,
+    "TIMEOUT" => 2,
+  );
 
-	$sql_filters = implode(' and ', array_map(
-		function ($v, $k) use ($db, $status_map) {
-			if ($k == "reason")
-				return sprintf("%s like %s", $k, $db->quote_smart($v));
-			else if ($k == "status")
-				return sprintf("%s=%s", $k, $db->quote_smart($status_map[$v]));
-			else
-				return sprintf("%s=%s", $k, $db->quote_smart($v));
-		},
-		$filters,
-		array_keys($filters)
-	));
+  $sql_filters = implode(' and ', array_map(
+    function ($v, $k) use ($db, $status_map) {
+      if ($k == "reason")
+        return sprintf("%s like %s", $k, $db->quote_smart($v));
+      else if ($k == "status")
+        return sprintf("%s=%s", $k, $db->quote_smart($status_map[$v]));
+      else
+        return sprintf("%s=%s", $k, $db->quote_smart($v));
+    },
+    $filters,
+    array_keys($filters)
+  ));
 
-	if (count($filters))
-		return "where " . $sql_filters;
-	else
-		return "";
+  if (count($filters))
+    return "where " . $sql_filters;
+  else
+    return "";
 }
 
 /*
Signature · 1 line
2.21.0
#2 lore raw

PATCH 2/2 web/index.php: reword the 'format_duration' function

In reply to Victor Huesca

The format_duration manually compute everything when it could just use the build-in date format function and trim the beginning for the same result.

---
 web/index.php | 22 ++--------------------
 1 file changed, 2 insertions(+), 20 deletions(-)
web/index.php +2 -20
index f3af62d..939cac5 100644
@@ -1,26 +1,8 @@
 <?php
 include("funcs.inc.php");
 
-function format_duration($seconds_count)
-{
-        $delimiter  = ':';
-        $seconds = $seconds_count % 60;
-        $minutes = floor($seconds_count/60) % 60;
-        $hours   = floor($seconds_count/3600);
-
-        $seconds = str_pad($seconds, 2, "0", STR_PAD_LEFT);
-        $minutes = str_pad($minutes, 2, "0", STR_PAD_LEFT).$delimiter;
-
-        if($hours > 0)
-        {
-		$hours = str_pad($hours, 2, "0", STR_PAD_LEFT).$delimiter;
-        }
-        else
-        {
-		$hours = '';
-        }
-
-        return "$hours$minutes$seconds";
+function format_duration($seconds_count) {
+  return ltrim(gmdate('H:i:s', $seconds_count), '0:');
 }
 
 function format_url_args($args)
Signature · 1 line
2.21.0
#3 lore raw

cover fix indentation problem and simplify a function

In reply to Victor Huesca
Quoted 3 lines · On Mon, 12 Aug 2019 16:43:43 +0200 Victor Huesca <[email protected]>…

Victor Huesca (2):
web/funcs.inc.php: fix 'bab_format_sql_filter' indentation web/index.php: reword the 'format_duration' function

Both applied to buildroot-test. Thanks!

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com