Index: glib/gunicode.h
===================================================================
RCS file: /cvs/gnome/glib/glib/gunicode.h,v
retrieving revision 1.25
diff -u -p -r1.25 gunicode.h
--- glib/gunicode.h	2001/09/02 17:14:23	1.25
+++ glib/gunicode.h	2002/01/20 15:05:54
@@ -24,6 +24,7 @@
 
 #include <glib/gerror.h>
 #include <glib/gtypes.h>
+#include <time.h>
 
 G_BEGIN_DECLS
 
@@ -247,6 +248,10 @@ gboolean g_utf8_validate (const gchar  *
 
 /* Validate a Unicode character */
 gboolean g_unichar_validate (gunichar ch);
+
+/* UTF-8 safe version of strftime */
+gchar *g_utf8_strftime (const gchar *format,
+		        struct tm *time_pieces);
 
 gchar *g_utf8_strup   (const gchar *str,
 		       gssize       len);
Index: glib/gutf8.c
===================================================================
RCS file: /cvs/gnome/glib/glib/gutf8.c,v
retrieving revision 1.29
diff -u -p -r1.29 gutf8.c
--- glib/gutf8.c	2001/11/28 21:23:32	1.29
+++ glib/gutf8.c	2002/01/20 15:05:54
@@ -26,6 +26,9 @@
 #include <langinfo.h>
 #endif
 #include <string.h>
+#ifdef __STDC_ISO_10646__
+#include <wchar.h>
+#endif
 
 #include "glib.h"
 
@@ -1568,3 +1571,64 @@ g_unichar_validate (gunichar ch)
 {
   return UNICODE_VALID (ch);
 }
+
+/**
+ * g_utf8_strftime:
+ *
+ * Cover for standard date-and-time-formatting routine strftime that returns
+ * a newly-allocated string of the correct size. The caller is responsible
+ * for g_free-ing the returned string.
+ *
+ * @format: format string to pass to strftime. See strftime documentation
+ * for details.
+ * @time_pieces: date/time, in struct format.
+ * 
+ * Return value: Newly allocated string containing the formatted time.
+ **/
+gchar *
+g_utf8_strftime (const gchar *format,
+		 struct tm *time_pieces)
+{
+  gchar buffer[512];
+  size_t length;
+  gchar *result;
+  
+#ifdef __STDC_ISO_10646__
+
+  length = wcsftime ((wchar_t *)buffer, sizeof (buffer),
+                     (wchar_t *)format, time_pieces);
+  if (length == 0)
+      buffer[0] = '\0';
+
+  result = g_strndup (buffer, length);
+
+#else /* !__STDC_ISO_10646__ */
+
+  const gchar *charset;
+
+  if (g_get_charset (&charset))
+    {
+      length = strftime (buffer, sizeof (buffer), format, time_pieces);
+      if (length == 0)
+        buffer[0] = '\0';
+
+      result = g_strndup (buffer, length);
+    }
+  else
+    {
+      gchar *format_locale = g_convert (format, -1, "UTF-8", charset, NULL, NULL, NULL);
+
+      length = strftime (buffer, sizeof (buffer), format_locale, time_pieces);
+      if (length == 0)
+        buffer[0] = '\0';
+
+      g_free (format_locale);
+
+      result = g_convert (buffer, length, charset, "UTF-8", NULL, NULL, NULL);
+    }
+
+#endif /* __STDC_ISO_10646__ */
+
+  return result;
+}
+
