refactor: ETA calculation (#2055)

* Refactor ETA calculation

* Update src/renderer/pages/player-page.js

Co-authored-by: Alex <alxmorais8@msn.com>

* Fix lint issue

Co-authored-by: Alex <alxmorais8@msn.com>
This commit is contained in:
Alex
2021-10-02 16:11:45 +03:00
committed by GitHub
parent 9c0ad29db9
commit 770c641f1b
3 changed files with 26 additions and 20 deletions

View File

@@ -7,6 +7,7 @@ const LinearProgress = require('material-ui/LinearProgress').default
const TorrentSummary = require('../lib/torrent-summary')
const TorrentPlayer = require('../lib/torrent-player')
const { dispatcher } = require('../lib/dispatcher')
const { calculateEta } = require('../lib/time')
module.exports = class TorrentList extends React.Component {
render () {
@@ -195,18 +196,9 @@ module.exports = class TorrentList extends React.Component {
const downloadSpeed = prog.downloadSpeed
if (downloadSpeed === 0 || missing === 0) return
const rawEta = missing / downloadSpeed
const hours = Math.floor(rawEta / 3600) % 24
const minutes = Math.floor(rawEta / 60) % 60
const seconds = Math.floor(rawEta % 60)
const etaStr = calculateEta(missing, downloadSpeed)
// Only display hours and minutes if they are greater than 0 but always
// display minutes if hours is being displayed
const hoursStr = hours ? hours + ' h' : ''
const minutesStr = (hours || minutes) ? minutes + ' min' : ''
const secondsStr = seconds + ' s'
return (<span key='eta'>{hoursStr} {minutesStr} {secondsStr} remaining</span>)
return (<span key='eta'>{etaStr}</span>)
}
function renderTorrentStatus () {