diff options
author | Carlos Garcia Campos <carlosgc@gnome.org> | 2010-07-11 16:15:51 (GMT) |
---|---|---|
committer | Carlos Garcia Campos <carlosgc@gnome.org> | 2010-07-12 17:12:01 (GMT) |
commit | c2ef0e90bc49e315f8241860419ef69320b7bd39 (patch) | |
tree | 925eb2355ba87aab93a32156e9cb10c23068047d /libdocument | |
parent | 356536f6b8b44bfcf13c644a26ecdd583465bc0f (diff) |
[libdocument] Move format_date function from ev-properties to ev-document-misc
Diffstat (limited to 'libdocument')
-rw-r--r-- | libdocument/ev-document-misc.c | 23 | ||||
-rw-r--r-- | libdocument/ev-document-misc.h | 2 |
2 files changed, 25 insertions, 0 deletions
diff --git a/libdocument/ev-document-misc.c b/libdocument/ev-document-misc.c index 605cbb0..de40405 100644 --- a/libdocument/ev-document-misc.c +++ b/libdocument/ev-document-misc.c @@ -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); +} diff --git a/libdocument/ev-document-misc.h b/libdocument/ev-document-misc.h index b09c194..7fbf716 100644 --- a/libdocument/ev-document-misc.h +++ b/libdocument/ev-document-misc.h @@ -60,6 +60,8 @@ void ev_document_misc_invert_pixbuf (GdkPixbuf *pixbuf); gdouble ev_document_misc_get_screen_dpi (GdkScreen *screen); +gchar *ev_document_misc_format_date (GTime utime); + G_END_DECLS #endif /* EV_DOCUMENT_MISC_H */ |