Skip to content

Commit

Permalink
Fixed duration formatter to properly count lengths longer than 24 hou…
Browse files Browse the repository at this point in the history
…rs (#612)

* Fixed durationfield formatter to properly count lengths longer than
24 hours.

* formatted DurationField.js with npm prettier
  • Loading branch information
JorisL committed Nov 5, 2020
1 parent fb1461f commit 0b977df
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions ui/src/common/DurationField.js
Expand Up @@ -11,10 +11,13 @@ const DurationField = ({ record = {}, source }) => {
}

const format = (d) => {
const date = new Date(null)
date.setSeconds(d)
const fmt = date.toISOString().substr(11, 8)
return fmt.replace(/^00:/, '')
const hours = Math.floor(d / 3600)
const minutes = Math.floor(d / 60) % 60
const seconds = d % 60
return [hours, minutes, seconds]
.map((v) => (v < 10 ? '0' + v : v))
.filter((v, i) => v !== '00' || i > 0)
.join(':')
}

DurationField.propTypes = {
Expand Down

0 comments on commit 0b977df

Please sign in to comment.