From: Jean-Baptiste Dubois Date: Mon, 4 Nov 2013 12:38:13 +0000 (+0100) Subject: Add milliseconds support in Rygel.TimeUtils time to string conversion X-Git-Tag: RYGEL_0_21_1~9 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=bea374723e36d0227b40a596f06c470346c8f935;p=profile%2Fivi%2Frygel.git Add milliseconds support in Rygel.TimeUtils time to string conversion https://bugzilla.gnome.org/show_bug.cgi?id=711399 --- 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); } }