Skip to content

Commit

Permalink
[AMORO-3287][amoro-web]format cost time keeping a maximum of 2 time …
Browse files Browse the repository at this point in the history
…units (#3376)

* add be codes

* add be codes

* add be codes

* revert
  • Loading branch information
ihadoop authored Dec 23, 2024
1 parent cf95293 commit 2d212be
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions amoro-web/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2d212be

Please sign in to comment.