More fixes for parsing dates in vcalendar on Windows.
authorAndrej Kacian <ticho@claws-mail.org>
Fri, 19 Aug 2016 16:50:53 +0000 (18:50 +0200)
committerAndrej Kacian <ticho@claws-mail.org>
Fri, 19 Aug 2016 16:50:53 +0000 (18:50 +0200)
...this time without all the i18n updates.

src/plugins/vcalendar/libical/libical/icalduration.c
src/plugins/vcalendar/libical/libical/icaltime.c
src/plugins/vcalendar/vcal_manager.c

index 18a74396f5194079f782c0ed944cb6b8d509e906..356809f22ead5d62f673dd08796d917c05d046db 100644 (file)
@@ -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;
 }
 
index 3ca3d9db42cc017c6f7edacf7e34fef331cdb804..7d3ee1cf685a71ff0f402b4d759f73c2522e5c67 100644 (file)
@@ -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);
 
index 1432e0f36ee6640e5037e4d8f015dcd059f6eccb..017aa8c444bebb8052d812aada1f2b9c06ba451c 100644 (file)
@@ -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