#include <stdlib.h>
#include <glib/gi18n.h>
#include <regex.h>
+#include <modest-tny-platform-factory.h>
#include "modest-text-utils.h"
gint indent, breakpoint, rem_indent = 0;
GString *q, *l, *remaining;
gsize len;
- gchar *tmp;
/* remaining will store the rest of the line if we have to break it */
q = g_string_new (cite);
return result;
}
+static GHashTable*
+get_display_date_cache (void)
+{
+ TnyPlatformFactory *fakt;
+ ModestCacheMgr *cache_mgr;
+
+ fakt = modest_tny_platform_factory_get_instance ();
+
+ cache_mgr = modest_tny_platform_factory_get_cache_mgr_instance
+ (MODEST_TNY_PLATFORM_FACTORY(fakt));
+
+ return modest_cache_mgr_get_cache (cache_mgr,
+ MODEST_CACHE_MGR_CACHE_TYPE_DATE_STRING);
+}
+
+
const gchar*
modest_text_utils_get_display_date (time_t date)
{
+ static GHashTable *date_cache = NULL;
+
struct tm date_tm, now_tm;
time_t now;
const gint buf_size = 64;
static gchar date_buf[64]; /* buf_size is not ... */
static gchar now_buf[64]; /* ...const enough... */
+ gchar* cached_val;
+
+ if (G_UNLIKELY(!date_cache))
+ date_cache = get_display_date_cache ();
+ cached_val = g_hash_table_lookup (date_cache, &date);
+ if (cached_val)
+ return cached_val;
+
now = time (NULL);
localtime_r(&now, &now_tm);
/* if this is today, get the time instead of the date */
if (strcmp (date_buf, now_buf) == 0)
strftime (date_buf, buf_size, _("%X"), &date_tm);
-
- return date_buf;
+
+ cached_val = g_strdup(date_buf);
+ g_hash_table_insert (date_cache, (gpointer)&date, (gpointer)cached_val);
+
+ return cached_val;
}
gboolean
*
* get a string representation for a date.
*
- *
- * Returns: the new display date. The string is *not* newly allocated,
- * but is a static buffer (for optimization reasons). Therefore, when
- * you call this function, you will loose the data.
+ * Returns: the new display date, as a constant string.
+ * must NOT be freed
*/
const gchar* modest_text_utils_get_display_date (time_t date);