[rygel/rygel-0-20] Add milliseconds support in Rygel.TimeUtils time to string conversion



commit 999d08e737d4f3cfd5b2fc2cdea9af7c9d441cd6
Author: Jean-Baptiste Dubois <jean-baptiste dubois parrot com>
Date:   Mon Nov 4 13:38:13 2013 +0100

    Add milliseconds support in Rygel.TimeUtils time to string conversion
    
    https://bugzilla.gnome.org/show_bug.cgi?id=711399
    
    Conflicts:
        src/librygel-renderer/rygel-time-utils.vala

 src/librygel-renderer/rygel-time-utils.vala |   19 ++++++++++++++-----
 1 files changed, 14 insertions(+), 5 deletions(-)
---
diff --git a/src/librygel-renderer/rygel-time-utils.vala b/src/librygel-renderer/rygel-time-utils.vala
index b7865f3..d9a6cbe 100644
--- a/src/librygel-renderer/rygel-time-utils.vala
+++ b/src/librygel-renderer/rygel-time-utils.vala
@@ -25,7 +25,7 @@
 
 internal abstract class Rygel.TimeUtils {
     public static int64 time_from_string (string str) {
-        uint64 hours, minutes, seconds;
+        uint64 hours, minutes, seconds, msecs;
         string time_str = str;
         int sign = 1;
 
@@ -41,13 +41,18 @@ internal abstract class Rygel.TimeUtils {
                 break;
         }
 
-        time_str.scanf ("%llu:%2llu:%2llu%*s", out hours, out minutes, out seconds);
+        time_str.scanf ("%llu:%2llu:%2llu.%3llu",
+                        out hours,
+                        out minutes,
+                        out seconds,
+                        out msecs);
 
-        return sign*(int64)(hours * 3600 + minutes * 60 + seconds) * TimeSpan.SECOND;
+        return sign * ((int64)(hours * 3600 + minutes * 60 + seconds) *
+               TimeSpan.SECOND + (int64)msecs * TimeSpan.MILLISECOND);
     }
 
     public static string time_to_string (int64 time) {
-        uint64 hours, minutes, seconds;
+        uint64 hours, minutes, seconds, totsecs, msecs;
         string sign = "";
 
         if (time < 0) {
@@ -60,6 +65,10 @@ internal abstract class Rygel.TimeUtils {
         minutes = seconds / 60;
         seconds = seconds % 60;
 
-        return "%s%llu:%.2llu:%.2llu".printf (sign, hours, minutes, seconds);
+        totsecs = (hours * 3600 + minutes * 60 + seconds) * TimeSpan.SECOND;
+        msecs = (time - totsecs) / TimeSpan.MILLISECOND;
+
+        return "%s%llu:%.2llu:%.2llu.%.3llu".printf (sign, hours, minutes,
+                                                     seconds, msecs);
     }
 }


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