From f64d42bba5abdd12dc9c815193230f6e71f32cc4 Mon Sep 17 00:00:00 2001
From: =?utf-8?q?Eli=C3=A1n=20Hanisch?= <lambdae2@gmail.com>
Date: Fri, 11 Sep 2009 13:54:39 -0300
Subject: [PATCH] localised datestamps

replaces ctime calls for a function that accounts localization when generating
the date strings
---
 src/core/wee-command.c         |   10 +++++-----
 src/core/wee-util.c            |   15 +++++++++++++++
 src/core/wee-util.h            |    1 +
 src/plugins/irc/irc-protocol.c |   18 +++++++++---------
 4 files changed, 30 insertions(+), 14 deletions(-)

diff --git a/src/core/wee-command.c b/src/core/wee-command.c
index dc7358b..300e4cf 100644
--- a/src/core/wee-command.c
+++ b/src/core/wee-command.c
@@ -27,7 +27,6 @@
 #include <stdlib.h>
 #include <string.h>
 #include <ctype.h>
-#include <time.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 
@@ -40,6 +39,7 @@
 #include "wee-input.h"
 #include "wee-log.h"
 #include "wee-proxy.h"
+#include "wee-util.h"
 #include "wee-string.h"
 #include "wee-upgrade.h"
 #include "wee-utf8.h"
@@ -3408,7 +3408,7 @@ command_uptime (void *data, struct t_gui_buffer *buffer,
                   hour,
                   min,
                   sec,
-                  ctime (&weechat_start_time));
+                  util_get_time_string (&weechat_start_time));
         string[strlen (string) - 1] = '\0';
         input_data (buffer, string);
     }
@@ -3432,7 +3432,7 @@ command_uptime (void *data, struct t_gui_buffer *buffer,
                          sec,
                          GUI_COLOR(GUI_COLOR_CHAT),
                          GUI_COLOR(GUI_COLOR_CHAT_BUFFER),
-                         ctime (&weechat_start_time));
+                         util_get_time_string (&weechat_start_time));
     }
     
     return WEECHAT_RC_OK;
@@ -3463,7 +3463,7 @@ command_version_display (struct t_gui_buffer *buffer,
                       _("Upgraded %d %s, first start: %s"),
                       weechat_upgrade_count,
                       NG_("time", "times", weechat_upgrade_count),
-                      ctime (&weechat_start_time));
+                      util_get_time_string (&weechat_start_time));
             string[strlen (string) - 1] = '\0';
             input_data (buffer, string);
         }
@@ -3486,7 +3486,7 @@ command_version_display (struct t_gui_buffer *buffer,
                              weechat_upgrade_count,
                              /* TRANSLATORS: text is: "upgraded xx times" */
                              NG_("time", "times", weechat_upgrade_count),
-                             ctime (&weechat_start_time));
+                             util_get_time_string (&weechat_start_time));
         }
     }
 }
diff --git a/src/core/wee-util.c b/src/core/wee-util.c
index bfdc38b..64bba92 100644
--- a/src/core/wee-util.c
+++ b/src/core/wee-util.c
@@ -124,6 +124,21 @@ util_get_time_length (const char *time_format)
 }
 
 /*
+ * util_get_time_string: converts calendar time to a string, accounting localization
+ */
+
+char *
+util_get_time_string (const time_t *date)
+{
+    struct tm *local_time;
+    static char text_time[128];
+
+    local_time = localtime(date);
+    strftime(text_time, sizeof (text_time), "%a %b %d %T %Y", local_time);
+    return text_time;
+}
+
+/*
  * util_catch_signal: catch a signal
  */
 
diff --git a/src/core/wee-util.h b/src/core/wee-util.h
index 03932a5..8766129 100644
--- a/src/core/wee-util.h
+++ b/src/core/wee-util.h
@@ -24,6 +24,7 @@ extern int util_timeval_cmp (struct timeval *tv1, struct timeval *tv2);
 extern long util_timeval_diff (struct timeval *tv1, struct timeval *tv2);
 extern void util_timeval_add (struct timeval *tv, long interval);
 extern int util_get_time_length (const char *time_format);
+extern char *util_get_time_string (const time_t *time);
 extern void util_catch_signal (int signum, void (*handler)(int));
 extern int util_mkdir_home (const char *directory, int mode);
 extern int util_mkdir (const char *directory, int mode);
diff --git a/src/plugins/irc/irc-protocol.c b/src/plugins/irc/irc-protocol.c
index 9e31fb2..e811864 100644
--- a/src/plugins/irc/irc-protocol.c
+++ b/src/plugins/irc/irc-protocol.c
@@ -29,9 +29,9 @@
 #include <string.h>
 #include <ctype.h>
 #include <sys/time.h>
-#include <time.h>
 
 #include "../weechat-plugin.h"
+#include "../../core/wee-util.h"
 #include "irc.h"
 #include "irc-protocol.h"
 #include "irc-buffer.h"
@@ -2930,7 +2930,7 @@ irc_protocol_cmd_317 (struct t_irc_server *server, const char *command,
                              IRC_COLOR_CHAT,
                              NG_("second", "seconds", sec),
                              IRC_COLOR_CHAT_CHANNEL,
-                             ctime (&datetime));
+                             util_get_time_string (&datetime));
     }
     else
     {
@@ -2958,7 +2958,7 @@ irc_protocol_cmd_317 (struct t_irc_server *server, const char *command,
                              IRC_COLOR_CHAT,
                              NG_("second", "seconds", sec),
                              IRC_COLOR_CHAT_CHANNEL,
-                             ctime (&datetime));
+                             util_get_time_string (&datetime));
     }
     
     return WEECHAT_RC_OK;
@@ -3223,7 +3223,7 @@ irc_protocol_cmd_329 (struct t_irc_server *server, const char *command,
                                  irc_protocol_tags (command, "irc_numeric"),
                                  _("%sChannel created on %s"),
                                  weechat_prefix ("network"),
-                                 ctime (&datetime));
+                                 util_get_time_string (&datetime));
             ptr_channel->display_creation_date = 0;
         }
     }
@@ -3236,7 +3236,7 @@ irc_protocol_cmd_329 (struct t_irc_server *server, const char *command,
                              IRC_COLOR_CHAT_CHANNEL,
                              argv[3],
                              IRC_COLOR_CHAT,
-                             ctime (&datetime));
+                             util_get_time_string (&datetime));
     }
     
     return WEECHAT_RC_OK;
@@ -3387,7 +3387,7 @@ irc_protocol_cmd_333 (struct t_irc_server *server, const char *command,
                              IRC_COLOR_NICK_IN_SERVER_MESSAGE(ptr_nick),
                              argv[4],
                              IRC_COLOR_CHAT,
-                             ctime (&datetime));
+                             util_get_time_string (&datetime));
     }
     else
     {
@@ -3401,7 +3401,7 @@ irc_protocol_cmd_333 (struct t_irc_server *server, const char *command,
                              IRC_COLOR_NICK_IN_SERVER_MESSAGE(ptr_nick),
                              argv[4],
                              IRC_COLOR_CHAT,
-                             ctime (&datetime));
+                             util_get_time_string (&datetime));
     }
     
     return WEECHAT_RC_OK;
@@ -3571,7 +3571,7 @@ irc_protocol_cmd_348 (struct t_irc_server *server, const char *command,
                              irc_protocol_get_address_from_host (argv[5]),
                              IRC_COLOR_CHAT_DELIMITERS,
                              IRC_COLOR_CHAT,
-                             ctime (&datetime));
+                             util_get_time_string (&datetime));
     }
     else
     {
@@ -4069,7 +4069,7 @@ irc_protocol_cmd_367 (struct t_irc_server *server, const char *command,
                              irc_protocol_get_address_from_host (argv[5]),
                              IRC_COLOR_CHAT_DELIMITERS,
                              IRC_COLOR_CHAT,
-                             ctime (&datetime));
+                             util_get_time_string (&datetime));
     }
     else
     {
-- 
1.6.0.4

