Index: tests/testglib.c
===================================================================
--- tests/testglib.c	(revision 6160)
+++ tests/testglib.c	(working copy)
@@ -1420,6 +1420,46 @@ various_string_tests (void)
   g_free (date_str);
 
   if (g_test_verbose())
+    g_print ("test format time for display:\n");
+  g_get_current_time (&ref_date);
+  ref_date.tv_sec -= 10;
+  date_str = g_format_time_for_display (&ref_date);
+  g_assert (date_str != NULL);
+  if (g_test_verbose())
+    g_print ("\tformatted time (now -10s) = %s\n", date_str);
+  g_free (date_str);
+  ref_date.tv_sec -= 110;
+  date_str = g_format_time_for_display (&ref_date);
+  g_assert (date_str != NULL);
+  if (g_test_verbose())
+    g_print ("\tformatted time (now -120s) = %s\n", date_str);
+  g_free (date_str);
+  ref_date.tv_sec -= 3600;
+  date_str = g_format_time_for_display (&ref_date);
+  g_assert (date_str != NULL);
+  if (g_test_verbose())
+    g_print ("\tformatted time (now -3720s) = %s\n", date_str);
+  g_free (date_str);
+  ref_date.tv_sec -= 80000;
+  date_str = g_format_time_for_display (&ref_date);
+  g_assert (date_str != NULL);
+  if (g_test_verbose())
+    g_print ("\tformatted time (now -83720s) = %s\n", date_str);
+  g_free (date_str);
+  ref_date.tv_sec -= 80000;
+  date_str = g_format_time_for_display (&ref_date);
+  g_assert (date_str != NULL);
+  if (g_test_verbose())
+    g_print ("\tformatted time (now -163720s) = %s\n", date_str);
+  g_free (date_str);
+  ref_date.tv_sec -= (7 * 60 * 60 * 24);
+  date_str = g_format_time_for_display (&ref_date);
+  g_assert (date_str != NULL);
+  if (g_test_verbose())
+    g_print ("\tformatted time (now -621170s) = %s\n", date_str);
+  g_free (date_str);
+
+  if (g_test_verbose())
     g_print ("checking g_ascii_strcasecmp...");
   g_assert (g_ascii_strcasecmp ("FroboZZ", "frobozz") == 0);
   g_assert (g_ascii_strcasecmp ("frobozz", "frobozz") == 0);
Index: glib/gtimer.c
===================================================================
--- glib/gtimer.c	(revision 6160)
+++ glib/gtimer.c	(working copy)
@@ -416,5 +416,97 @@ g_time_val_to_iso8601 (GTimeVal *time_)
   return retval;
 }
 
+/**
+ * g_format_time_for_display:
+ * @time_: a #GTimeVal
+ *
+ * Converts @time_ into a UTF-8 string suitable for display. The
+ * conversion takes into account the time elapsed from @time_ to
+ * the current time.
+ *
+ * Return value: the time in a newly allocated formatted string.
+ *   Use g_free() when done
+ *
+ * Since: 2.16
+ */
+gchar *
+g_format_time_for_display (GTimeVal *time_)
+{
+  GTimeVal now;
+  struct tm tm_mtime;
+  const gchar *format = NULL;
+  gchar *locale_format = NULL;
+  gchar buf[256];
+  gchar *retval;
+  gint secs_diff;
+
+  g_return_val_if_fail (time_->tv_usec >= 0 && time_->tv_usec < G_USEC_PER_SEC, NULL);
+
+  g_get_current_time (&now);
+
+#ifdef HAVE_LOCALTIME_R
+  localtime_r ((time_t *) &(time_->tv_sec), &tm_mtime);
+#else
+  {
+    struct tm *ptm = localtime ((time_t *) &(time_->tv_usec));
+
+    if (!ptm)
+      {
+        g_warning ("ptm != NULL failed");
+        return NULL;
+      }
+    else
+      memcpy ((void *) &tm_mtime, (void *) ptm, sizeof (struct tm));
+  }
+#endif /* HAVE_LOCALTIME_R */
+
+  secs_diff  = now.tv_sec - time_->tv_sec;
+
+  /* within the hour */
+  if (secs_diff < 60)
+    format = "%d seconds ago";
+  else
+    {
+      gint mins_diff = secs_diff / 60;
+
+      if (mins_diff < 60)
+        format = "%d minutes ago";
+    }
+
+  if (!format)
+    {
+      GDate d1, d2;
+      gint days_diff;
+
+      g_date_set_time_t (&d1, now.tv_sec);
+      g_date_set_time_t (&d2, time_->tv_sec);
+
+      days_diff = g_date_get_julian (&d1) - g_date_get_julian (&d2);
+
+      if (days_diff == 0)
+        format = "Today at %H:%M";
+      else if (days_diff == 1)
+        format = "Yesterday at %H:%M";
+      else
+        {
+          if (days_diff > 1 && days_diff < 7)
+            format = "%A"; /* days of the week */
+          else
+            format = "%x"; /* any other date */
+        }
+    }
+
+  locale_format = g_locale_from_utf8 (format, -1, NULL, NULL, NULL);
+
+  if (strftime (buf, sizeof (buf), locale_format, &tm_mtime) != 0)
+    retval = g_locale_to_utf8 (buf, -1, NULL, NULL, NULL);
+  else
+    retval = g_strdup ("Unknown");
+
+  g_free (locale_format);
+
+  return retval;
+}
+
 #define __G_TIMER_C__
 #include "galiasdef.c"
Index: glib/gtimer.h
===================================================================
--- glib/gtimer.h	(revision 6159)
+++ glib/gtimer.h	(working copy)
@@ -39,22 +39,24 @@ typedef struct _GTimer		GTimer;
 
 #define G_USEC_PER_SEC 1000000
 
-GTimer*  g_timer_new	         (void);
-void	 g_timer_destroy         (GTimer      *timer);
-void	 g_timer_start	         (GTimer      *timer);
-void	 g_timer_stop	         (GTimer      *timer);
-void	 g_timer_reset	         (GTimer      *timer);
-void	 g_timer_continue        (GTimer      *timer);
-gdouble  g_timer_elapsed         (GTimer      *timer,
-				  gulong      *microseconds);
-
-void     g_usleep                (gulong       microseconds);
-
-void     g_time_val_add          (GTimeVal    *time_, 
-                                  glong        microseconds);
-gboolean g_time_val_from_iso8601 (const gchar *iso_date,
-				  GTimeVal    *time_);
-gchar*   g_time_val_to_iso8601   (GTimeVal    *time_) G_GNUC_MALLOC;
+GTimer*  g_timer_new	           (void);
+void	 g_timer_destroy           (GTimer      *timer);
+void	 g_timer_start	           (GTimer      *timer);
+void	 g_timer_stop	           (GTimer      *timer);
+void	 g_timer_reset	           (GTimer      *timer);
+void	 g_timer_continue          (GTimer      *timer);
+gdouble  g_timer_elapsed           (GTimer      *timer,
+				    gulong      *microseconds);
+
+void     g_usleep                  (gulong       microseconds);
+
+void     g_time_val_add            (GTimeVal    *time_, 
+                                    glong        microseconds);
+gboolean g_time_val_from_iso8601   (const gchar *iso_date,
+				    GTimeVal    *time_);
+gchar*   g_time_val_to_iso8601     (GTimeVal    *time_) G_GNUC_MALLOC;
+
+gchar*   g_format_time_for_display (GTimeVal    *time_) G_GNUC_MALLOC;
 
 G_END_DECLS
 
