[sushi] all: use the common method to format time strings



commit bdf20e273a247d3ad93e37fd156c6ea1266fbcbb
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Thu May 12 18:51:25 2011 -0400

    all: use the common method to format time strings

 src/js/viewers/audio.js |   40 ++++------------------------------------
 src/js/viewers/gst.js   |   32 ++------------------------------
 2 files changed, 6 insertions(+), 66 deletions(-)
---
diff --git a/src/js/viewers/audio.js b/src/js/viewers/audio.js
index 8eda041..e66a787 100644
--- a/src/js/viewers/audio.js
+++ b/src/js/viewers/audio.js
@@ -7,6 +7,8 @@ let _ = Gettext.gettext;
 
 let Constants = imports.util.constants;
 
+let Utils = imports.ui.utils;
+
 function AudioRenderer(args) {
     this._init(args);
 }
@@ -157,12 +159,6 @@ AudioRenderer.prototype = {
         this._isSettingValue = false;
     },
 
-    _formatTimeComponent : function(n) {
-        // FIXME: we need a sprinf equivalent to do
-        // proper formatting here.
-        return (n >= 10 ? n : "0" + n);
-    },
-
     _updateCurrentLabel : function() {
         if (!this._mainToolbar)
             return;
@@ -170,21 +166,7 @@ AudioRenderer.prototype = {
         let currentTime =
             Math.floor(this._player.duration * this._player.progress);
 
-        let hours = Math.floor(currentTime / 3600);
-        currentTime -= hours * 3600;
-
-        let minutes = Math.floor(currentTime / 60);
-        currentTime -= minutes * 60;
-
-        let seconds = Math.floor(currentTime);
-
-        let current = this._formatTimeComponent(minutes) + ":" +
-            this._formatTimeComponent(seconds);
-        if (hours > 0) {
-            current = this._formatTimeComponent(hours) + ":" + current;
-        }
-
-        this._currentLabel.set_text(current);
+        this._currentLabel.set_text(Utils.formatTimeString(currentTime));
     },
 
     _updateDurationLabel : function() {
@@ -193,21 +175,7 @@ AudioRenderer.prototype = {
 
         let totalTime = this._player.duration;
 
-        let hours = Math.floor(totalTime / 3600);
-        totalTime -= hours * 3600;
-
-        let minutes = Math.floor(totalTime / 60);
-        totalTime -= minutes * 60;
-
-        let seconds = Math.floor(totalTime);
-
-        let total = this._formatTimeComponent(minutes) + ":" +
-            this._formatTimeComponent(seconds);
-        if (hours > 0) {
-            this._formatTimeComponent(hours) + ":" + total;
-        }
-
-        this._durationLabel.set_text(total);
+        this._durationLabel.set_text(Utils.formatTimeString(totalTime));
     },
 
     _onPlayerProgressChanged : function() {
diff --git a/src/js/viewers/gst.js b/src/js/viewers/gst.js
index bdf038d..68f0215 100644
--- a/src/js/viewers/gst.js
+++ b/src/js/viewers/gst.js
@@ -74,21 +74,7 @@ GstRenderer.prototype = {
         let currentTime =
             Math.floor(this._video.duration * this._video.progress);
 
-        let hours = Math.floor(currentTime / 3600);
-        currentTime -= hours * 3600;
-
-        let minutes = Math.floor(currentTime / 60);
-        currentTime -= minutes * 60;
-
-        let seconds = Math.floor(currentTime);
-
-        let current = this._formatTimeComponent(minutes) + ":" +
-            this._formatTimeComponent(seconds);
-        if (hours > 0) {
-            current = this._formatTimeComponent(hours) + ":" + current;
-        }
-
-        this._currentLabel.set_text(current);
+        this._currentLabel.set_text(Utils.formatTimeString(currentTime));
     },
 
     _updateDurationLabel : function() {
@@ -97,21 +83,7 @@ GstRenderer.prototype = {
 
         let totalTime = this._video.duration;
 
-        let hours = Math.floor(totalTime / 3600);
-        totalTime -= hours * 3600;
-
-        let minutes = Math.floor(totalTime / 60);
-        totalTime -= minutes * 60;
-
-        let seconds = Math.floor(totalTime);
-
-        let total = this._formatTimeComponent(minutes) + ":" +
-            this._formatTimeComponent(seconds);
-        if (hours > 0) {
-            this._formatTimeComponent(hours) + ":" + total;
-        }
-
-        this._durationLabel.set_text(total);
+        this._durationLabel.set_text(Utils.formatTimeString(totalTime));
     },
 
     _onVideoProgressChange : function() {



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]