improve date formatting.
authorGustavo Sverzut Barbieri <barbieri@profusion.mobi>
Sun, 5 Aug 2012 18:46:47 +0000 (15:46 -0300)
committerGustavo Sverzut Barbieri <barbieri@profusion.mobi>
Sun, 5 Aug 2012 18:46:47 +0000 (15:46 -0300)
For dates over a week, show the locale date representation.

This allows us to skip updating those items.

dialer/history.c
dialer/util.c
dialer/util.h

index 0747d3a..8753848 100644 (file)
@@ -54,14 +54,23 @@ static Eina_Bool _history_time_updater(void *data)
 {
        History *ctx = data;
        Elm_Object_Item *it;
+       long long update_threshold = time(NULL) - WEEK - DAY;
 
        it = elm_genlist_first_item_get(ctx->genlist_all);
-       for (; it != NULL; it = elm_genlist_item_next_get(it))
+       for (; it != NULL; it = elm_genlist_item_next_get(it)) {
+               const Call_Info *call_info = elm_object_item_data_get(it);
+               if (call_info->start_time < update_threshold)
+                       continue;
                elm_genlist_item_update(it);
+       }
 
        it = elm_genlist_first_item_get(ctx->genlist_missed);
-       for (; it != NULL; it = elm_genlist_item_next_get(it))
+       for (; it != NULL; it = elm_genlist_item_next_get(it)) {
+               const Call_Info *call_info = elm_object_item_data_get(it);
+               if (call_info->start_time < update_threshold)
+                       continue;
                elm_genlist_item_update(it);
+       }
 
        return EINA_TRUE;
 }
index 8cfbed6..83fe7dd 100644 (file)
@@ -5,11 +5,7 @@
 #include <Eina.h>
 #include <time.h>
 
-#define MINUTE 60
-#define HOUR ((MINUTE) * 60)
-#define DAY ((HOUR) * 24)
-#define MONTH ((DAY) * 30)
-#define YEAR ((MONTH) *12)
+#include "util.h"
 
 /* TODO: find a configurable way to format the number.
  * Right now it's: 1-234-567-8901 as per
@@ -76,32 +72,22 @@ char *date_format(time_t date)
                r = asprintf(&buf, "%d minutes ago", (int)dt/60);
        else if (dt < (HOUR * 4))
                r = asprintf(&buf, "%d hours ago", (int)dt/3600);
-       else if (dt < DAY) {
+       else if (dt <= DAY) {
                struct tm *f_time = gmtime(&date);
                EINA_SAFETY_ON_NULL_GOTO(f_time, err_gmtime);
                r = asprintf(&buf,  "%02d:%02d", f_time->tm_hour,
                                f_time->tm_min);
-       } else if(dt < MONTH){
-               struct tm f_time;
-               struct tm f_now;
-               EINA_SAFETY_ON_NULL_GOTO(gmtime_r(&now, &f_now), err_gmtime);
-               EINA_SAFETY_ON_NULL_GOTO(gmtime_r(&date, &f_time), err_gmtime);
-               r = asprintf(&buf, "%d days ago",
-                               f_now.tm_mday - f_time.tm_mday);
-       } else if (dt < YEAR) {
-               struct tm f_time;
-               struct tm f_now;
-               EINA_SAFETY_ON_NULL_GOTO(gmtime_r(&now, &f_now), err_gmtime);
-               EINA_SAFETY_ON_NULL_GOTO(gmtime_r(&date, &f_time), err_gmtime);
-               r = asprintf(&buf, "%d months ago",
-                               f_now.tm_mon - f_time.tm_mon);
+       } else if (dt < WEEK) {
+               char tmp[256];
+               struct tm *tm = localtime(&date);
+               strftime(tmp, sizeof(tmp), "%A", tm);
+               int days = dt / DAY;
+               r = asprintf(&buf, "%s, %d days ago", tmp, days);
        } else {
-               struct tm f_time;
-               struct tm f_now;
-               EINA_SAFETY_ON_NULL_GOTO(gmtime_r(&now, &f_now), err_gmtime);
-               EINA_SAFETY_ON_NULL_GOTO(gmtime_r(&date, &f_time), err_gmtime);
-               r = asprintf(&buf, "%d years ago",
-                               f_now.tm_year - f_time.tm_year);
+               char tmp[256];
+               struct tm *tm = localtime(&date);
+               strftime(tmp, sizeof(tmp), "%x", tm);
+               r = asprintf(&buf, "%s", tmp);
        }
 
        if (r < 0)
index c9e6e78..495f204 100644 (file)
@@ -1,6 +1,13 @@
 #ifndef _EFL_OFONO_UTIL_H__
 #define _EFL_OFONO_UTIL_H__
 
+#define MINUTE 60
+#define HOUR ((MINUTE) * 60)
+#define DAY ((HOUR) * 24)
+#define WEEK ((DAY) * 7)
+#define MONTH ((DAY) * 30)
+#define YEAR ((MONTH) *12)
+
 char *phone_format(const char *number);
 
 char *date_format(time_t date);