[Xfce4-commits] <postler:master> Display date as Today or Yesterday if appropriate

Christian Dywan noreply at xfce.org
Thu Jun 3 03:24:02 CEST 2010


Updating branch refs/heads/master
         to 904c55789889341f69f557f0373c605fbe768815 (commit)
       from 282000071c5828a04a3c546726d8df7f1739461e (commit)

commit 904c55789889341f69f557f0373c605fbe768815
Author: Christian Dywan <christian at twotoasts.de>
Date:   Wed Jun 2 20:56:09 2010 +0200

    Display date as Today or Yesterday if appropriate

 postler/postler-content.vala  |    4 +++-
 postler/postler-messages.vala |   14 ++++++++++++--
 2 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/postler/postler-content.vala b/postler/postler-content.vala
index 3856fbf..c70dac2 100644
--- a/postler/postler-content.vala
+++ b/postler/postler-content.vala
@@ -223,6 +223,8 @@ public class Postler.Content : WebKit.WebView {
             string content_encoding = "";
             string from = _("Unknown");
             string date = _("(No date)");
+            var now = GLib.Date ();
+            now.set_time_val (GLib.TimeVal ());
             string recipient = "";
             string carbon_copy = "";
             /* TODO: blind_copy, some clients keep it */
@@ -259,7 +261,7 @@ public class Postler.Content : WebKit.WebView {
                 }
                 else if (field == "date") {
                     time_t timestamp;
-                    date = Postler.Messages.format_date (parts[1], out timestamp);
+                    date = Postler.Messages.format_date (parts[1], now, out timestamp);
                 }
                 else if (field == "to")
                     recipient = parts[1].strip ();
diff --git a/postler/postler-messages.vala b/postler/postler-messages.vala
index 6195d6f..f4e1a9c 100644
--- a/postler/postler-messages.vala
+++ b/postler/postler-messages.vala
@@ -181,9 +181,17 @@ public class Postler.Messages : Gtk.TreeView {
         content.clear ();
     }
 
-    internal static string format_date (string date, out time_t timestamp) {
+    internal static string format_date (string date, GLib.Date now,
+        out time_t timestamp) {
         var parsed = new Soup.Date.from_string (date);
         timestamp = parsed != null ? (time_t)parsed.to_time_t () : 0;
+        var the_time = GLib.Date ();
+        the_time.set_time_t (timestamp);
+        int days = now.days_between (the_time);
+        if (days == 0)
+            return _("Today") + GLib.Time.local (timestamp).format (" %X");
+        if (days == 1)
+            return _("Yesterday") + GLib.Time.local (timestamp).format ("%X");
         return GLib.Time.local (timestamp).format ("%x %X");
     }
 
@@ -199,6 +207,8 @@ public class Postler.Messages : Gtk.TreeView {
             return true;
         if (filter != "")
             last_filter = filter;
+        var now = GLib.Date ();
+        now.set_time_val (GLib.TimeVal ());
         try {
             string[] folders = { "cur", "new" };
             foreach (var folder in folders) {
@@ -272,7 +282,7 @@ public class Postler.Messages : Gtk.TreeView {
                                 from = parse_encoded (parts[1], out from_charset);
                             }
                             else if (field == "date")
-                                date = format_date (parts[1], out timestamp);
+                                date = format_date (parts[1], now, out timestamp);
                         }
                     } catch (GLib.Error contents_error) {
                         GLib.critical (_("Failed to read message \"%s\": %s"),



More information about the Xfce4-commits mailing list