nypublicradio/ember-hifi

View on GitHub
addon/helpers/numeric-duration.js

Summary

Maintainability
A
0 mins
Test Coverage
B
87%
import { helper } from '@ember/component/helper';

export function numericDuration([duration]) {
  var seconds = parseInt((duration / 1000) % 60),
    minutes = parseInt((duration / (1000 * 60)) % 60),
    hours = parseInt((duration / (1000 * 60 * 60)) % 24);

    minutes = (minutes < 10) ? "0" + minutes : minutes;
    seconds = (seconds < 10) ? "0" + seconds : seconds;

  if (hours > 0) {
    return hours + ":" + minutes + ":" + seconds;
  }
  else {
    return minutes + ":" + seconds;
  }


}

export default helper(numericDuration);