summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Hughes <richard@hughsie.com>2016-07-19 15:46:11 +0100
committerRichard Hughes <richard@hughsie.com>2016-07-19 15:46:11 +0100
commitaccf6cd614f1be1dec2963f72f0a419a48de69f9 (patch)
tree726d792148cf127a39626510c2a2465b45847f83
parent0c5326ea06054bcd95d43476ea4b08023affba35 (diff)
downloadappstream-glib-accf6cd614f1be1dec2963f72f0a419a48de69f9.tar.gz
trivial: Factor out a soon-to-be-shared function
-rw-r--r--libappstream-glib/as-release.c28
-rw-r--r--libappstream-glib/as-utils-private.h1
-rw-r--r--libappstream-glib/as-utils.c36
3 files changed, 38 insertions, 27 deletions
diff --git a/libappstream-glib/as-release.c b/libappstream-glib/as-release.c
index 731daa1..b273078 100644
--- a/libappstream-glib/as-release.c
+++ b/libappstream-glib/as-release.c
@@ -603,32 +603,6 @@ as_release_node_insert (AsRelease *release, GNode *parent, AsNodeContext *ctx)
return n;
}
-static GDateTime *
-as_release_iso8601_to_datetime (const gchar *iso_date)
-{
- GTimeVal tv;
- guint dmy[] = {0, 0, 0};
-
- /* nothing set */
- if (iso_date == NULL || iso_date[0] == '\0')
- return NULL;
-
- /* try to parse complete ISO8601 date */
- if (g_strstr_len (iso_date, -1, " ") != NULL) {
- if (g_time_val_from_iso8601 (iso_date, &tv) && tv.tv_sec != 0)
- return g_date_time_new_from_timeval_utc (&tv);
- }
-
- /* g_time_val_from_iso8601() blows goats and won't
- * accept a valid ISO8601 formatted date without a
- * time value - try and parse this case */
- if (sscanf (iso_date, "%u-%u-%u", &dmy[0], &dmy[1], &dmy[2]) != 3)
- return NULL;
-
- /* create valid object */
- return g_date_time_new_utc (dmy[0], dmy[1], dmy[2], 0, 0, 0);
-}
-
/**
* as_release_node_parse:
* @release: a #AsRelease instance.
@@ -656,7 +630,7 @@ as_release_node_parse (AsRelease *release, GNode *node,
tmp = as_node_get_attribute (node, "date");
if (tmp != NULL) {
g_autoptr(GDateTime) dt = NULL;
- dt = as_release_iso8601_to_datetime (tmp);
+ dt = as_utils_iso8601_to_datetime (tmp);
if (dt != NULL)
as_release_set_timestamp (release, g_date_time_to_unix (dt));
}
diff --git a/libappstream-glib/as-utils-private.h b/libappstream-glib/as-utils-private.h
index 0ea7e5a..ebf6fbf 100644
--- a/libappstream-glib/as-utils-private.h
+++ b/libappstream-glib/as-utils-private.h
@@ -44,6 +44,7 @@ const gchar *as_ptr_array_find_string (GPtrArray *array,
const gchar *value);
gboolean as_utils_locale_is_compatible (const gchar *locale1,
const gchar *locale2);
+GDateTime *as_utils_iso8601_to_datetime (const gchar *iso_date);
G_END_DECLS
diff --git a/libappstream-glib/as-utils.c b/libappstream-glib/as-utils.c
index ca28bc3..30e57ab 100644
--- a/libappstream-glib/as-utils.c
+++ b/libappstream-glib/as-utils.c
@@ -1669,3 +1669,39 @@ as_utils_string_replace (GString *string, const gchar *search, const gchar *repl
return count;
}
+
+/**
+ * as_utils_iso8601_to_datetime: (skip)
+ * @iso_date: The ISO8601 date
+ *
+ * Converts an ISO8601 to a #GDateTime.
+ *
+ * Returns: a #GDateTime, or %NULL for error.
+ *
+ * Since: 0.5.18
+ **/
+GDateTime *
+as_utils_iso8601_to_datetime (const gchar *iso_date)
+{
+ GTimeVal tv;
+ guint dmy[] = {0, 0, 0};
+
+ /* nothing set */
+ if (iso_date == NULL || iso_date[0] == '\0')
+ return NULL;
+
+ /* try to parse complete ISO8601 date */
+ if (g_strstr_len (iso_date, -1, " ") != NULL) {
+ if (g_time_val_from_iso8601 (iso_date, &tv) && tv.tv_sec != 0)
+ return g_date_time_new_from_timeval_utc (&tv);
+ }
+
+ /* g_time_val_from_iso8601() blows goats and won't
+ * accept a valid ISO8601 formatted date without a
+ * time value - try and parse this case */
+ if (sscanf (iso_date, "%u-%u-%u", &dmy[0], &dmy[1], &dmy[2]) != 3)
+ return NULL;
+
+ /* create valid object */
+ return g_date_time_new_utc (dmy[0], dmy[1], dmy[2], 0, 0, 0);
+}