aboutsummaryrefslogtreecommitdiffstats
path: root/libempathy
diff options
context:
space:
mode:
authorGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>2011-04-19 17:06:52 +0800
committerDanielle Madeley <danielle.madeley@collabora.co.uk>2011-04-21 10:40:06 +0800
commit845c7de7a4caee49f6cea3b9f10f0df3db9d0971 (patch)
treec2fa2f7f28fc5fa8099e22cd635106b2ddc9aaca /libempathy
parent3aa72e42ffe1ce5068dfc5c351d05598f2884bea (diff)
downloadgsoc2013-empathy-845c7de7a4caee49f6cea3b9f10f0df3db9d0971.tar
gsoc2013-empathy-845c7de7a4caee49f6cea3b9f10f0df3db9d0971.tar.gz
gsoc2013-empathy-845c7de7a4caee49f6cea3b9f10f0df3db9d0971.tar.bz2
gsoc2013-empathy-845c7de7a4caee49f6cea3b9f10f0df3db9d0971.tar.lz
gsoc2013-empathy-845c7de7a4caee49f6cea3b9f10f0df3db9d0971.tar.xz
gsoc2013-empathy-845c7de7a4caee49f6cea3b9f10f0df3db9d0971.tar.zst
gsoc2013-empathy-845c7de7a4caee49f6cea3b9f10f0df3db9d0971.zip
Port all timestamps from time_t to gint64 (#648188)
Diffstat (limited to 'libempathy')
-rw-r--r--libempathy/empathy-ft-handler.c4
-rw-r--r--libempathy/empathy-message.c18
-rw-r--r--libempathy/empathy-message.h2
-rw-r--r--libempathy/empathy-time.c76
-rw-r--r--libempathy/empathy-time.h8
-rw-r--r--libempathy/empathy-tp-file.c2
6 files changed, 63 insertions, 47 deletions
diff --git a/libempathy/empathy-ft-handler.c b/libempathy/empathy-ft-handler.c
index 94b9cf3d4..26db91b07 100644
--- a/libempathy/empathy-ft-handler.c
+++ b/libempathy/empathy-ft-handler.c
@@ -144,7 +144,7 @@ typedef struct {
/* time and speed */
gdouble speed;
guint remaining_time;
- time_t last_update_time;
+ gint64 last_update_time;
gboolean is_completed;
} EmpathyFTHandlerPriv;
@@ -662,7 +662,7 @@ update_remaining_time_and_speed (EmpathyFTHandler *handler,
guint64 transferred_bytes)
{
EmpathyFTHandlerPriv *priv = GET_PRIV (handler);
- time_t elapsed_time, current_time;
+ gint64 elapsed_time, current_time;
guint64 transferred, last_transferred_bytes;
gdouble speed;
gint remaining_time;
diff --git a/libempathy/empathy-message.c b/libempathy/empathy-message.c
index 883c5e7bb..076a10053 100644
--- a/libempathy/empathy-message.c
+++ b/libempathy/empathy-message.c
@@ -44,7 +44,7 @@ typedef struct {
EmpathyContact *sender;
EmpathyContact *receiver;
gchar *body;
- time_t timestamp;
+ gint64 timestamp;
gboolean is_backlog;
guint id;
gboolean incoming;
@@ -119,12 +119,10 @@ empathy_message_class_init (EmpathyMessageClass *class)
G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property (object_class,
PROP_TIMESTAMP,
- g_param_spec_long ("timestamp",
+ g_param_spec_int64 ("timestamp",
"timestamp",
"timestamp",
- -1,
- G_MAXLONG,
- -1,
+ G_MININT64, G_MAXINT64, 0,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS |
G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property (object_class,
@@ -212,7 +210,7 @@ message_get_property (GObject *object,
g_value_set_string (value, priv->body);
break;
case PROP_TIMESTAMP:
- g_value_set_long (value, priv->timestamp);
+ g_value_set_int64 (value, priv->timestamp);
break;
case PROP_IS_BACKLOG:
g_value_set_boolean (value, priv->is_backlog);
@@ -256,7 +254,7 @@ message_set_property (GObject *object,
priv->body = g_value_dup_string (value);
break;
case PROP_TIMESTAMP:
- priv->timestamp = g_value_get_long (value);
+ priv->timestamp = g_value_get_int64 (value);
if (priv->timestamp <= 0)
priv->timestamp = empathy_time_get_current ();
break;
@@ -324,7 +322,7 @@ empathy_message_from_tpl_log_event (TplEvent *logevent)
"type", tpl_text_event_get_message_type (TPL_TEXT_EVENT (logevent)),
"body", body,
"is-backlog", TRUE,
- "timestamp", (glong) tpl_event_get_timestamp (logevent),
+ "timestamp", tpl_event_get_timestamp (logevent),
NULL);
if (receiver != NULL) {
@@ -435,7 +433,7 @@ empathy_message_get_body (EmpathyMessage *message)
return priv->body;
}
-time_t
+gint64
empathy_message_get_timestamp (EmpathyMessage *message)
{
EmpathyMessagePriv *priv;
@@ -632,7 +630,7 @@ empathy_message_new_from_tp_message (TpMessage *tp_msg,
message = g_object_new (EMPATHY_TYPE_MESSAGE,
"body", body,
"type", tp_message_get_message_type (tp_msg),
- "timestamp", (glong) tp_message_get_received_timestamp (tp_msg),
+ "timestamp", tp_message_get_received_timestamp (tp_msg),
"flags", flags,
"is-backlog", flags & TP_CHANNEL_TEXT_MESSAGE_FLAG_SCROLLBACK,
"incoming", incoming,
diff --git a/libempathy/empathy-message.h b/libempathy/empathy-message.h
index bba65aeb2..7508cb08e 100644
--- a/libempathy/empathy-message.h
+++ b/libempathy/empathy-message.h
@@ -67,7 +67,7 @@ EmpathyContact * empathy_message_get_receiver (EmpathyMessage
void empathy_message_set_receiver (EmpathyMessage *message,
EmpathyContact *contact);
const gchar * empathy_message_get_body (EmpathyMessage *message);
-time_t empathy_message_get_timestamp (EmpathyMessage *message);
+gint64 empathy_message_get_timestamp (EmpathyMessage *message);
gboolean empathy_message_is_backlog (EmpathyMessage *message);
gboolean empathy_message_is_incoming (EmpathyMessage *message);
diff --git a/libempathy/empathy-time.c b/libempathy/empathy-time.c
index b0ad01888..f33152d97 100644
--- a/libempathy/empathy-time.c
+++ b/libempathy/empathy-time.c
@@ -31,89 +31,107 @@
/* Note: EmpathyTime is always in UTC. */
-time_t
+gint64
empathy_time_get_current (void)
{
- return time (NULL);
+ GDateTime *now;
+ gint64 result;
+
+ now = g_date_time_new_now_utc ();
+ result = g_date_time_to_unix (now);
+ g_date_time_unref (now);
+
+ return result;
}
/* Converts the UTC timestamp to a string, also in UTC. Returns NULL on failure. */
gchar *
-empathy_time_to_string_utc (time_t t,
+empathy_time_to_string_utc (gint64 t,
const gchar *format)
{
- gchar stamp[128];
- struct tm *tm;
+ GDateTime *d;
+ char *result;
g_return_val_if_fail (format != NULL, NULL);
- tm = gmtime (&t);
- if (strftime (stamp, sizeof (stamp), format, tm) == 0) {
- return NULL;
- }
+ d = g_date_time_new_from_unix_utc (t);
+ result = g_date_time_format (d, format);
+ g_date_time_unref (d);
- return g_strdup (stamp);
+ return result;
}
/* Converts the UTC timestamp to a string, in local time. Returns NULL on failure. */
gchar *
-empathy_time_to_string_local (time_t t,
+empathy_time_to_string_local (gint64 t,
const gchar *format)
{
- gchar stamp[128];
- struct tm *tm;
+ GDateTime *d, *local;
+ gchar *result;
g_return_val_if_fail (format != NULL, NULL);
- tm = localtime (&t);
- if (strftime (stamp, sizeof (stamp), format, tm) == 0) {
- return NULL;
- }
+ d = g_date_time_new_from_unix_utc (t);
+ local = g_date_time_to_local (d);
+ g_date_time_unref (d);
- return g_strdup (stamp);
+ result = g_date_time_format (local, format);
+ g_date_time_unref (local);
+
+ return result;
}
gchar *
-empathy_time_to_string_relative (time_t then)
+empathy_time_to_string_relative (gint64 t)
{
- time_t now;
+ GDateTime *now, *then;
gint seconds;
+ GTimeSpan delta;
+ gchar *result;
+
+ now = g_date_time_new_now_utc ();
+ then = g_date_time_new_from_unix_utc (t);
- now = time (NULL);
- seconds = now - then;
+ delta = g_date_time_difference (now, then);
+ seconds = delta / G_TIME_SPAN_SECOND;
if (seconds > 0) {
if (seconds < 60) {
- return g_strdup_printf (ngettext ("%d second ago",
+ result = g_strdup_printf (ngettext ("%d second ago",
"%d seconds ago", seconds), seconds);
}
else if (seconds < (60 * 60)) {
seconds /= 60;
- return g_strdup_printf (ngettext ("%d minute ago",
+ result = g_strdup_printf (ngettext ("%d minute ago",
"%d minutes ago", seconds), seconds);
}
else if (seconds < (60 * 60 * 24)) {
seconds /= 60 * 60;
- return g_strdup_printf (ngettext ("%d hour ago",
+ result = g_strdup_printf (ngettext ("%d hour ago",
"%d hours ago", seconds), seconds);
}
else if (seconds < (60 * 60 * 24 * 7)) {
seconds /= 60 * 60 * 24;
- return g_strdup_printf (ngettext ("%d day ago",
+ result = g_strdup_printf (ngettext ("%d day ago",
"%d days ago", seconds), seconds);
}
else if (seconds < (60 * 60 * 24 * 30)) {
seconds /= 60 * 60 * 24 * 7;
- return g_strdup_printf (ngettext ("%d week ago",
+ result = g_strdup_printf (ngettext ("%d week ago",
"%d weeks ago", seconds), seconds);
}
else {
seconds /= 60 * 60 * 24 * 30;
- return g_strdup_printf (ngettext ("%d month ago",
+ result = g_strdup_printf (ngettext ("%d month ago",
"%d months ago", seconds), seconds);
}
}
else {
- return g_strdup (_("in the future"));
+ result = g_strdup (_("in the future"));
}
+
+ g_date_time_unref (now);
+ g_date_time_unref (then);
+
+ return result;
}
diff --git a/libempathy/empathy-time.h b/libempathy/empathy-time.h
index 5c20a6a5a..7fac48221 100644
--- a/libempathy/empathy-time.h
+++ b/libempathy/empathy-time.h
@@ -39,12 +39,12 @@ G_BEGIN_DECLS
#define EMPATHY_DATE_FORMAT_DISPLAY_SHORT _("%a %d %b %Y")
#define EMPATHY_TIME_DATE_FORMAT_DISPLAY_SHORT _("%a %d %b %Y, %H:%M")
-time_t empathy_time_get_current (void);
-gchar *empathy_time_to_string_utc (time_t t,
+gint64 empathy_time_get_current (void);
+gchar *empathy_time_to_string_utc (gint64 t,
const gchar *format);
-gchar *empathy_time_to_string_local (time_t t,
+gchar *empathy_time_to_string_local (gint64 t,
const gchar *format);
-gchar *empathy_time_to_string_relative (time_t t);
+gchar *empathy_time_to_string_relative (gint64 t);
G_END_DECLS
diff --git a/libempathy/empathy-tp-file.c b/libempathy/empathy-tp-file.c
index d69b2153a..3bb2dd49c 100644
--- a/libempathy/empathy-tp-file.c
+++ b/libempathy/empathy-tp-file.c
@@ -79,7 +79,7 @@ struct _EmpathyTpFilePrivate {
/* transfer properties */
gboolean incoming;
- time_t start_time;
+ gint64 start_time;
GArray *socket_address;
guint port;
guint64 offset;