Commit e594821e authored by Paolo Bacchilega's avatar Paolo Bacchilega
Browse files

added _g_time_val_to_xmp_date to create dates in XMP format

parent 0705c6f7
......@@ -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
......
......@@ -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)
......
......@@ -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);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment