[evolution] Bug #594609 - Date field in message list shows incorrect "x days ago".



commit 1b1ca26a24330b601aa8469cdb5ec6eadaf8bd6a
Author: Chenthill Palanisamy <pchenthill novell com>
Date:   Thu Sep 10 14:31:36 2009 +0530

    Bug #594609 - Date field in message list shows incorrect "x days ago".

 e-util/e-datetime-format.c |   18 ++++++++++--------
 1 files changed, 10 insertions(+), 8 deletions(-)
---
diff --git a/e-util/e-datetime-format.c b/e-util/e-datetime-format.c
index 6dff77f..2e63231 100644
--- a/e-util/e-datetime-format.c
+++ b/e-util/e-datetime-format.c
@@ -171,13 +171,18 @@ static gchar *
 format_relative_date (time_t tvalue, time_t ttoday, const struct tm *value, const struct tm *today)
 {
 	gchar *res = g_strdup (get_default_format (DTFormatKindDate, NULL));
+	GDate now, val;
+	gint diff;
 
 	g_return_val_if_fail (value != NULL, res);
 	g_return_val_if_fail (today != NULL, res);
 
+	g_date_set_time_t (&now, ttoday);
+	g_date_set_time_t (&val, tvalue);
+		
+	diff = g_date_get_julian (&now) - g_date_get_julian (&val);
 	/* if it's more than a week, use the default date format */
-	if (ttoday - tvalue > 7 * 24 * 60 * 60 ||
-	    tvalue - ttoday > 7 * 24 * 60 * 60)
+	if (ABS (diff) > 7)
 		return res;
 
 	g_free (res);
@@ -187,14 +192,11 @@ format_relative_date (time_t tvalue, time_t ttoday, const struct tm *value, cons
 	    value->tm_mday == today->tm_mday) {
 		res = g_strdup (_("Today"));
 	} else {
-		gint diff = (gint) (tvalue - ttoday);
-		gint since_midnight = today->tm_sec + (60 * today->tm_min) + (60 * 60 * today->tm_hour);
-		gboolean future = (diff > 0);
+		gboolean future = FALSE;
 
-		if (!future)
-			diff *= -1;
+		if (diff < 0)
+			future = TRUE;
 
-		diff = (diff - since_midnight) / (24 * 60 * 60);
 		if (diff <= 1) {
 			if (future)
 				res = g_strdup (_("Tomorrow"));



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]