From f84e4ee04d34b7e02a9c36fda5a8b8c2e95b7403 Mon Sep 17 00:00:00 2001 From: Jacob Boerema Date: Mon, 23 Sep 2024 13:37:29 -0400 Subject: [PATCH] plug-ins: fix failure to write IPTC TimeCreated The IPTC TimeCreated tag does not allow fractions of a second, while Xmp.Photoshop.DateCreated (which includes the time) does allow this. In our metadata editor we base our date/time on the last value and then synchronize it with the IPTC date and time values. While doing that, we did not check if the seconds had a fractional part. To fix this we first check for the presence of a fraction by checking for a dot in the time string. Complicating factor is that a timezone difference may follow that, which we want to keep if present. So we check for that too and concatenate the parts we want. --- plug-ins/metadata/metadata-editor.c | 30 ++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/plug-ins/metadata/metadata-editor.c b/plug-ins/metadata/metadata-editor.c index cb4a539228..3777c2b76e 100644 --- a/plug-ins/metadata/metadata-editor.c +++ b/plug-ins/metadata/metadata-editor.c @@ -5131,8 +5131,36 @@ metadata_editor_write_callback (GtkWidget *dialog, if (date_time_split[1] != NULL) { + gchar **time_split = NULL; + gchar *iptc_time = NULL; + + /* IPTC TimeCreated can't have fractional parts. */ + time_split = g_strsplit (date_time_split[1], ".", 2); + + /* A timezone adjustment can follow this, which + * we want to keep. */ + if (time_split[1] != NULL) + { + gchar **tz_split = NULL; + + tz_split = g_strsplit_set (time_split[1], "+-", 2); + if (tz_split[1] != NULL) + iptc_time = g_strconcat (time_split[0], + time_split[1] + strlen (tz_split[0]), + NULL); + else + iptc_time = g_strdup (time_split[0]); + g_strfreev (tz_split); + } + else + { + iptc_time = g_strdup (time_split[0]); + } + set_tag_string (g_metadata, "Iptc.Application2.TimeCreated", - date_time_split[1], FALSE); + iptc_time, FALSE); + g_strfreev (time_split); + g_free (iptc_time); } else {