Fixed duration formatter to properly count lengths longer than 24 hours (#612)

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

* formatted DurationField.js with npm prettier
This commit is contained in:
JorisL 2020-11-05 20:02:09 +01:00 committed by GitHub
parent fb1461fd0b
commit 0b977df8dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 4 deletions

View File

@ -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 = {