diff -ur telepathy-logger-0.1.5/telepathy-logger/datetime.c telepathy-logger-0.1.5.patched//telepathy-logger/datetime.c --- telepathy-logger-0.1.5/telepathy-logger/datetime.c 2010-08-11 15:35:33.000000000 +0400 +++ telepathy-logger-0.1.5.patched//telepathy-logger/datetime.c 2010-09-23 18:06:32.000000000 +0400 @@ -125,3 +125,24 @@ return g_strdup (stamp); } + +/* Converts the UTC timestamp to a local timestamp. */ +time_t +_tpl_time_to_local (time_t t) +{ + return _tpl_time_get_local_time (localtime (&t)); +} + + +/* Returns offset in seconds between the local time and UTC. */ +double +_tpl_time_get_tz_offset (void) +{ + struct tm *tm; + time_t t; + + t = time (NULL); + tm = localtime (&t); + + return difftime (_tpl_time_get_local_time (tm), t); +} diff -ur telepathy-logger-0.1.5/telepathy-logger/datetime-internal.h telepathy-logger-0.1.5.patched//telepathy-logger/datetime-internal.h --- telepathy-logger-0.1.5/telepathy-logger/datetime-internal.h 2010-08-11 15:35:33.000000000 +0400 +++ telepathy-logger-0.1.5.patched//telepathy-logger/datetime-internal.h 2010-09-23 17:54:31.000000000 +0400 @@ -37,6 +37,8 @@ time_t _tpl_time_parse (const gchar * str); gchar *_tpl_time_to_string_utc (time_t t, const gchar * format); gchar *_tpl_time_to_string_local (time_t t, const gchar * format); +time_t _tpl_time_to_local (time_t t); +double _tpl_time_get_tz_offset (void); G_END_DECLS #endif /* __TPL_TIME_H__ */ diff -ur telepathy-logger-0.1.5/telepathy-logger/log-manager.c telepathy-logger-0.1.5.patched//telepathy-logger/log-manager.c --- telepathy-logger-0.1.5/telepathy-logger/log-manager.c 2010-08-11 13:36:26.000000000 +0400 +++ telepathy-logger-0.1.5.patched//telepathy-logger/log-manager.c 2010-09-23 17:52:10.000000000 +0400 @@ -479,6 +479,26 @@ } +static gint +log_manager_message_date_cmp (gconstpointer a, + gconstpointer b) +{ + TplEntry *one = (TplEntry *) a; + TplEntry *two = (TplEntry *) b; + gint64 one_time, two_time; + + g_assert (TPL_IS_ENTRY (one)); + g_assert (TPL_IS_ENTRY (two)); + + one_time = tpl_entry_get_timestamp (one); + two_time = tpl_entry_get_timestamp (two); + + /* return -1, o or 1 depending on message1 is newer, the same or older than + * message2 */ + return CLAMP (one_time - two_time, -1, 1); +} + + GList * _tpl_log_manager_get_messages_for_date (TplLogManager *manager, TpAccount *account, @@ -486,8 +506,10 @@ gboolean chatroom, const GDate *date) { - GList *l, *out = NULL; + GList *l, *out = NULL, *redundant = NULL; TplLogManagerPriv *priv; + GDate *additional_date, *entry_date; + double tz_offset; g_return_val_if_fail (TPL_IS_LOG_MANAGER (manager), NULL); g_return_val_if_fail (chat_id != NULL, NULL); @@ -502,27 +524,47 @@ account, chat_id, chatroom, date)); } - return out; -} - + tz_offset = _tpl_time_get_tz_offset(); -static gint -log_manager_message_date_cmp (gconstpointer a, - gconstpointer b) -{ - TplEntry *one = (TplEntry *) a; - TplEntry *two = (TplEntry *) b; - gint64 one_time, two_time; + if (tz_offset != 0) + { + redundant = out; + out = NULL; - g_assert (TPL_IS_ENTRY (one)); - g_assert (TPL_IS_ENTRY (two)); + additional_date = g_date_new_julian (g_date_get_julian (date)); + if (tz_offset < 0) + g_date_add_days (additional_date, 1); + else + g_date_subtract_days (additional_date, 1); + + for (l = priv->readable_stores; l != NULL; l = g_list_next (l)) + { + TplLogStore *store = TPL_LOG_STORE (l->data); + + redundant = g_list_concat (redundant, + _tpl_log_store_get_messages_for_date (store, account, chat_id, + chatroom, additional_date)); + } + + entry_date = g_date_new (); + + for (l = redundant; l; l = l->next) + { + g_date_set_time_t (entry_date, + _tpl_time_to_local (tpl_entry_get_timestamp (l->data))); + + if (!g_date_compare (entry_date, date)) + out = g_list_insert_sorted (out, l->data, + (GCompareFunc) log_manager_message_date_cmp); + else + g_object_unref (l->data); + } - one_time = tpl_entry_get_timestamp (one); - two_time = tpl_entry_get_timestamp (two); + g_date_free (entry_date); + g_list_free (redundant); + } - /* return -1, o or 1 depending on message1 is newer, the same or older than - * message2 */ - return CLAMP (one_time - two_time, -1, 1); + return out; }