diff options
author | Will Thompson <will.thompson@collabora.co.uk> | 2011-05-16 21:08:10 +0800 |
---|---|---|
committer | Will Thompson <will.thompson@collabora.co.uk> | 2011-05-16 21:08:10 +0800 |
commit | 45609a2304c805e1c05ba15e0856c9c41f020986 (patch) | |
tree | 4183120a0648545786d23a15af91dea2a14ff08a /libempathy | |
parent | 383bf53000a686e5d411f48603b506bb64dd0e28 (diff) | |
parent | 9c42c7ae5d46bf3bf2aa4aab8e4d615876982eca (diff) | |
download | gsoc2013-empathy-45609a2304c805e1c05ba15e0856c9c41f020986.tar gsoc2013-empathy-45609a2304c805e1c05ba15e0856c9c41f020986.tar.gz gsoc2013-empathy-45609a2304c805e1c05ba15e0856c9c41f020986.tar.bz2 gsoc2013-empathy-45609a2304c805e1c05ba15e0856c9c41f020986.tar.lz gsoc2013-empathy-45609a2304c805e1c05ba15e0856c9c41f020986.tar.xz gsoc2013-empathy-45609a2304c805e1c05ba15e0856c9c41f020986.tar.zst gsoc2013-empathy-45609a2304c805e1c05ba15e0856c9c41f020986.zip |
Merge branch 'more-contact-info'
Diffstat (limited to 'libempathy')
-rw-r--r-- | libempathy/empathy-time.c | 64 | ||||
-rw-r--r-- | libempathy/empathy-time.h | 1 |
2 files changed, 36 insertions, 29 deletions
diff --git a/libempathy/empathy-time.c b/libempathy/empathy-time.c index f33152d97..5144fa4d8 100644 --- a/libempathy/empathy-time.c +++ b/libempathy/empathy-time.c @@ -81,6 +81,40 @@ empathy_time_to_string_local (gint64 t, return result; } +gchar * +empathy_duration_to_string (guint seconds) +{ + if (seconds < 60) { + return g_strdup_printf (ngettext ("%d second ago", + "%d seconds ago", seconds), seconds); + } + else if (seconds < (60 * 60)) { + seconds /= 60; + return g_strdup_printf (ngettext ("%d minute ago", + "%d minutes ago", seconds), seconds); + } + else if (seconds < (60 * 60 * 24)) { + seconds /= 60 * 60; + return g_strdup_printf (ngettext ("%d hour ago", + "%d hours ago", seconds), seconds); + } + else if (seconds < (60 * 60 * 24 * 7)) { + seconds /= 60 * 60 * 24; + return g_strdup_printf (ngettext ("%d day ago", + "%d days ago", seconds), seconds); + } + else if (seconds < (60 * 60 * 24 * 30)) { + seconds /= 60 * 60 * 24 * 7; + return g_strdup_printf (ngettext ("%d week ago", + "%d weeks ago", seconds), seconds); + } + else { + seconds /= 60 * 60 * 24 * 30; + return g_strdup_printf (ngettext ("%d month ago", + "%d months ago", seconds), seconds); + } +} + gchar * empathy_time_to_string_relative (gint64 t) { @@ -96,35 +130,7 @@ empathy_time_to_string_relative (gint64 t) seconds = delta / G_TIME_SPAN_SECOND; if (seconds > 0) { - if (seconds < 60) { - result = g_strdup_printf (ngettext ("%d second ago", - "%d seconds ago", seconds), seconds); - } - else if (seconds < (60 * 60)) { - seconds /= 60; - result = g_strdup_printf (ngettext ("%d minute ago", - "%d minutes ago", seconds), seconds); - } - else if (seconds < (60 * 60 * 24)) { - seconds /= 60 * 60; - result = g_strdup_printf (ngettext ("%d hour ago", - "%d hours ago", seconds), seconds); - } - else if (seconds < (60 * 60 * 24 * 7)) { - seconds /= 60 * 60 * 24; - result = g_strdup_printf (ngettext ("%d day ago", - "%d days ago", seconds), seconds); - } - else if (seconds < (60 * 60 * 24 * 30)) { - seconds /= 60 * 60 * 24 * 7; - result = g_strdup_printf (ngettext ("%d week ago", - "%d weeks ago", seconds), seconds); - } - else { - seconds /= 60 * 60 * 24 * 30; - result = g_strdup_printf (ngettext ("%d month ago", - "%d months ago", seconds), seconds); - } + result = empathy_duration_to_string (seconds); } else { result = g_strdup (_("in the future")); diff --git a/libempathy/empathy-time.h b/libempathy/empathy-time.h index 7fac48221..3a22adeee 100644 --- a/libempathy/empathy-time.h +++ b/libempathy/empathy-time.h @@ -45,6 +45,7 @@ gchar *empathy_time_to_string_utc (gint64 t, gchar *empathy_time_to_string_local (gint64 t, const gchar *format); gchar *empathy_time_to_string_relative (gint64 t); +gchar *empathy_duration_to_string (guint seconds); G_END_DECLS |