[rygel] Add milliseconds support in Rygel.TimeUtils time to string conversion



commit bea374723e36d0227b40a596f06c470346c8f935
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

 src/librygel-renderer/rygel-time-utils.vala |   19 ++++++++++++-------
 1 files changed, 12 insertions(+), 7 deletions(-)
---
diff --git a/src/librygel-renderer/rygel-time-utils.vala b/src/librygel-renderer/rygel-time-utils.vala
index f6a66b4..fb91ecd 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;
 
@@ -43,17 +43,18 @@ internal abstract class Rygel.TimeUtils {
                 break;
         }
 
-        time_str.scanf ("%llu:%2llu:%2llu%*s",
+        time_str.scanf ("%llu:%2llu:%2llu.%3llu",
                         out hours,
                         out minutes,
-                        out seconds);
+                        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) {
@@ -66,6 +67,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]