This is an automated email from the ASF dual-hosted git repository.

jinsongzhou pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/amoro.git


The following commit(s) were added to refs/heads/master by this push:
     new 2d212beb2  [AMORO-3287][amoro-web]format cost time  keeping a maximum 
of 2 time units (#3376)
2d212beb2 is described below

commit 2d212beb2ccd08ac0061f37cbd927e3bf046f0c6
Author: sunshine <13574...@qq.com>
AuthorDate: Mon Dec 23 11:40:34 2024 +0800

     [AMORO-3287][amoro-web]format cost time  keeping a maximum of 2 time units 
(#3376)
    
    * add be codes
    
    * add be codes
    
    * add be codes
    
    * revert
---
 amoro-web/src/utils/index.ts | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/amoro-web/src/utils/index.ts b/amoro-web/src/utils/index.ts
index 8d852e083..3b89598a7 100644
--- a/amoro-web/src/utils/index.ts
+++ b/amoro-web/src/utils/index.ts
@@ -81,9 +81,19 @@ export function formatMS2Time(ms: number): string {
     { value: seconds, unit: 's' },
   ]
 
-  return times.reduce((pre: string, cur: { value: number, unit: string }) => {
-    return cur.value > 0 ? `${pre}${cur.value} ${cur.unit} ` : pre
-  }, '')
+  let result = ''
+  let count = 0
+
+  // Only add at most two non-zero time units to the result
+  for (const time of times) {
+    if (time.value > 0 && count < 2) {
+      result += `${time.value}${time.unit} `
+      count++
+    }
+  }
+
+  // Trim any trailing spaces and return the formatted result
+  return result.trim()
 }
 /**
  * Convert milliseconds to d h min s format

Reply via email to