diff options
author | Stig Bjørlykke <stig@bjorlykke.org> | 2009-06-25 02:07:17 +0000 |
---|---|---|
committer | Stig Bjørlykke <stig@bjorlykke.org> | 2009-06-25 02:07:17 +0000 |
commit | 7221f30ab3266400b2c848fd39f10c6c9bc00a70 (patch) | |
tree | cab6adb3663c465357de37bc43134161025b56fb | |
parent | 26bd9f362315344b5eff6db1a8486643941c67fb (diff) |
From Nathan Hartwell via bug 2733:
Added time_secs_to_str_unsigned().
svn path=/trunk/; revision=28840
-rw-r--r-- | epan/to_str.c | 55 | ||||
-rw-r--r-- | epan/to_str.h | 1 |
2 files changed, 56 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) { diff --git a/epan/to_str.h b/epan/to_str.h index 6bf5a6cfc1..f2727ad771 100644 --- a/epan/to_str.h +++ b/epan/to_str.h @@ -69,6 +69,7 @@ extern gchar* ipxnet_to_str_punct(const guint32 ad, char punct); extern gchar* vines_addr_to_str(const guint8 *addrp); extern void vines_addr_to_str_buf(const guint8 *addrp, gchar *buf, int buf_len); extern gchar* time_secs_to_str(gint32); +extern gchar* time_secs_to_str_unsigned(guint32); extern gchar* time_msecs_to_str(gint32); extern gchar* abs_time_to_str(nstime_t*); extern gchar* abs_time_secs_to_str(time_t); |