[gthumb] added _g_time_val_to_xmp_date to create dates in XMP format



commit e594821ebe24a6069033c3b4b8fd8a98fce52c9a
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Wed Jul 20 12:17:33 2011 +0200

    added _g_time_val_to_xmp_date to create dates in XMP format

 configure.ac        |   33 +++++++++++++++++++++++++++++++++
 gthumb/glib-utils.c |   50 ++++++++++++++++++++++++++++++++++++++++++++++++++
 gthumb/glib-utils.h |    1 +
 3 files changed, 84 insertions(+), 0 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 95a343e..201eb81 100644
--- a/configure.ac
+++ b/configure.ac
@@ -322,6 +322,39 @@ AC_SUBST(GTHUMB_IMPLIB)
 
 dnl ===========================================================================
 
+AC_CACHE_CHECK(for tm_gmtoff in struct tm, [ac_cv_struct_tm_gmtoff],
+	AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
+	[[	#include <time.h>	]],
+	[[
+		struct tm tm;
+		tm.tm_gmtoff = 1;
+	]]
+	)],[ac_cv_struct_tm_gmtoff=yes],[ac_cv_struct_tm_gmtoff=no]))
+if test "x$ac_cv_struct_tm_gmtoff" = "xyes"; then
+	AC_DEFINE(HAVE_TM_GMTOFF, 1, [Define if struct tm has a tm_gmtoff member])
+else
+	AC_CACHE_CHECK(for timezone variable, [ac_cv_var_timezone],
+		AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
+		[[	#include <time.h> ]],
+		[[	timezone = 1;	]]
+		)],[ac_cv_var_timezone=yes],[ac_cv_var_timezone=no]))
+	if test "x$ac_cv_var_timezone" = "xyes"; then
+		AC_DEFINE(HAVE_TIMEZONE, 1, [Define if libc defines a timezone variable])
+		AC_CACHE_CHECK(for altzone variable, [ac_cv_var_altzone],
+			AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
+			[[	#include <time.h>	]],
+			[[	altzone = 1; ]]
+			)],[ac_cv_var_altzone=yes],[ac_cv_var_altzone=no]))
+		if test "x$ac_cv_var_altzone" = "xyes"; then
+			AC_DEFINE(HAVE_ALTZONE, 1, [Define if libc defines an altzone variable])
+		fi
+	else
+		AC_MSG_ERROR([unable to find a way to determine timezone])
+	fi
+fi
+
+dnl ===========================================================================
+
 WARN_CFLAGS="-Wall -Wcast-align -Wtype-limits -Wclobbered -Wempty-body -Wignored-qualifiers"
 
 for option in $WARN_CFLAGS; do
diff --git a/gthumb/glib-utils.c b/gthumb/glib-utils.c
index d5595b6..ba19c7e 100644
--- a/gthumb/glib-utils.c
+++ b/gthumb/glib-utils.c
@@ -547,6 +547,56 @@ _g_time_val_to_exif_date (GTimeVal *time_)
 }
 
 
+static int
+_g_time_get_timezone_offset (struct tm *tm)
+{
+	int offset;
+
+	offset = -timezone;
+#if defined (HAVE_TM_GMTOFF)
+	offset = tm->tm_gmtoff;
+#elif defined (HAVE_TIMEZONE)
+	if (tm->tm_isdst > 0) {
+  #if defined (HAVE_ALTZONE)
+		offset = -altzone;
+  #else /* !defined (HAVE_ALTZONE) */
+		offset = -timezone + 3600;
+  #endif
+	} else
+		offset = -timezone;
+#endif
+
+	return offset;
+}
+
+
+char *
+_g_time_val_to_xmp_date (GTimeVal *time_)
+{
+	time_t     secs;
+	struct tm *tm;
+	int        offset;
+	char      *retval;
+
+	g_return_val_if_fail (time_->tv_usec >= 0 && time_->tv_usec < G_USEC_PER_SEC, NULL);
+
+	secs = time_->tv_sec;
+	tm = localtime (&secs);
+	offset = _g_time_get_timezone_offset (tm);
+	retval = g_strdup_printf ("%4d-%02d-%02dT%02d:%02d:%02d%+03d:%02d",
+				  tm->tm_year + 1900,
+				  tm->tm_mon + 1,
+				  tm->tm_mday,
+				  tm->tm_hour,
+				  tm->tm_min,
+				  tm->tm_sec,
+				  offset / 3600,
+				  offset % 3600);
+
+	return retval;
+}
+
+
 char *
 _g_time_val_strftime (GTimeVal   *time_,
 		      const char *format)
diff --git a/gthumb/glib-utils.h b/gthumb/glib-utils.h
index 6405407..eebc71a 100644
--- a/gthumb/glib-utils.h
+++ b/gthumb/glib-utils.h
@@ -143,6 +143,7 @@ void            _g_time_val_reset                (GTimeVal   *time_);
 gboolean        _g_time_val_from_exif_date       (const char *exif_date,
 						  GTimeVal   *time_);
 char *          _g_time_val_to_exif_date         (GTimeVal   *time_);
+char *          _g_time_val_to_xmp_date          (GTimeVal   *time_);
 char *          _g_time_val_strftime             (GTimeVal   *time_,
 						  const char *format);
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]