Skip to content

Commit

Permalink
fix: Make sure time displays use correctly-formatted time. (#4643)
Browse files Browse the repository at this point in the history
  • Loading branch information
misteroneill committed Oct 3, 2017
1 parent f0d9c24 commit 20f7fe9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
15 changes: 15 additions & 0 deletions src/js/control-bar/time-controls/remaining-time-display.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,21 @@ class RemainingTimeDisplay extends TimeDisplay {
return 'vjs-remaining-time';
}

/**
* The remaining time display prefixes numbers with a "minus" character.
*
* @param {number} time
* A numeric time, in seconds.
*
* @return {string}
* A formatted time
*
* @private
*/
formatTime_(time) {
return '-' + super.formatTime_(time);
}

/**
* Update remaining time display.
*
Expand Down
19 changes: 17 additions & 2 deletions src/js/control-bar/time-controls/time-display.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,25 @@ class TimeDisplay extends Component {
if (this.textNode_) {
this.contentEl_.removeChild(this.textNode_);
}
this.textNode_ = document.createTextNode(` -${this.formattedTime_ || '0:00'}`);
this.textNode_ = document.createTextNode(this.formattedTime_ || '0:00');
this.contentEl_.appendChild(this.textNode_);
}

/**
* Generates a formatted time for this component to use in display.
*
* @param {number} time
* A numeric time, in seconds.
*
* @return {string}
* A formatted time
*
* @private
*/
formatTime_(time) {
return formatTime(time);
}

/**
* Updates the time display text node if it has what was passed in changed
* the formatted time.
Expand All @@ -80,7 +95,7 @@ class TimeDisplay extends Component {
* @private
*/
updateFormattedTime_(time) {
const formattedTime = formatTime(time);
const formattedTime = this.formatTime_(time);

if (formattedTime === this.formattedTime_) {
return;
Expand Down

0 comments on commit 20f7fe9

Please sign in to comment.