[tracker/tracker-0.6] Fixed NB#126260, Some images dont have Image:Date
- From: Ivan Frade <ifrade src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [tracker/tracker-0.6] Fixed NB#126260, Some images dont have Image:Date
- Date: Wed, 29 Jul 2009 08:54:20 +0000 (UTC)
commit b311853e4101aef661187ca4c1f4702e69873c28
Author: Ivan Frade <ivan frade nokia com>
Date: Wed Jul 29 11:52:22 2009 +0300
Fixed NB#126260, Some images dont have Image:Date
Improved date parsing algorithm to support an ISO8601 valid format:
...THH:MM+yy:zz (time with no seconds and timezone)
Included unit test for the new format.
src/libtracker-common/tracker-type-utils.c | 40 +++++++++++++++-----
tests/libtracker-common/tracker-type-utils-test.c | 4 ++
2 files changed, 34 insertions(+), 10 deletions(-)
---
diff --git a/src/libtracker-common/tracker-type-utils.c b/src/libtracker-common/tracker-type-utils.c
index 500be3f..06b2036 100644
--- a/src/libtracker-common/tracker-type-utils.c
+++ b/src/libtracker-common/tracker-type-utils.c
@@ -91,9 +91,14 @@ static gboolean
tracker_simplify_8601 (const gchar *date_string,
gchar *buf)
{
- gchar *copy, *date, *time, *zone, *sep;
- gint year, mon, day, hour, min, sec, remainder;
- gint len;
+ gchar *copy, *date, *sep;
+ gchar *time = NULL, *zone = NULL;
+ const gchar *time_part;
+ gint year, mon, day, hour, min, sec, remainder;
+ gint len;
+ gchar **pieces;
+ const gchar *timezone_sep = NULL;
+
if (!date_string) {
return FALSE;
@@ -114,21 +119,30 @@ tracker_simplify_8601 (const gchar *date_string,
if (sep) {
/* Separate date and time */
*sep = '\0';
- time = sep + 1;
+ time_part = sep + 1;
} else {
- time = NULL;
+ time_part = NULL;
}
- if (time) {
- zone = strchr (time, '+');
+ if (time_part) {
+ timezone_sep = g_strrstr (time_part, "+");
+ if (!timezone_sep) {
+ timezone_sep = g_strrstr (time_part, "-");
+ }
- if (!zone) {
- zone = strchr (time, '-');
+ if (!timezone_sep) {
+ time = g_strdup (time_part);
+ zone = g_strdup ("+00:00");
+ } else {
+ pieces = g_strsplit_set (time_part, "+-", -1);
+ time = g_strdup (pieces [0]);
+ zone = g_strdup_printf ("%c%s", timezone_sep[0], pieces [1]);
+ g_strfreev (pieces);
}
}
if (!zone) {
- zone = "+00:00";
+ zone = g_strdup ("+00:00");
}
if (date) {
@@ -189,6 +203,8 @@ tracker_simplify_8601 (const gchar *date_string,
} else {
g_critical ("Could not parse time in '%s'", time);
g_free (copy);
+ g_free (time);
+ g_free (zone);
return FALSE;
}
}
@@ -200,6 +216,10 @@ tracker_simplify_8601 (const gchar *date_string,
zone);
g_free (copy);
+ g_free (zone);
+ if (time) {
+ g_free (time);
+ }
return TRUE;
}
diff --git a/tests/libtracker-common/tracker-type-utils-test.c b/tests/libtracker-common/tracker-type-utils-test.c
index 55d6f17..60d857f 100644
--- a/tests/libtracker-common/tracker-type-utils-test.c
+++ b/tests/libtracker-common/tracker-type-utils-test.c
@@ -102,6 +102,10 @@ test_date_format (void)
g_assert (tracker_test_helpers_cmpstr_equal (result, "1979-03-04T16:00:00+00:00"));
g_free (result);
+ result = tracker_date_format ("2009-02-13T09:00+02:00");
+ g_assert (tracker_test_helpers_cmpstr_equal (result, "2009-02-13T09:00:00+02:00"));
+ g_free (result);
+
/* Decimals */
/* We are only interested in accuracy of a second */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]