[Xfce4-commits] <midori:master> Use GDateTime instead of GDate if available

Christian Dywan noreply at xfce.org
Tue Feb 21 21:48:03 CET 2012


Updating branch refs/heads/master
         to ffb86ce7ff23cdf83a4d424fb0d330da6dd9daf5 (commit)
       from f586c3004b9277fcd6e0e23b439f232be6fc784b (commit)

commit ffb86ce7ff23cdf83a4d424fb0d330da6dd9daf5
Author: Christian Dywan <christian at twotoasts.de>
Date:   Tue Feb 21 21:46:10 2012 +0100

    Use GDateTime instead of GDate if available
    
    GDate depends on broken msvcrt code.

 midori/sokoke.c         |   31 ------------------------
 midori/sokoke.h         |    4 ---
 panels/midori-history.c |   60 ++++++++++++++++++++++++++++++++++++++++++----
 3 files changed, 54 insertions(+), 41 deletions(-)

diff --git a/midori/sokoke.c b/midori/sokoke.c
index 3db12aa..8cd7df7 100644
--- a/midori/sokoke.c
+++ b/midori/sokoke.c
@@ -1030,37 +1030,6 @@ sokoke_time_t_to_julian (const time_t* timestamp)
 }
 
 /**
- * sokoke_days_between:
- * @day1: a time_t timestamp value
- * @day2: a time_t timestamp value
- *
- * Calculates the number of days between two timestamps.
- *
- * Return value: an integer.
- **/
-gint
-sokoke_days_between (const time_t* day1,
-                     const time_t* day2)
-{
-    GDate* date1;
-    GDate* date2;
-    gint age;
-
-    date1 = g_date_new ();
-    date2 = g_date_new ();
-
-    g_date_set_time_t (date1, *day1);
-    g_date_set_time_t (date2, *day2);
-
-    age = g_date_days_between (date1, date2);
-
-    g_date_free (date1);
-    g_date_free (date2);
-
-    return age;
-}
-
-/**
  * sokoke_set_config_dir:
  * @new_config_dir: an absolute path, or %NULL
  *
diff --git a/midori/sokoke.h b/midori/sokoke.h
index ac8902f..a92c6a7 100644
--- a/midori/sokoke.h
+++ b/midori/sokoke.h
@@ -121,10 +121,6 @@ sokoke_action_create_popup_menu_item    (GtkAction*      action);
 gint64
 sokoke_time_t_to_julian                 (const time_t*   timestamp);
 
-gint
-sokoke_days_between                     (const time_t*   day1,
-                                         const time_t*   day2);
-
 const gchar*
 sokoke_set_config_dir                   (const gchar*    new_config_dir);
 
diff --git a/panels/midori-history.c b/panels/midori-history.c
index ce635f6..d264950 100644
--- a/panels/midori-history.c
+++ b/panels/midori-history.c
@@ -116,18 +116,59 @@ midori_history_get_stock_id (MidoriViewable* viewable)
     return STOCK_HISTORY;
 }
 
+#if !GLIB_CHECK_VERSION (2, 26, 0)
+static gint
+sokoke_days_between (const time_t* day1,
+                     const time_t* day2)
+{
+    GDate* date1;
+    GDate* date2;
+    gint age;
+
+    date1 = g_date_new ();
+    date2 = g_date_new ();
+
+    g_date_set_time_t (date1, *day1);
+    g_date_set_time_t (date2, *day2);
+
+    age = g_date_days_between (date1, date2);
+
+    g_date_free (date1);
+    g_date_free (date2);
+
+    return age;
+}
+#endif
+
 static gchar*
 midori_history_format_date (KatzeItem *item)
 {
+    gint64 day = katze_item_get_added (item);
+    gchar* sdate;
     gint age;
-    gint64 day;
+    #if GLIB_CHECK_VERSION (2, 26, 0)
+    GDateTime* now = g_date_time_new_now_local ();
+    GDateTime* then = g_date_time_new_from_unix_local (day);
+    if (g_date_time_get_day_of_month (then) == g_date_time_get_day_of_month (now))
+        sdate = g_strdup (_("Today"));
+    else if (g_date_time_get_day_of_year (then) == g_date_time_get_day_of_year (now) - 1)
+        sdate = g_strdup (_("Yesterday"));
+    else
+    {
+        age = g_date_time_get_day_of_year (now) - g_date_time_get_day_of_year (then);
+        if (age < 7)
+            sdate = g_strdup_printf (ngettext ("%d day ago",
+                "%d days ago", (gint)age), (gint)age);
+        else if (age == 7)
+            sdate = g_strdup (_("A week ago"));
+        else
+            sdate = g_date_time_format (then, "%x");
+    }
+    #else
     gchar token[50];
-    gchar* sdate;
     time_t current_time;
 
     current_time = time (NULL);
-    day = katze_item_get_added (item);
-
     age = sokoke_days_between ((time_t*)&day, &current_time);
 
     /* A negative age is a date in the future, the clock is probably off */
@@ -147,6 +188,7 @@ midori_history_format_date (KatzeItem *item)
         sdate = g_strdup (_("Today"));
     else
         sdate = g_strdup (_("Yesterday"));
+    #endif
     return sdate;
 }
 
@@ -412,9 +454,8 @@ midori_history_add_item_cb (KatzeArray*    array,
     GtkTreeModel* model = gtk_tree_view_get_model (treeview);
     GtkTreeIter iter;
     KatzeItem* today;
-    time_t current_time;
+    time_t current_time = time (NULL);
 
-    current_time = time (NULL);
     if (gtk_tree_model_iter_children (model, &iter, NULL))
     {
         gint64 day;
@@ -423,7 +464,14 @@ midori_history_add_item_cb (KatzeArray*    array,
         gtk_tree_model_get (model, &iter, 0, &today, -1);
 
         day = katze_item_get_added (today);
+        #if GLIB_CHECK_VERSION (2, 26, 0)
+        has_today = g_date_time_get_day_of_month (
+            g_date_time_new_from_unix_local (day))
+         == g_date_time_get_day_of_month (
+            g_date_time_new_from_unix_local (current_time));
+        #else
         has_today = sokoke_days_between ((time_t*)&day, &current_time) == 0;
+        #endif
         g_object_unref (today);
         if (has_today)
         {


More information about the Xfce4-commits mailing list