pidgin/pidgin

e9573eaa68f9
Parents df346d4c3074
Children eb0f386cea6b
Start replacing time utility functions with GDateTime

Replace some of the utility time functions with g_date_time functions.

Testing Done:
Compile only.

Reviewed at https://reviews.imfreedom.org/r/152/
--- a/ChangeLog.API Mon Oct 12 20:54:13 2020 -0500
+++ b/ChangeLog.API Mon Oct 12 20:57:09 2020 -0500
@@ -369,6 +369,8 @@
or whatever is appropriate for your UI.
* purple_core_migrate
* Removed the general Purple DBus interface
+ * purple_date_format_long, use g_date_time_format instead.
+ * purple_date_format_short, use g_date_time_format instead.
* purple_dnsquery_a_account
* purple_event_loop_{get|set}_ui_ops. Manually drive the GLib
event loop yourself. See GLib Main Event Loop docs.
@@ -513,6 +515,8 @@
* purple_str_has_prefix. Use g_str_has_prefix instead
* purple_str_has_suffix. Use g_str_has_suffix instead
* purple_str_size_to_units. Use g_format_size() instead.
+ * purple_time_build. Use g_date_time_new* instead.
+ * purple_time_format. Use g_date_time_format instead.
* purple_timeout_*. Use g_timeout_* or g_idle_* instead.
* purple_txt_cancel
* purple_txt_resolve_account
--- a/libpurple/protocols/irc/msgs.c Mon Oct 12 20:54:13 2020 -0500
+++ b/libpurple/protocols/irc/msgs.c Mon Oct 12 20:57:09 2020 -0500
@@ -606,8 +606,8 @@
void irc_msg_topicinfo(struct irc_conn *irc, const char *name, const char *from, char **args)
{
PurpleChatConversation *chat;
- struct tm *tm;
- time_t t;
+ GDateTime *dt, *local;
+ gint64 mtime;
char *msg, *timestamp, *datestamp;
chat = purple_conversations_find_chat_with_account(args[1], irc->account);
@@ -616,21 +616,30 @@
return;
}
- t = (time_t)atol(args[3]);
- if (t == 0) {
+ mtime = g_ascii_strtoll(args[3], NULL, 10);
+ if(mtime == 0 || mtime == G_MININT64 || mtime == G_MAXINT64) {
purple_debug(PURPLE_DEBUG_ERROR, "irc", "Got apparently nonsensical topic timestamp %s\n", args[3]);
return;
}
- tm = localtime(&t);
- timestamp = g_strdup(purple_time_format(tm));
- datestamp = g_strdup(purple_date_format_short(tm));
+ dt = g_date_time_new_from_unix_utc(mtime);
+ if(dt == NULL) {
+ purple_debug(PURPLE_DEBUG_ERROR, "irc", "Failed to turn %" G_GINT64_FORMAT " into a GDateTime\n", mtime);
+ return;
+ }
+
+ local = g_date_time_to_local(dt);
+ g_date_time_unref(dt);
+
+ timestamp = g_date_time_format(local, "%X");
+ datestamp = g_date_time_format(local, "%x");
msg = g_strdup_printf(_("Topic for %s set by %s at %s on %s"), args[1], args[2], timestamp, datestamp);
purple_conversation_write_system_message(PURPLE_CONVERSATION(chat),
msg, PURPLE_MESSAGE_NO_LINKIFY);
g_free(timestamp);
g_free(datestamp);
g_free(msg);
+ g_date_time_unref(local);
}
void irc_msg_unknown(struct irc_conn *irc, const char *name, const char *from, char **args)
--- a/libpurple/protocols/jabber/buddy.c Mon Oct 12 20:54:13 2020 -0500
+++ b/libpurple/protocols/jabber/buddy.c Mon Oct 12 20:57:09 2020 -0500
@@ -739,17 +739,17 @@
}
if (jbr && jbr->tz_off != PURPLE_NO_TZ_OFF) {
- time_t now_t;
- struct tm *now;
- char *timestamp;
- time(&now_t);
- now_t += jbr->tz_off;
- now = gmtime(&now_t);
+ GDateTime *dt = NULL;
+ GTimeZone *tz = NULL;
+ char *timestamp = NULL;
- timestamp = g_strdup_printf("%s %c%02d%02d", purple_time_format(now),
- jbr->tz_off < 0 ? '-' : '+',
- abs((int)(jbr->tz_off / (60 * 60))),
- abs((int)((jbr->tz_off % (60 * 60)) / 60)));
+ tz = g_time_zone_new_offset(jbr->tz_off);
+ dt = g_date_time_new_now(tz);
+ g_time_zone_unref(tz);
+
+ timestamp = g_date_time_format(dt, "%X %:z");
+ g_date_time_unref(dt);
+
purple_notify_user_info_prepend_pair_plaintext(user_info, _("Local Time"), timestamp);
g_free(timestamp);
}
--- a/libpurple/util.c Mon Oct 12 20:54:13 2020 -0500
+++ b/libpurple/util.c Mon Oct 12 20:57:09 2020 -0500
@@ -101,50 +101,11 @@
}
const char *
-purple_date_format_short(const struct tm *tm)
-{
- return purple_utf8_strftime("%x", tm);
-}
-
-const char *
-purple_date_format_long(const struct tm *tm)
-{
- /*
- * This string determines how some dates are displayed. The default
- * string "%x %X" shows the date then the time. Translators can
- * change this to "%X %x" if they want the time to be shown first,
- * followed by the date.
- */
- return purple_utf8_strftime(_("%x %X"), tm);
-}
-
-const char *
purple_date_format_full(const struct tm *tm)
{
return purple_utf8_strftime("%c", tm);
}
-const char *
-purple_time_format(const struct tm *tm)
-{
- return purple_utf8_strftime("%X", tm);
-}
-
-time_t
-purple_time_build(int year, int month, int day, int hour, int min, int sec)
-{
- struct tm tm;
-
- tm.tm_year = year - 1900;
- tm.tm_mon = month - 1;
- tm.tm_mday = day;
- tm.tm_hour = hour;
- tm.tm_min = min;
- tm.tm_sec = sec >= 0 ? sec : time(NULL) % 60;
-
- return mktime(&tm);
-}
-
/* originally taken from GLib trunk 1-6-11 */
/* originally licensed as LGPL 2+ */
static time_t
--- a/libpurple/util.h Mon Oct 12 20:54:13 2020 -0500
+++ b/libpurple/util.h Mon Oct 12 20:57:09 2020 -0500
@@ -125,34 +125,6 @@
const char *purple_utf8_strftime(const char *format, const struct tm *tm);
/**
- * purple_date_format_short:
- * @tm: The time to format, or %NULL to use the current local time
- *
- * Formats a time into the user's preferred short date format.
- *
- * The returned string is stored in a static buffer, so the result
- * should be g_strdup()'d if it's going to be kept.
- *
- * Returns: The date, formatted as per the user's settings. In the USA this
- * is something like "02/18/13"
- */
-const char *purple_date_format_short(const struct tm *tm);
-
-/**
- * purple_date_format_long:
- * @tm: The time to format, or %NULL to use the current local time
- *
- * Formats a time into the user's preferred short date plus time format.
- *
- * The returned string is stored in a static buffer, so the result
- * should be g_strdup()'d if it's going to be kept.
- *
- * Returns: The timestamp, formatted as per the user's settings. In the USA
- * this is something like "02/18/13 15:26:44"
- */
-const char *purple_date_format_long(const struct tm *tm);
-
-/**
* purple_date_format_full:
* @tm: The time to format, or %NULL to use the current local time
*
@@ -167,36 +139,6 @@
const char *purple_date_format_full(const struct tm *tm);
/**
- * purple_time_format:
- * @tm: The time to format, or %NULL to use the current local time
- *
- * Formats a time into the user's preferred time format.
- *
- * The returned string is stored in a static buffer, so the result
- * should be g_strdup()'d if it's going to be kept.
- *
- * Returns: The time, formatted as per the user's settings. In the USA this
- * is something like "15:26:44"
- */
-const char *purple_time_format(const struct tm *tm);
-
-/**
- * purple_time_build:
- * @year: The year.
- * @month: The month.
- * @day: The day.
- * @hour: The hour.
- * @min: The minute.
- * @sec: The second.
- *
- * Builds a time_t from the supplied information.
- *
- * Returns: A time_t.
- */
-time_t purple_time_build(int year, int month, int day, int hour,
- int min, int sec);
-
-/**
* PURPLE_NO_TZ_OFF:
*
* Used by purple_str_to_time to indicate no timezone offset was
--- a/pidgin/gtkblist.c Mon Oct 12 20:54:13 2020 -0500
+++ b/pidgin/gtkblist.c Mon Oct 12 20:57:09 2020 -0500
@@ -3434,9 +3434,17 @@
* must be wrong, show the actual date instead of
* "4 days", etc.
*/
- tmp = g_strdup(purple_date_format_long(localtime(&signon)));
- } else
+ GDateTime *dt = NULL, *local = NULL;
+
+ dt = g_date_time_new_from_unix_utc(signon);
+ local = g_date_time_to_local(dt);
+ g_date_time_unref(dt);
+
+ tmp = g_date_time_format(local, _("%x %X"));
+ g_date_time_unref(local);
+ } else {
tmp = purple_str_seconds_to_string(time(NULL) - signon);
+ }
purple_notify_user_info_add_pair_plaintext(user_info, _("Logged In"), tmp);
g_free(tmp);
}