summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: b3ae43e)
raw | patch | inline | side by side (parent: b3ae43e)
author | Max Kellermann <max@duempel.org> | |
Fri, 2 Oct 2009 06:22:05 +0000 (08:22 +0200) | ||
committer | Max 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 | patch | blob | history | |
src/utils.c | patch | blob | history | |
src/utils.h | patch | blob | history |
diff --git a/src/screen_song.c b/src/screen_song.c
index d0ad9f9c96f6322c0a759556a2cd7f1ff92d18de..78fbf45e5a957d5537bfa157fc0d47e605b00763 100644 (file)
--- a/src/screen_song.c
+++ b/src/screen_song.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();
diff --git a/src/utils.c b/src/utils.c
index 41ba2a541375ae07a6fb12fc5b9d9d4f7eb4c40d..688f6c88f4463afc93938fe3008dca8d16794d39 100644 (file)
--- a/src/utils.c
+++ b/src/utils.c
}
char *
-time_seconds_to_durationstr(unsigned long time_seconds)
+format_duration_long(unsigned long duration)
{
const char *year = _("year");
const char *years = _("years");
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;
}
diff --git a/src/utils.h b/src/utils.h
index 40856800c08fe028f98616e86397c89eb9cc2061..1c8fe8ba0c914a3a272124a44aaa9eebc3682ded 100644 (file)
--- a/src/utils.h
+++ b/src/utils.h
GList *list, gint types);
char *
-time_seconds_to_durationstr(unsigned long time_seconds);
+format_duration_long(unsigned long duration);
#endif