More support for pre-Epoch dates for Windows.
authorAndrej Kacian <ticho@claws-mail.org>
Thu, 18 Aug 2016 23:44:39 +0000 (01:44 +0200)
committerAndrej Kacian <ticho@claws-mail.org>
Thu, 18 Aug 2016 23:44:39 +0000 (01:44 +0200)
get_rfc822_date_from_time_t() (vcalendar)
procheader_date_parse() (core)

src/plugins/vcalendar/vcal_manager.c
src/procheader.c

index 771c7318219c94a55a701edb7272d9eaa9321485..1432e0f36ee6640e5037e4d8f015dcd059f6eccb 100644 (file)
@@ -519,24 +519,24 @@ gchar *vcal_manager_event_dump(VCalEvent *event, gboolean is_reply, gboolean is_
 
 static void get_rfc822_date_from_time_t(gchar *buf, gint len, time_t t)
 {
+#ifndef G_OS_WIN32
        struct tm *lt;
        gchar day[4], mon[4];
        gint dd, hh, mm, ss, yyyy;
        gchar buft1[512];
        struct tm buft2;
 
-#ifndef G_OS_WIN32
        lt = localtime_r(&t, &buft2);
-#else
-       if (t < 0)
-               t = 1;
-       lt = localtime(&t);
-#endif
-
        sscanf(asctime_r(lt, buft1), "%3s %3s %d %d:%d:%d %d\n",
               day, mon, &dd, &hh, &mm, &ss, &yyyy);
        g_snprintf(buf, len, "%s, %d %s %d %02d:%02d:%02d %s",
                   day, dd, mon, yyyy, hh, mm, ss, tzoffset(&t));
+#else
+       GDateTime *dt = g_date_time_new_from_unix_local(t);
+       gchar *buf2 = g_date_time_format(dt, "%a, %e %b %Y %H:%M:%S %Z");
+       strncpy(buf, buf2, len);
+       g_free(buf2);
+#endif
 }
 
 static gchar *write_headers_date(const gchar *uid)
index be70c9fcfb1d09fba00874fe10e9646171544007..a9bfa5ddd058117ef2e93c2930b6decac56eff3a 100644 (file)
@@ -955,10 +955,8 @@ time_t procheader_date_parse(gchar *dest, const gchar *src, gint len)
        gint hh, mm, ss;
        gchar zone[7];
        GDateMonth dmonth = G_DATE_BAD_MONTH;
-       struct tm t;
        gchar *p;
        time_t timer;
-       time_t tz_offset;
 
        if (procheader_scan_date_string(src, weekday, &day, month, &year,
                                        &hh, &mm, &ss, zone) < 0) {
@@ -967,14 +965,6 @@ time_t procheader_date_parse(gchar *dest, const gchar *src, gint len)
                return 0;
        }
 
-       /* Y2K compliant :) */
-       if (year < 1000) {
-               if (year < 50)
-                       year += 2000;
-               else
-                       year += 1900;
-       }
-
        month[3] = '\0';
        for (p = monthstr; *p != '\0'; p += 3) {
                if (!g_ascii_strncasecmp(p, month, 3)) {
@@ -983,6 +973,30 @@ time_t procheader_date_parse(gchar *dest, const gchar *src, gint len)
                }
        }
 
+#ifdef G_OS_WIN32
+       GTimeZone *tz;
+       GDateTime *dt;
+
+       tz = g_time_zone_new(zone);
+       dt = g_date_time_new(tz, year, dmonth, day, hh, mm, ss);
+
+       timer = g_date_time_to_unix(dt);
+
+       g_date_time_unref(dt);
+       g_time_zone_unref(tz);
+
+#else
+       struct tm t;
+       time_t tz_offset;
+
+       /* Y2K compliant :) */
+       if (year < 1000) {
+               if (year < 50)
+                       year += 2000;
+               else
+                       year += 1900;
+       }
+
        t.tm_sec = ss;
        t.tm_min = mm;
        t.tm_hour = hh;
@@ -1000,6 +1014,7 @@ time_t procheader_date_parse(gchar *dest, const gchar *src, gint len)
 
        if (dest)
                procheader_date_get_localtime(dest, len, timer);
+#endif
 
        return timer;
 }