[tracker-miners/wip/sthursfield/debian10-hacks: 4/5] HACK: Avoid new date time functions
- From: Sam Thursfield <sthursfield src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker-miners/wip/sthursfield/debian10-hacks: 4/5] HACK: Avoid new date time functions
- Date: Wed, 16 Jun 2021 17:27:11 +0000 (UTC)
commit ec3d72d6c526471e405b76851827c9a5b2e88dbf
Author: Sam Thursfield <sam afuera me uk>
Date: Wed Jun 16 14:19:44 2021 +0200
HACK: Avoid new date time functions
GLib 2.62
src/miners/fs/tracker-miner-files.c | 56 ++++++++++++++++++++++++++
tests/libtracker-miner/tracker-miner-fs-test.c | 12 ++----
2 files changed, 60 insertions(+), 8 deletions(-)
---
diff --git a/src/miners/fs/tracker-miner-files.c b/src/miners/fs/tracker-miner-files.c
index 518b19843..ba78739e1 100644
--- a/src/miners/fs/tracker-miner-files.c
+++ b/src/miners/fs/tracker-miner-files.c
@@ -272,6 +272,62 @@ tracker_miner_files_class_init (TrackerMinerFilesClass *klass)
miner_files_error_quark = g_quark_from_static_string ("TrackerMinerFiles");
}
+/* Backport */
+/**
+ * g_date_time_format_iso8601:
+ * @datetime: A #GDateTime
+ *
+ * Format @datetime in [ISO 8601 format](https://en.wikipedia.org/wiki/ISO_8601),
+ * including the date, time and time zone, and return that as a UTF-8 encoded
+ * string.
+ *
+ * Since GLib 2.66, this will output to sub-second precision if needed.
+ *
+ * Returns: (transfer full) (nullable): a newly allocated string formatted in
+ * ISO 8601 format or %NULL in the case that there was an error. The string
+ * should be freed with g_free().
+ *
+ * Since: 2.62
+ */
+gchar *
+g_date_time_format_iso8601 (GDateTime *datetime)
+{
+ GString *outstr = NULL;
+ gchar *main_date = NULL;
+ gint64 offset;
+ gchar *format = "%Y-%m-%dT%H:%M:%S";
+
+#if 0
+ /* if datetime has sub-second non-zero values below the second precision we
+ * should print them as well */
+ if (datetime->usec % G_TIME_SPAN_SECOND != 0)
+ format = "%Y-%m-%dT%H:%M:%S.%f";
+#endif
+
+ /* Main date and time. */
+ main_date = g_date_time_format (datetime, format);
+ outstr = g_string_new (main_date);
+ g_free (main_date);
+
+ /* Timezone. Format it as `%:::z` unless the offset is zero, in which case
+ * we can simply use `Z`. */
+ offset = g_date_time_get_utc_offset (datetime);
+
+ if (offset == 0)
+ {
+ g_string_append_c (outstr, 'Z');
+ }
+ else
+ {
+ gchar *time_zone = g_date_time_format (datetime, "%:::z");
+ g_string_append (outstr, time_zone);
+ g_free (time_zone);
+ }
+
+ return g_string_free (outstr, FALSE);
+}
+
+
static void
tracker_miner_files_check_unextracted (TrackerMinerFiles *mf)
{
diff --git a/tests/libtracker-miner/tracker-miner-fs-test.c b/tests/libtracker-miner/tracker-miner-fs-test.c
index 8f13d764b..dd48a7262 100644
--- a/tests/libtracker-miner/tracker-miner-fs-test.c
+++ b/tests/libtracker-miner/tracker-miner-fs-test.c
@@ -35,7 +35,6 @@ test_miner_process_file (TrackerMinerFS *miner,
gboolean created)
{
TrackerResource *resource;
- GDateTime *modification_time;
TrackerIndexingTree *tree;
gchar *uri, *parent_uri, *str;
GFile *parent;
@@ -55,13 +54,10 @@ test_miner_process_file (TrackerMinerFS *miner,
tracker_resource_add_relation (resource, "nie:isStoredAs", resource);
if (info) {
- modification_time = g_file_info_get_modification_date_time (info);
- if (modification_time) {
- str = g_date_time_format_iso8601 (modification_time);
- tracker_resource_set_string (resource, "nfo:fileLastModified", str);
- g_free (str);
- g_date_time_unref (modification_time);
- }
+ time_t time_ = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_TIME_MODIFIED);
+ char *time_str = tracker_date_to_string (time_);
+ tracker_resource_set_string (resource, "nfo:fileLastModified", time_str);
+ g_free (time_str);
}
tracker_resource_set_string (resource, "nie:url", uri);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]