Index: libical/src/libical/icaltime.c
===================================================================
RCS file: /cvs/gnome/libical/src/libical/icaltime.c,v
retrieving revision 1.40
diff -u -p -r1.40 icaltime.c
--- libical/src/libical/icaltime.c	28 Nov 2005 03:17:39 -0000	1.40
+++ libical/src/libical/icaltime.c	21 Mar 2006 16:03:56 -0000
@@ -51,6 +51,16 @@
 #define strcasecmp    stricmp
 #endif
 
+#ifdef WIN32
+/* Undef the similar macro from pthread.h, it doesn't check if
+ * gmtime() returns NULL.
+ */
+#undef gmtime_r
+
+/* The gmtime() in Microsoft's C library is MT-safe */
+#define gmtime_r(tp,tmp) (gmtime(tp)?(*(tmp)=*gmtime(tp),(tmp)):0)
+#endif
+
 #ifdef HAVE_PTHREAD
  #include <pthread.h>    
     static pthread_mutex_t tzid_mutex = PTHREAD_MUTEX_INITIALIZER;
@@ -195,9 +205,13 @@ icaltime_from_timet_with_zone(const time
 
     /* Convert the time_t to a struct tm in UTC time. We can trust gmtime
        for this. */
-    t = *(gmtime(&tm));
+#ifdef HAVE_PTHREAD
+    gmtime_r (&tm, &t);
+#else
+    t = *(gmtime (&tm));
+#endif
      
-     tt.year   = t.tm_year + 1900;
+    tt.year   = t.tm_year + 1900;
     tt.month  = t.tm_mon + 1;
     tt.day    = t.tm_mday;
     tt.hour   = t.tm_hour;
@@ -417,7 +431,13 @@ time_t icaltime_as_timet_with_zone(const
 #ifdef WIN32
     tzset ();
 #endif
+
+#ifdef HAVE_PTHREAD
+    pthread_mutex_lock (&tzid_mutex);
     t = mktime (&stm);
+    pthread_mutex_unlock (&tzid_mutex);
+#endif
+
     unset_tz (old_tz);
 #ifdef WIN32
     tzset ();
Index: libecal/e-cal-time-util.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/calendar/libecal/e-cal-time-util.c,v
retrieving revision 1.2
diff -u -p -r1.2 e-cal-time-util.c
--- libecal/e-cal-time-util.c	6 May 2005 05:19:57 -0000	1.2
+++ libecal/e-cal-time-util.c	21 Mar 2006 16:03:59 -0000
@@ -570,9 +570,11 @@ char *
 isodate_from_time_t (time_t t)
 {
 	gchar *ret;
+	struct tm stm;
 
+	gmtime_r (&t, &stm);
 	ret = g_malloc (17); /* 4+2+2+1+2+2+2+1 + 1 */
-	strftime (ret, 17, "%Y%m%dT%H%M%SZ", gmtime (&t));
+	strftime (ret, 17, "%Y%m%dT%H%M%SZ", &stm);
 
 	return ret;
 }
