aboutsummaryrefslogtreecommitdiffstats
path: root/epan/to_str.c
diff options
context:
space:
mode:
authorStig Bjørlykke <stig@bjorlykke.org>2009-06-25 02:07:17 +0000
committerStig Bjørlykke <stig@bjorlykke.org>2009-06-25 02:07:17 +0000
commit7221f30ab3266400b2c848fd39f10c6c9bc00a70 (patch)
treecab6adb3663c465357de37bc43134161025b56fb /epan/to_str.c
parent26bd9f362315344b5eff6db1a8486643941c67fb (diff)
From Nathan Hartwell via bug 2733:
Added time_secs_to_str_unsigned(). svn path=/trunk/; revision=28840
Diffstat (limited to 'epan/to_str.c')
-rw-r--r--epan/to_str.c55
1 files changed, 55 insertions, 0 deletions
diff --git a/epan/to_str.c b/epan/to_str.c
index 37b6f3c49b..5350a46cd7 100644
--- a/epan/to_str.c
+++ b/epan/to_str.c
@@ -426,6 +426,61 @@ time_secs_to_str(gint32 time)
return buf->str;
}
+static void
+time_secs_to_str_buf_unsigned(guint32 time, guint32 frac, gboolean is_nsecs,
+ emem_strbuf_t *buf)
+{
+ int hours, mins, secs;
+ const gchar *msign = "";
+ gboolean do_comma = FALSE;
+
+ secs = time % 60;
+ time /= 60;
+ mins = time % 60;
+ time /= 60;
+ hours = time % 24;
+ time /= 24;
+
+ if (time != 0) {
+ ep_strbuf_append_printf(buf, "%s%u day%s", msign, time, PLURALIZE(time));
+ do_comma = TRUE;
+ }
+ if (hours != 0) {
+ ep_strbuf_append_printf(buf, "%s%s%u hour%s", COMMA(do_comma), msign, hours, PLURALIZE(hours));
+ do_comma = TRUE;
+ }
+ if (mins != 0) {
+ ep_strbuf_append_printf(buf, "%s%s%u minute%s", COMMA(do_comma), msign, mins, PLURALIZE(mins));
+ do_comma = TRUE;
+ }
+ if (secs != 0 || frac != 0) {
+ if (frac != 0) {
+ if (is_nsecs)
+ ep_strbuf_append_printf(buf, "%s%s%u.%09u seconds", COMMA(do_comma), msign, secs, frac);
+ else
+ ep_strbuf_append_printf(buf, "%s%s%u.%03u seconds", COMMA(do_comma), msign, secs, frac);
+ } else
+ ep_strbuf_append_printf(buf, "%s%s%u second%s", COMMA(do_comma), msign, secs, PLURALIZE(secs));
+ }
+}
+
+gchar *
+time_secs_to_str_unsigned(guint32 time)
+{
+ emem_strbuf_t *buf;
+
+ buf=ep_strbuf_sized_new(TIME_SECS_LEN+1, TIME_SECS_LEN+1);
+
+ if (time == 0) {
+ ep_strbuf_append(buf, "0 time");
+ return buf->str;
+ }
+
+ time_secs_to_str_buf_unsigned(time, 0, FALSE, buf);
+ return buf->str;
+}
+
+
gchar *
time_msecs_to_str(gint32 time)
{