From: Klaus Ethgen Date: Sat, 27 Feb 2010 20:34:54 +0000 (+0000) Subject: Unifying the datetime output X-Git-Url: http://geeqie.org/cgi-bin/gitweb.cgi?p=geeqie.git;a=commitdiff_plain;h=f842eed3cf52fcc820bd0a20a82823aeffd3d836 Unifying the datetime output The output of %date% and %formatted.DateTime% should be equivalent. --- diff --git a/src/exif-common.c b/src/exif-common.c index 5664cb4e..84ebef52 100644 --- a/src/exif-common.c +++ b/src/exif-common.c @@ -9,6 +9,8 @@ # include "config.h" #endif +#define _XOPEN_SOURCE + #include #include #include @@ -188,6 +190,11 @@ static gchar *exif_build_formatted_DateTime(ExifData *exif) { gchar *text = exif_get_data_as_text(exif, "Exif.Photo.DateTimeOriginal"); gchar *subsec = NULL; + gchar buf[128]; + gchar *tmp; + gint buflen; + struct tm tm; + GError *error = NULL; if (text) { @@ -198,9 +205,30 @@ static gchar *exif_build_formatted_DateTime(ExifData *exif) text = exif_get_data_as_text(exif, "Exif.Image.DateTime"); if (text) subsec = exif_get_data_as_text(exif, "Exif.Photo.SubSecTime"); } + + /* Convert the stuff into a tm struct */ + if (text && strptime(text, "%Y:%m:%d %H:%M:%S", &tm)) + { + buflen = strftime(buf, sizeof(buf), "%x %X", &tm); + if (buflen > 0) + { + tmp = g_locale_to_utf8(buf, buflen, NULL, NULL, &error); + if (error) + { + log_printf("Error converting locale strftime to UTF-8: %s\n", error->message); + g_error_free(error); + } + else + { + g_free(text); + text = g_strdup(tmp); + } + } + } + if (subsec) { - gchar *tmp = text; + tmp = text; text = g_strconcat(tmp, ".", subsec, NULL); g_free(tmp); g_free(subsec); diff --git a/src/filedata.c b/src/filedata.c index 9da09fa1..77814d08 100644 --- a/src/filedata.c +++ b/src/filedata.c @@ -116,7 +116,7 @@ const gchar *text_from_time(time_t t) btime = localtime(&t); /* the %x warning about 2 digit years is not an error */ - buflen = strftime(buf, sizeof(buf), "%x %H:%M", btime); + buflen = strftime(buf, sizeof(buf), "%x %X", btime); if (buflen < 1) return ""; g_free(ret);