From: Andrej Kacian Date: Thu, 18 Aug 2016 23:44:39 +0000 (+0200) Subject: More support for pre-Epoch dates for Windows. X-Git-Tag: 3.14.1~121 X-Git-Url: http://git.claws-mail.org/?p=claws.git;a=commitdiff_plain;h=b84884479e197092efb1792331dd1c2170ec912b More support for pre-Epoch dates for Windows. get_rfc822_date_from_time_t() (vcalendar) procheader_date_parse() (core) --- diff --git a/src/plugins/vcalendar/vcal_manager.c b/src/plugins/vcalendar/vcal_manager.c index 771c73182..1432e0f36 100644 --- a/src/plugins/vcalendar/vcal_manager.c +++ b/src/plugins/vcalendar/vcal_manager.c @@ -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) diff --git a/src/procheader.c b/src/procheader.c index be70c9fcf..a9bfa5ddd 100644 --- a/src/procheader.c +++ b/src/procheader.c @@ -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; }