From e0a8fffedff3555b2a2451394ef78f104a9001ca Mon Sep 17 00:00:00 2001 From: Mike Blumenkrantz Date: Tue, 17 Jul 2012 12:10:18 +0000 Subject: [PATCH] add e_util_time_str_get() to convert a time value in seconds to a string approximation SVN revision: 73976 --- src/bin/e_utils.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++ src/bin/e_utils.h | 2 +- 2 files changed, 64 insertions(+), 1 deletion(-) diff --git a/src/bin/e_utils.c b/src/bin/e_utils.c index 6b81534b0..88c726f68 100644 --- a/src/bin/e_utils.c +++ b/src/bin/e_utils.c @@ -1732,3 +1732,66 @@ e_util_fullscreen_any(void) return EINA_FALSE; } +EAPI const char * +e_util_time_str_get(long int seconds) +{ + static char buf[1024]; + long int test; + + if (seconds < 0) + snprintf(buf, sizeof(buf), _("Never")); + else + { + if (seconds <= 60) + snprintf(buf, sizeof(buf), _("%d Seconds"), seconds); + else if (seconds >= 31526000) + { + test = seconds / 31526000; + if (test == 1) + snprintf(buf, sizeof(buf), _("One year")); + else + snprintf(buf, sizeof(buf), _("%li Years"), test); + } + else if (seconds >= 2592000) + { + test = seconds / 2592000; + if (test == 1) + snprintf(buf, sizeof(buf), _("One month")); + else + snprintf(buf, sizeof(buf), _("%li Months"), test); + } + else if (seconds >= 604800) + { + test = seconds / 604800; + if (test == 1) + snprintf(buf, sizeof(buf), _("One week")); + else + snprintf(buf, sizeof(buf), _("%li Weeks"), test); + } + else if (seconds >= 86400) + { + test = seconds / 86400; + if (test == 1) + snprintf(buf, sizeof(buf), _("One day")); + else + snprintf(buf, sizeof(buf), _("%li Days"), test); + } + else if (seconds >= 3600) + { + test = seconds / 3600; + if (test == 1) + snprintf(buf, sizeof(buf), _("An hour")); + else + snprintf(buf, sizeof(buf), _("%li Hours"), test); + } + else if (seconds > 60) + { + test = seconds / 60; + if (test == 1) + snprintf(buf, sizeof(buf), _("A minute")); + else + snprintf(buf, sizeof(buf), _("%li Minutes"), test); + } + } + return buf; +} diff --git a/src/bin/e_utils.h b/src/bin/e_utils.h index 95ac4b389..c7786a4aa 100644 --- a/src/bin/e_utils.h +++ b/src/bin/e_utils.h @@ -81,6 +81,6 @@ EAPI int e_util_container_desk_count_get(E_Container *con); EAPI Eina_Bool e_util_fullscreen_curreny_any(void); EAPI Eina_Bool e_util_fullscreen_any(void); - +EAPI const char *e_util_time_str_get(long int seconds); #endif #endif