changeset 125:f0305c387d32

replaced troublesome strptime() with our own function read_timestamp().
author Yoshiki Yazawa <yaz@honeyplanet.jp>
date Sat, 19 Jul 2008 11:33:17 +0900
parents ec861f8a2268
children bac987852e66
files pidgin-twitter.c pidgin-twitter.h
diffstat 2 files changed, 74 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/pidgin-twitter.c	Fri Jul 18 20:03:59 2008 +0900
+++ b/pidgin-twitter.c	Sat Jul 19 11:33:17 2008 +0900
@@ -294,6 +294,74 @@
     }
 }
 
+static char *day_of_week_name[] = {
+    "Sun",
+    "Mon",
+    "Tue",
+    "Wed",
+    "Thu",
+    "Fri",
+    "Sat",
+    "Sun",
+    NULL
+};
+
+static char *month_name[] = {
+    "Jan",
+    "Feb",
+    "Mar",
+    "Apr",
+    "May",
+    "Jun",
+    "Jul",
+    "Aug",
+    "Sep",
+    "Oct",
+    "Nov",
+    "Dec",
+    NULL
+};
+
+static void
+read_timestamp(const char *str, struct tm *res)
+{
+    char day_of_week[4];
+    char month[4];
+    char time_offset[6];
+    int day, hour, minute, second, year;
+    int i;
+
+    if(str == NULL || res == NULL)
+        return;
+
+    sscanf(str, "%s %s %d %d:%d:%d %s %d",
+           day_of_week, month, &day,
+           &hour, &minute, &second,
+           time_offset, &year);
+
+    for(i=0; i<7; i++) {
+        if(!strcmp(day_of_week_name[i], day_of_week)) {
+            res->tm_wday = i;
+        }
+    }
+    for(i=0; i<12; i++) {
+        if(!strcmp(month_name[i], month)) {
+            res->tm_mon = i;
+        }
+    }
+
+    res->tm_mday = day;
+    res->tm_hour = hour;
+    res->tm_min  = minute;
+    res->tm_sec  = second;
+    res->tm_year = year - 1900;
+#ifndef _WIN32
+    int offset   = atoi(time_offset);
+    res->tm_gmtoff = -1 * (60 * 60 * offset / 100);
+#endif
+
+}
+
 static void
 parse_status(xmlNode *status, status_t *st)
 {
@@ -305,19 +373,16 @@
                 gchar *str = (gchar *)xmlNodeGetContent(nptr);
                 st->created_at = g_strdup(str);
 
-                /* set locale to C */
-                gchar *lc_time = setlocale(LC_TIME, NULL);
-                setlocale(LC_TIME, "C");
-
                 /* read time stamp */
                 struct tm res;
                 memset(&res, 0x00, sizeof(struct tm));
-                strptime(str, "%a %b %d %T %z %Y", &res);
+                read_timestamp(str, &res);
                 tzset();
+#ifdef _WIN32
+                st->time = mktime(&res) - timezone;
+#else
                 st->time = mktime(&res) + res.tm_gmtoff;
-
-                /* restore locale */
-                setlocale(LC_TIME, lc_time);
+#endif
 
                 xmlFree(str);
             }
--- a/pidgin-twitter.h	Fri Jul 18 20:03:59 2008 +0900
+++ b/pidgin-twitter.h	Sat Jul 19 11:33:17 2008 +0900
@@ -202,5 +202,6 @@
 static void parse_status(xmlNode *status, status_t *st);
 static void get_status_with_api_cb(PurpleUtilFetchUrlData *url_data, gpointer user_data, const gchar *url_text, size_t len, const gchar *error_message);
 static gboolean get_status_with_api(gpointer data);
+static void read_timestamp(const char *str, struct tm *res);
 
 #endif