]> www.fi.muni.cz Git - evince.git/blobdiff - libdocument/ev-document-misc.c
[libdocument] Move format_date function from ev-properties to ev-document-misc
[evince.git] / libdocument / ev-document-misc.c
index 605cbb0a87c0074a67a7c03762db37af0ddd0e41..de4040510a52d414c46c02129cdc25f797ac4271 100644 (file)
@@ -400,3 +400,26 @@ ev_document_misc_get_screen_dpi (GdkScreen *screen)
 
        return (dp / di);
 }
+
+/* Returns a locale specific date and time representation */
+gchar *
+ev_document_misc_format_date (GTime utime)
+{
+       time_t time = (time_t) utime;
+       char s[256];
+       const char fmt_hack[] = "%c";
+       size_t len;
+#ifdef HAVE_LOCALTIME_R
+       struct tm t;
+       if (time == 0 || !localtime_r (&time, &t)) return NULL;
+       len = strftime (s, sizeof (s), fmt_hack, &t);
+#else
+       struct tm *t;
+       if (time == 0 || !(t = localtime (&time)) ) return NULL;
+       len = strftime (s, sizeof (s), fmt_hack, t);
+#endif
+
+       if (len == 0 || s[0] == '\0') return NULL;
+
+       return g_locale_to_utf8 (s, -1, NULL, NULL, NULL);
+}