talons

Fork of Claws Mail https://www.claws-mail
Log | Files | Refs | README | LICENSE

commit 7635e2f51c93610b93b3150be91957ad1a2f73d5
parent 3813793f54f8b77bee519f827b8493776c0ef50b
Author: Andrej Kacian <ticho@claws-mail.org>
Date:   Fri, 19 Aug 2016 18:50:53 +0200

More fixes for parsing dates in vcalendar on Windows.

...this time without all the i18n updates.

Diffstat:
Msrc/plugins/vcalendar/libical/libical/icalduration.c | 36+++++++++++++++++++++++++++++++++++-
Msrc/plugins/vcalendar/libical/libical/icaltime.c | 2+-
Msrc/plugins/vcalendar/vcal_manager.c | 19++++++++++++++++---
3 files changed, 52 insertions(+), 5 deletions(-)

diff --git a/src/plugins/vcalendar/libical/libical/icalduration.c b/src/plugins/vcalendar/libical/libical/icalduration.c @@ -31,6 +31,8 @@ #include "icalduration.h" +#include <glib.h> + #include <assert.h> #include <string.h> #include <stdlib.h> @@ -299,10 +301,42 @@ struct icaltimetype icaltime_add(struct icaltimetype t, { int dt = icaldurationtype_as_int(d); +#ifdef G_OS_WIN32 + GTimeZone *zone; + GDateTime *dtm; + + if (t.is_utc == 1) + zone = g_time_zone_new_utc(); + else + zone = g_time_zone_new_local(); + + dtm = g_date_time_new( + zone, + t.year, + t.month, + t.day, + t.hour, + t.minute, + t.second); + + GDateTime *d2 = g_date_time_add_seconds(dtm, dt); + + t.year = g_date_time_get_year(d2); + t.month = g_date_time_get_month(d2); + t.day = g_date_time_get_day_of_month(d2); + t.hour = g_date_time_get_hour(d2); + t.minute = g_date_time_get_minute(d2); + t.second = g_date_time_get_second(d2); + + g_date_time_unref(dtm); + g_date_time_unref(d2); + g_time_zone_unref(zone); +#else t.second += dt; t = icaltime_normalize(t); - +#endif + return t; } diff --git a/src/plugins/vcalendar/libical/libical/icaltime.c b/src/plugins/vcalendar/libical/libical/icaltime.c @@ -538,7 +538,7 @@ short icaltime_day_of_year(struct icaltimetype t){ if (dt == NULL) return 1; - gint doy = g_date_time_get_day_of_year(dt); + gint doy = g_date_time_get_day_of_year(dt) - 1; g_date_time_unref(dt); g_time_zone_unref(zone); diff --git a/src/plugins/vcalendar/vcal_manager.c b/src/plugins/vcalendar/vcal_manager.c @@ -533,7 +533,8 @@ static void get_rfc822_date_from_time_t(gchar *buf, gint len, time_t t) 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"); + gchar *buf2 = g_date_time_format(dt, "%a, %e %b %Y %H:%M:%S %z"); + g_date_time_unref(dt); strncpy(buf, buf2, len); g_free(buf2); #endif @@ -546,7 +547,6 @@ static gchar *write_headers_date(const gchar *uid) gchar date[128]; time_t t; struct tm lt; - struct tm buft; memset(subject, 0, sizeof(subject)); memset(date, 0, sizeof(date)); @@ -572,6 +572,7 @@ static gchar *write_headers_date(const gchar *uid) } #ifndef G_OS_WIN32 + struct tm buft; lt = *localtime_r(&t, &buft); #else if (t < 0) @@ -787,16 +788,28 @@ VCalEvent * vcal_manager_new_event (const gchar *uid, if (dtend && *(dtend)) { time_t tmp = icaltime_as_timet((icaltime_from_string(dtend))); +#ifdef G_OS_WIN32 + GDateTime *dt = g_date_time_new_from_unix_local(tmp); + event->end = g_date_time_format(dt, "%a, %e %b %Y %H:%M:%S %z"); + g_date_time_unref(dt); +#else gchar buft[512]; tzset(); event->end = g_strdup(ctime_r(&tmp, buft)); +#endif } if (dtstart && *(dtstart)) { time_t tmp = icaltime_as_timet((icaltime_from_string(dtstart))); +#ifdef G_OS_WIN32 + GDateTime *dt = g_date_time_new_from_unix_local(tmp); + event->start = g_date_time_format(dt, "%a, %e %b %Y %H:%M:%S %z"); + g_date_time_unref(dt); +#else gchar buft[512]; tzset(); event->start = g_strdup(ctime_r(&tmp, buft)); +#endif } event->dtstart = g_strdup(dtstart?dtstart:""); event->dtend = g_strdup(dtend?dtend:""); @@ -1482,7 +1495,6 @@ EventTime event_to_today(VCalEvent *event, time_t t) struct tm evtstart, today; time_t evtstart_t, today_t; struct icaltimetype itt; - struct tm buft; tzset(); @@ -1495,6 +1507,7 @@ EventTime event_to_today(VCalEvent *event, time_t t) } #ifndef G_OS_WIN32 + struct tm buft; today = *localtime_r(&today_t, &buft); localtime_r(&evtstart_t, &evtstart); #else