[rhythmbox] add a function for formatting times that could be 0 seconds
- From: Jonathan Matthew <jmatthew src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [rhythmbox] add a function for formatting times that could be 0 seconds
- Date: Wed, 28 Mar 2012 13:23:43 +0000 (UTC)
commit a2d77c6ed7948e958690110091d64092f1d39cb1
Author: Jonathan Matthew <jonathan d14n org>
Date: Wed Mar 28 22:48:34 2012 +1000
add a function for formatting times that could be 0 seconds
rb_make_time_string is like rb_make_duration_string, except
it returns 0:00 for 0 seconds rather than 'Unknown'
lib/rb-util.c | 43 ++++++++++++++++++++++++++++---------------
lib/rb-util.h | 1 +
2 files changed, 29 insertions(+), 15 deletions(-)
---
diff --git a/lib/rb-util.c b/lib/rb-util.c
index d3f62ab..d08c819 100644
--- a/lib/rb-util.c
+++ b/lib/rb-util.c
@@ -674,6 +674,30 @@ rb_search_fold (const char *original)
}
/**
+ * rb_make_time_string:
+ * @seconds: time in seconds
+ *
+ * Constructs a string describing the specified time.
+ *
+ * Return value: (transfer full): time string
+ */
+char *
+rb_make_time_string (guint nseconds)
+{
+ int hours, minutes, seconds;
+
+ hours = nseconds / (60 * 60);
+ minutes = (nseconds - (hours * 60 * 60)) / 60;
+ seconds = nseconds % 60;
+
+ if (hours == 0)
+ return g_strdup_printf (_("%d:%02d"), minutes, seconds);
+ else
+ return g_strdup_printf (_("%d:%02d:%02d"), hours, minutes, seconds);
+}
+
+
+/**
* rb_make_duration_string:
* @duration: duration in seconds
*
@@ -685,21 +709,10 @@ rb_search_fold (const char *original)
char *
rb_make_duration_string (guint duration)
{
- char *str;
- int hours, minutes, seconds;
-
- hours = duration / (60 * 60);
- minutes = (duration - (hours * 60 * 60)) / 60;
- seconds = duration % 60;
-
- if (hours == 0 && minutes == 0 && seconds == 0)
- str = g_strdup (_("Unknown"));
- else if (hours == 0)
- str = g_strdup_printf (_("%d:%02d"), minutes, seconds);
+ if (duration == 0)
+ return g_strdup (_("Unknown"));
else
- str = g_strdup_printf (_("%d:%02d:%02d"), hours, minutes, seconds);
-
- return str;
+ return rb_make_time_string (duration);
}
/**
@@ -721,7 +734,7 @@ rb_make_elapsed_time_string (guint elapsed, guint duration, gboolean show_remain
int seconds2 = 0, minutes2 = 0, hours2 = 0;
if (duration == 0)
- return rb_make_duration_string (elapsed);
+ return rb_make_time_string (elapsed);
if (duration > 0) {
hours2 = duration / (60 * 60);
diff --git a/lib/rb-util.h b/lib/rb-util.h
index 2532e72..4b9024d 100644
--- a/lib/rb-util.h
+++ b/lib/rb-util.h
@@ -52,6 +52,7 @@ int rb_gvalue_compare (GValue *a, GValue *b);
int rb_compare_gtimeval (GTimeVal *a, GTimeVal *b);
int rb_safe_strcmp (const char *a, const char *b);
+char *rb_make_time_string (guint seconds);
char *rb_make_duration_string (guint duration);
char *rb_make_elapsed_time_string (guint elapsed, guint duration, gboolean show_remaining);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]