Code

utils: renamed time_seconds_to_durationstr()
authorMax Kellermann <max@duempel.org>
Fri, 2 Oct 2009 06:22:05 +0000 (08:22 +0200)
committerMax Kellermann <max@duempel.org>
Fri, 2 Oct 2009 06:22:05 +0000 (08:22 +0200)
Rename time_seconds_to_durationstr() to format_duration_long().

src/screen_song.c
src/utils.c
src/utils.h

index d0ad9f9c96f6322c0a759556a2cd7f1ff92d18de..78fbf45e5a957d5537bfa157fc0d47e605b00763 100644 (file)
@@ -319,13 +319,13 @@ screen_song_add_stats(const struct mpdclient *c)
                g_snprintf(buf, sizeof(buf), "%d",
                           mpd_stats_get_number_of_songs(mpd_stats));
                screen_song_append(labels[SONGS], buf, max_label_width);
-               duration = time_seconds_to_durationstr(mpd_stats_get_db_play_time(mpd_stats));
+               duration = format_duration_long(mpd_stats_get_db_play_time(mpd_stats));
                screen_song_append(labels[DBPLAYTIME], duration, max_label_width);
                g_free(duration);
-               duration = time_seconds_to_durationstr(mpd_stats_get_play_time(mpd_stats));
+               duration = format_duration_long(mpd_stats_get_play_time(mpd_stats));
                screen_song_append(labels[PLAYTIME], duration, max_label_width);
                g_free(duration);
-               duration = time_seconds_to_durationstr(mpd_stats_get_uptime(mpd_stats));
+               duration = format_duration_long(mpd_stats_get_uptime(mpd_stats));
                screen_song_append(labels[UPTIME], duration, max_label_width);
                g_free(duration);
                date = g_date_new();
index 41ba2a541375ae07a6fb12fc5b9d9d4f7eb4c40d..688f6c88f4463afc93938fe3008dca8d16794d39 100644 (file)
@@ -123,7 +123,7 @@ gcmp_list_from_path(struct mpdclient *c, const gchar *path,
 }
 
 char *
-time_seconds_to_durationstr(unsigned long time_seconds)
+format_duration_long(unsigned long duration)
 {
        const char *year = _("year");
        const char *years = _("years");
@@ -131,46 +131,43 @@ time_seconds_to_durationstr(unsigned long time_seconds)
        const char *weeks = _("weeks");
        const char *day = _("day");
        const char *days = _("days");
-       char *duration;
-       char *iter;
+       char *buffer, *p;
        unsigned bytes_written = 0;
        unsigned length = utf8_width(years) +
                utf8_width(weeks) + utf8_width(days) + 32;
 
-       duration = g_malloc(length);
-       iter = duration;
-       if (time_seconds / 31536000 > 0) {
-               if (time_seconds / 31536000 == 1)
-                       bytes_written = g_snprintf(iter, length, "%d %s, ", 1, year);
+       buffer = g_malloc(length);
+       p = buffer;
+       if (duration / 31536000 > 0) {
+               if (duration / 31536000 == 1)
+                       bytes_written = g_snprintf(p, length, "%d %s, ", 1, year);
                else
-                       bytes_written = g_snprintf(iter, length, "%lu %s, ", time_seconds / 31536000, years);
-               time_seconds %= 31536000;
+                       bytes_written = g_snprintf(p, length, "%lu %s, ", duration / 31536000, years);
+               duration %= 31536000;
                length -= bytes_written;
-               iter += bytes_written;
+               p += bytes_written;
        }
-       if (time_seconds / 604800 > 0) {
-               if (time_seconds / 604800 == 1)
-                       bytes_written = g_snprintf(iter, length, "%d %s, ", 1, week);
+       if (duration / 604800 > 0) {
+               if (duration / 604800 == 1)
+                       bytes_written = g_snprintf(p, length, "%d %s, ", 1, week);
                else
-                       bytes_written = g_snprintf(iter, length, "%lu %s, ", time_seconds / 604800, weeks);
-               time_seconds %= 604800;
+                       bytes_written = g_snprintf(p, length, "%lu %s, ", duration / 604800, weeks);
+               duration %= 604800;
                length -= bytes_written;
-               iter += bytes_written;
+               p += bytes_written;
        }
-       if (time_seconds / 86400 > 0) {
-               if (time_seconds / 86400 == 1)
-                       bytes_written = g_snprintf(iter, length, "%d %s, ", 1, day);
+       if (duration / 86400 > 0) {
+               if (duration / 86400 == 1)
+                       bytes_written = g_snprintf(p, length, "%d %s, ", 1, day);
                else
-                       bytes_written = g_snprintf(iter, length, "%lu %s, ", time_seconds / 86400, days);
-               time_seconds %= 86400;
+                       bytes_written = g_snprintf(p, length, "%lu %s, ", duration / 86400, days);
+               duration %= 86400;
                length -= bytes_written;
-               iter += bytes_written;
+               p += bytes_written;
        }
-       g_snprintf(iter, length, "%02lu:%02lu:%02lu",
-                       time_seconds / 3600,
-                       time_seconds % 3600 / 60,
-                       time_seconds % 3600 % 60);
-       return duration;
+       g_snprintf(p, length, "%02lu:%02lu:%02lu", duration / 3600,
+                  duration % 3600 / 60, duration % 3600 % 60);
+       return buffer;
 }
 
 
index 40856800c08fe028f98616e86397c89eb9cc2061..1c8fe8ba0c914a3a272124a44aaa9eebc3682ded 100644 (file)
@@ -41,6 +41,6 @@ gcmp_list_from_path(struct mpdclient *c, const gchar *path,
                    GList *list, gint types);
 
 char *
-time_seconds_to_durationstr(unsigned long time_seconds);
+format_duration_long(unsigned long duration);
 
 #endif