[tracker/datetime] libtracker-common, -extract: Improvements to date-time parsing
- From: Philip Van Hoof <pvanhoof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/datetime] libtracker-common, -extract: Improvements to date-time parsing
- Date: Tue, 23 Feb 2010 14:50:31 +0000 (UTC)
commit 8d8453f524be6ff76f8936b226bbde945638e675
Author: Philip Van Hoof <philip codeminded be>
Date: Tue Feb 23 15:48:05 2010 +0100
libtracker-common, -extract: Improvements to date-time parsing
This patch refactors the date-time handling a bit: It moves the functions for
date-time formatting from libtracker-common to libtracker-extract, and many
extractor modules have been adapted to start using it for proper date-time
handling and guessing.
configure.ac | 1 +
src/libtracker-common/tracker-date-time.c | 360 +------------------
src/libtracker-common/tracker-date-time.h | 5 -
src/libtracker-extract/tracker-exif.c | 3 +-
src/libtracker-extract/tracker-iptc.c | 3 +-
src/libtracker-extract/tracker-utils.c | 401 ++++++++++++++++++++-
src/libtracker-extract/tracker-utils.h | 4 +
src/libtracker-extract/tracker-xmp.c | 4 +-
src/tracker-extract/tracker-extract-flac.c | 4 +-
src/tracker-extract/tracker-extract-libxine.c | 5 +-
src/tracker-extract/tracker-extract-mp3.c | 13 +-
src/tracker-extract/tracker-extract-mplayer.c | 7 +-
src/tracker-extract/tracker-extract-msoffice.c | 42 ++-
src/tracker-extract/tracker-extract-oasis.c | 9 +-
src/tracker-extract/tracker-extract-png.c | 2 +-
src/tracker-extract/tracker-extract-ps.c | 8 +-
src/tracker-extract/tracker-extract-tiff.c | 14 +-
src/tracker-extract/tracker-extract-vorbis.c | 5 +-
tests/Makefile.am | 1 +
tests/libtracker-common/tracker-type-utils-test.c | 41 ---
tests/libtracker-extract/Makefile.am | 33 ++
tests/libtracker-extract/tracker-utils-test.c | 81 +++++
22 files changed, 599 insertions(+), 447 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 4095727..1104377 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1648,6 +1648,7 @@ AC_CONFIG_FILES([
src/vapi/Makefile
tests/common/Makefile
tests/libtracker-common/Makefile
+ tests/libtracker-extract/Makefile
tests/libtracker-data/Makefile
tests/libtracker-data/aggregates/Makefile
tests/libtracker-data/algebra/Makefile
diff --git a/src/libtracker-common/tracker-date-time.c b/src/libtracker-common/tracker-date-time.c
index 1074208..cdd5494 100644
--- a/src/libtracker-common/tracker-date-time.c
+++ b/src/libtracker-common/tracker-date-time.c
@@ -20,9 +20,6 @@
#include "config.h"
-#define _XOPEN_SOURCE
-#include <time.h>
-
#include <strings.h>
#include <string.h>
#include <stdlib.h>
@@ -32,365 +29,10 @@
#include "tracker-date-time.h"
#include "tracker-type-utils.h"
-#define DATE_FORMAT_ISO8601 "%Y-%m-%dT%H:%M:%S%z"
-
GQuark tracker_date_error_quark (void) {
return g_quark_from_static_string ("tracker_date_error-quark");
}
-static const char *months[] = {
- "Jan", "Feb", "Mar", "Apr", "May", "Jun",
- "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
-};
-
-static const char imonths[] = {
- '1', '2', '3', '4', '5',
- '6', '7', '8', '9', '0', '1', '2'
-};
-
-static gboolean
-is_int (const gchar *str)
-{
- gint i, len;
-
- if (!str || str[0] == '\0') {
- return FALSE;
- }
-
- len = strlen (str);
-
- for (i = 0; i < len; i++) {
- if (!g_ascii_isdigit(str[i])) {
- return FALSE;
- }
- }
-
- return TRUE ;
-}
-
-static gint
-parse_month (const gchar *month)
-{
- gint i;
-
- for (i = 0; i < 12; i++) {
- if (!strncmp (month, months[i], 3)) {
- return i;
- }
- }
-
- return -1;
-}
-
-/* Determine date format and convert to ISO 8601 format */
-/* FIXME We should handle all the fractions here (see ISO 8601), as well as YYYY:DDD etc */
-gchar *
-tracker_date_format (const gchar *date_string)
-{
- gchar buf[30];
- gint len;
-
- if (!date_string) {
- return NULL;
- }
-
- len = strlen (date_string);
-
- /* We cannot format a date without at least a four digit
- * year.
- */
- if (len < 4) {
- return NULL;
- }
-
- /* Check for year only dates (EG ID3 music tags might have
- * Audio.ReleaseDate as 4 digit year)
- */
- if (len == 4) {
- if (is_int (date_string)) {
- buf[0] = date_string[0];
- buf[1] = date_string[1];
- buf[2] = date_string[2];
- buf[3] = date_string[3];
- buf[4] = '-';
- buf[5] = '0';
- buf[6] = '1';
- buf[7] = '-';
- buf[8] = '0';
- buf[9] = '1';
- buf[10] = 'T';
- buf[11] = '0';
- buf[12] = '0';
- buf[13] = ':';
- buf[14] = '0';
- buf[15] = '0';
- buf[16] = ':';
- buf[17] = '0';
- buf[18] = '0';
- buf[19] = 'Z';
- buf[20] = '\0';
-
- return g_strdup (buf);
- } else {
- return NULL;
- }
- } else if (len == 10) {
- /* Check for date part only YYYY-MM-DD*/
- buf[0] = date_string[0];
- buf[1] = date_string[1];
- buf[2] = date_string[2];
- buf[3] = date_string[3];
- buf[4] = '-';
- buf[5] = date_string[5];
- buf[6] = date_string[6];
- buf[7] = '-';
- buf[8] = date_string[8];
- buf[9] = date_string[9];
- buf[10] = 'T';
- buf[11] = '0';
- buf[12] = '0';
- buf[13] = ':';
- buf[14] = '0';
- buf[15] = '0';
- buf[16] = ':';
- buf[17] = '0';
- buf[18] = '0';
- buf[19] = '\0';
-
- return g_strdup (buf);
- } else if (len == 14) {
- /* Check for pdf format EG 20050315113224-08'00' or
- * 20050216111533Z
- */
- buf[0] = date_string[0];
- buf[1] = date_string[1];
- buf[2] = date_string[2];
- buf[3] = date_string[3];
- buf[4] = '-';
- buf[5] = date_string[4];
- buf[6] = date_string[5];
- buf[7] = '-';
- buf[8] = date_string[6];
- buf[9] = date_string[7];
- buf[10] = 'T';
- buf[11] = date_string[8];
- buf[12] = date_string[9];
- buf[13] = ':';
- buf[14] = date_string[10];
- buf[15] = date_string[11];
- buf[16] = ':';
- buf[17] = date_string[12];
- buf[18] = date_string[13];
- buf[19] = '\0';
-
- return g_strdup (buf);
- } else if (len == 15 && date_string[14] == 'Z') {
- buf[0] = date_string[0];
- buf[1] = date_string[1];
- buf[2] = date_string[2];
- buf[3] = date_string[3];
- buf[4] = '-';
- buf[5] = date_string[4];
- buf[6] = date_string[5];
- buf[7] = '-';
- buf[8] = date_string[6];
- buf[9] = date_string[7];
- buf[10] = 'T';
- buf[11] = date_string[8];
- buf[12] = date_string[9];
- buf[13] = ':';
- buf[14] = date_string[10];
- buf[15] = date_string[11];
- buf[16] = ':';
- buf[17] = date_string[12];
- buf[18] = date_string[13];
- buf[19] = 'Z';
- buf[20] = '\0';
-
- return g_strdup (buf);
- } else if (len == 21 && (date_string[14] == '-' || date_string[14] == '+' )) {
- buf[0] = date_string[0];
- buf[1] = date_string[1];
- buf[2] = date_string[2];
- buf[3] = date_string[3];
- buf[4] = '-';
- buf[5] = date_string[4];
- buf[6] = date_string[5];
- buf[7] = '-';
- buf[8] = date_string[6];
- buf[9] = date_string[7];
- buf[10] = 'T';
- buf[11] = date_string[8];
- buf[12] = date_string[9];
- buf[13] = ':';
- buf[14] = date_string[10];
- buf[15] = date_string[11];
- buf[16] = ':';
- buf[17] = date_string[12];
- buf[18] = date_string[13];
- buf[19] = date_string[14];
- buf[20] = date_string[15];
- buf[21] = date_string[16];
- buf[22] = ':';
- buf[23] = date_string[18];
- buf[24] = date_string[19];
- buf[25] = '\0';
-
- return g_strdup (buf);
- } else if ((len == 24) && (date_string[3] == ' ')) {
- /* Check for msoffice date format "Mon Feb 9 10:10:00 2004" */
- gint num_month;
- gchar mon1;
- gchar day1;
-
- num_month = parse_month (date_string + 4);
-
- mon1 = imonths[num_month];
-
- if (date_string[8] == ' ') {
- day1 = '0';
- } else {
- day1 = date_string[8];
- }
-
- buf[0] = date_string[20];
- buf[1] = date_string[21];
- buf[2] = date_string[22];
- buf[3] = date_string[23];
- buf[4] = '-';
-
- if (num_month < 10) {
- buf[5] = '0';
- buf[6] = mon1;
- } else {
- buf[5] = '1';
- buf[6] = mon1;
- }
-
- buf[7] = '-';
- buf[8] = day1;
- buf[9] = date_string[9];
- buf[10] = 'T';
- buf[11] = date_string[11];
- buf[12] = date_string[12];
- buf[13] = ':';
- buf[14] = date_string[14];
- buf[15] = date_string[15];
- buf[16] = ':';
- buf[17] = date_string[17];
- buf[18] = date_string[18];
- buf[19] = '\0';
-
- return g_strdup (buf);
- } else if ((len == 19) && (date_string[4] == ':') && (date_string[7] == ':')) {
- /* Check for Exif date format "2005:04:29 14:56:54" */
- buf[0] = date_string[0];
- buf[1] = date_string[1];
- buf[2] = date_string[2];
- buf[3] = date_string[3];
- buf[4] = '-';
- buf[5] = date_string[5];
- buf[6] = date_string[6];
- buf[7] = '-';
- buf[8] = date_string[8];
- buf[9] = date_string[9];
- buf[10] = 'T';
- buf[11] = date_string[11];
- buf[12] = date_string[12];
- buf[13] = ':';
- buf[14] = date_string[14];
- buf[15] = date_string[15];
- buf[16] = ':';
- buf[17] = date_string[17];
- buf[18] = date_string[18];
- buf[19] = '\0';
-
- return g_strdup (buf);
- } else if ((len == 28) && (date_string[4] == '-') && (date_string[10] == 'T')
- && (date_string[19] == '.') ) {
- /* The fraction of seconds ISO 8601 "YYYY-MM-DDThh:mm:ss.ff+zz:zz" */
- buf[0] = date_string[0];
- buf[1] = date_string[1];
- buf[2] = date_string[2];
- buf[3] = date_string[3];
- buf[4] = '-';
- buf[5] = date_string[5];
- buf[6] = date_string[6];
- buf[7] = '-';
- buf[8] = date_string[8];
- buf[9] = date_string[9];
- buf[10] = 'T';
- buf[11] = date_string[11];
- buf[12] = date_string[12];
- buf[13] = ':';
- buf[14] = date_string[14];
- buf[15] = date_string[15];
- buf[16] = ':';
- buf[17] = date_string[17];
- buf[18] = date_string[18];
- buf[19] = date_string[22];
- buf[20] = date_string[23];
- buf[21] = date_string[24];
- buf[22] = ':';
- buf[23] = date_string[26];
- buf[24] = date_string[27];
- buf[25] = '\0';
-
- return g_strdup (buf);
- }
-
- return g_strdup (date_string);
-}
-
-gchar *
-tracker_date_format_to_iso8601 (const gchar *date_string,
- const gchar *format)
-{
- gchar *result;
- struct tm date_tm = { 0 };
-
- g_return_val_if_fail (date_string != NULL, NULL);
- g_return_val_if_fail (format != NULL, NULL);
-
- if (strptime (date_string, format, &date_tm) == 0) {
- return NULL;
- }
-
- result = g_malloc (sizeof (char)*25);
-
- strftime (result, 25, DATE_FORMAT_ISO8601 , &date_tm);
-
- return result;
-}
-
-gchar *
-tracker_date_to_time_string (const gchar *date_string, GError **error)
-{
- gchar *str;
- GError *new_error = NULL;
-
- str = tracker_date_format (date_string);
-
- if (str) {
- time_t t;
-
- t = tracker_string_to_date (str, NULL, &new_error);
-
- g_free (str);
-
- if (new_error) {
- g_propagate_error (error, new_error);
- return NULL;
- }
-
- if (t != -1) {
- return tracker_gint_to_string (t);
- }
- }
-
- return NULL;
-}
-
time_t
tracker_string_to_date (const gchar *date_string,
gint *offset_p,
@@ -487,6 +129,8 @@ tracker_string_to_date (const gchar *date_string,
if (offset < -14 * 3600 || offset > 14 * 3600) {
g_set_error (error, TRACKER_DATE_ERROR, TRACKER_DATE_ERROR_OFFSET,
"UTC offset too large: %d seconds", offset);
+ g_match_info_free (match_info);
+ return -1;
}
t -= offset;
diff --git a/src/libtracker-common/tracker-date-time.h b/src/libtracker-common/tracker-date-time.h
index 7f39401..d339b4e 100644
--- a/src/libtracker-common/tracker-date-time.h
+++ b/src/libtracker-common/tracker-date-time.h
@@ -53,11 +53,6 @@ gint tracker_date_time_get_offset (const GValue *value);
gint tracker_date_time_get_local_date (const GValue *value);
gint tracker_date_time_get_local_time (const GValue *value);
-gchar * tracker_date_format (const gchar *date_string);
-gchar * tracker_date_format_to_iso8601 (const gchar *date_string,
- const gchar *format);
-gchar * tracker_date_to_time_string (const gchar *date_string,
- GError **error);
time_t tracker_string_to_date (const gchar *date_string,
gint *offset,
GError **error);
diff --git a/src/libtracker-extract/tracker-exif.c b/src/libtracker-extract/tracker-exif.c
index 6337c9b..0c6dcf3 100644
--- a/src/libtracker-extract/tracker-exif.c
+++ b/src/libtracker-extract/tracker-exif.c
@@ -28,6 +28,7 @@
#include <libtracker-common/tracker-date-time.h>
#include <libtracker-common/tracker-utils.h>
+#include <libtracker-extract/tracker-utils.h>
#include "tracker-exif.h"
@@ -95,7 +96,7 @@ get_date (ExifData *exif,
exif_entry_get_value (entry, buf, 1024);
/* From: ex; date "2007:04:15 15:35:58"
* To : ex. "2007-04-15T17:35:58+0200 where +0200 is localtime */
- return tracker_date_format_to_iso8601 (buf, EXIF_DATE_FORMAT);
+ return tracker_extract_date_format_to_iso8601 (buf, EXIF_DATE_FORMAT);
}
return NULL;
diff --git a/src/libtracker-extract/tracker-iptc.c b/src/libtracker-extract/tracker-iptc.c
index 783685b..c043bc5 100644
--- a/src/libtracker-extract/tracker-iptc.c
+++ b/src/libtracker-extract/tracker-iptc.c
@@ -24,6 +24,7 @@
#include <glib.h>
#include <libtracker-common/tracker-date-time.h>
+#include <libtracker-extract/tracker-utils.h>
#include "tracker-iptc.h"
@@ -101,7 +102,7 @@ foreach_dataset (IptcDataSet *dataset,
iptc_dataset_get_as_str (dataset, mbuffer, 1024);
/* From: ex; date "2007:04:15 15:35:58"
* To : ex. "2007-04-15T17:35:58+0200 where +0200 is localtime */
- data->date_created = tracker_date_format_to_iso8601 (mbuffer, IPTC_DATE_FORMAT);
+ data->date_created = tracker_extract_date_format_to_iso8601 (mbuffer, IPTC_DATE_FORMAT);
}
break;
diff --git a/src/libtracker-extract/tracker-utils.c b/src/libtracker-extract/tracker-utils.c
index fb0671d..6e9d71a 100644
--- a/src/libtracker-extract/tracker-utils.c
+++ b/src/libtracker-extract/tracker-utils.c
@@ -21,14 +21,32 @@
#include "config.h"
-#include <locale.h>
+#define _XOPEN_SOURCE
+#include <time.h>
+
+#include <strings.h>
#include <string.h>
+#include <stdlib.h>
+#include <locale.h>
#include <glib.h>
#include <glib/gi18n.h>
#include <libtracker-extract/tracker-utils.h>
#include <libtracker-common/tracker-utils.h>
+#include <libtracker-common/tracker-date-time.h>
+
+#define DATE_FORMAT_ISO8601 "%Y-%m-%dT%H:%M:%S%z"
+
+static const char *months[] = {
+ "Jan", "Feb", "Mar", "Apr", "May", "Jun",
+ "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
+};
+
+static const char imonths[] = {
+ '1', '2', '3', '4', '5',
+ '6', '7', '8', '9', '0', '1', '2'
+};
gchar *
tracker_extract_coalesce (gint n_values,
@@ -137,3 +155,384 @@ tracker_extract_text_normalize (const gchar *text,
return g_string_free (string, FALSE);
}
+
+gchar *
+tracker_extract_date_format_to_iso8601 (const gchar *date_string,
+ const gchar *format)
+{
+ gchar *result;
+ struct tm date_tm = { 0 };
+
+ g_return_val_if_fail (date_string != NULL, NULL);
+ g_return_val_if_fail (format != NULL, NULL);
+
+ if (strptime (date_string, format, &date_tm) == 0) {
+ return NULL;
+ }
+
+ result = g_malloc (sizeof (char)*25);
+
+ strftime (result, 25, DATE_FORMAT_ISO8601 , &date_tm);
+
+ return result;
+}
+
+
+static gboolean
+is_int (const gchar *str)
+{
+ gint i, len;
+
+ if (!str || str[0] == '\0') {
+ return FALSE;
+ }
+
+ len = strlen (str);
+
+ for (i = 0; i < len; i++) {
+ if (!g_ascii_isdigit(str[i])) {
+ return FALSE;
+ }
+ }
+
+ return TRUE ;
+}
+
+static gint
+parse_month (const gchar *month)
+{
+ gint i;
+
+ for (i = 0; i < 12; i++) {
+ if (!strncmp (month, months[i], 3)) {
+ return i;
+ }
+ }
+
+ return -1;
+}
+
+
+/* Determine date format and convert to ISO 8601 format */
+/* FIXME We should handle all the fractions here (see ISO 8601), as well as YYYY:DDD etc */
+gchar *
+tracker_extract_guess_date (const gchar *date_string)
+{
+ gchar buf[30];
+ gint len;
+ GError *error = NULL;
+
+ if (!date_string) {
+ return NULL;
+ }
+
+ len = strlen (date_string);
+
+ /* We cannot format a date without at least a four digit
+ * year.
+ */
+ if (len < 4) {
+ return NULL;
+ }
+
+ /* Check for year only dates (EG ID3 music tags might have
+ * Audio.ReleaseDate as 4 digit year)
+ */
+ if (len == 4) {
+ if (is_int (date_string)) {
+ buf[0] = date_string[0];
+ buf[1] = date_string[1];
+ buf[2] = date_string[2];
+ buf[3] = date_string[3];
+ buf[4] = '-';
+ buf[5] = '0';
+ buf[6] = '1';
+ buf[7] = '-';
+ buf[8] = '0';
+ buf[9] = '1';
+ buf[10] = 'T';
+ buf[11] = '0';
+ buf[12] = '0';
+ buf[13] = ':';
+ buf[14] = '0';
+ buf[15] = '0';
+ buf[16] = ':';
+ buf[17] = '0';
+ buf[18] = '0';
+ buf[19] = 'Z';
+ buf[20] = '\0';
+
+ tracker_string_to_date (buf, NULL, &error);
+
+ if (error != NULL) {
+ g_error_free (error);
+ return NULL;
+ }
+
+ return g_strdup (buf);
+ } else {
+ return NULL;
+ }
+ } else if (len == 10) {
+ /* Check for date part only YYYY-MM-DD*/
+ buf[0] = date_string[0];
+ buf[1] = date_string[1];
+ buf[2] = date_string[2];
+ buf[3] = date_string[3];
+ buf[4] = '-';
+ buf[5] = date_string[5];
+ buf[6] = date_string[6];
+ buf[7] = '-';
+ buf[8] = date_string[8];
+ buf[9] = date_string[9];
+ buf[10] = 'T';
+ buf[11] = '0';
+ buf[12] = '0';
+ buf[13] = ':';
+ buf[14] = '0';
+ buf[15] = '0';
+ buf[16] = ':';
+ buf[17] = '0';
+ buf[18] = '0';
+ buf[19] = '\0';
+
+ tracker_string_to_date (buf, NULL, &error);
+
+ if (error != NULL) {
+ g_error_free (error);
+ return NULL;
+ }
+
+ return g_strdup (buf);
+ } else if (len == 14) {
+ /* Check for pdf format EG 20050315113224-08'00' or
+ * 20050216111533Z
+ */
+ buf[0] = date_string[0];
+ buf[1] = date_string[1];
+ buf[2] = date_string[2];
+ buf[3] = date_string[3];
+ buf[4] = '-';
+ buf[5] = date_string[4];
+ buf[6] = date_string[5];
+ buf[7] = '-';
+ buf[8] = date_string[6];
+ buf[9] = date_string[7];
+ buf[10] = 'T';
+ buf[11] = date_string[8];
+ buf[12] = date_string[9];
+ buf[13] = ':';
+ buf[14] = date_string[10];
+ buf[15] = date_string[11];
+ buf[16] = ':';
+ buf[17] = date_string[12];
+ buf[18] = date_string[13];
+ buf[19] = '\0';
+
+ tracker_string_to_date (buf, NULL, &error);
+
+ if (error != NULL) {
+ g_error_free (error);
+ return NULL;
+ }
+
+ return g_strdup (buf);
+ } else if (len == 15 && date_string[14] == 'Z') {
+ buf[0] = date_string[0];
+ buf[1] = date_string[1];
+ buf[2] = date_string[2];
+ buf[3] = date_string[3];
+ buf[4] = '-';
+ buf[5] = date_string[4];
+ buf[6] = date_string[5];
+ buf[7] = '-';
+ buf[8] = date_string[6];
+ buf[9] = date_string[7];
+ buf[10] = 'T';
+ buf[11] = date_string[8];
+ buf[12] = date_string[9];
+ buf[13] = ':';
+ buf[14] = date_string[10];
+ buf[15] = date_string[11];
+ buf[16] = ':';
+ buf[17] = date_string[12];
+ buf[18] = date_string[13];
+ buf[19] = 'Z';
+ buf[20] = '\0';
+
+ tracker_string_to_date (buf, NULL, &error);
+
+ if (error != NULL) {
+ g_error_free (error);
+ return NULL;
+ }
+
+ return g_strdup (buf);
+ } else if (len == 21 && (date_string[14] == '-' || date_string[14] == '+' )) {
+ buf[0] = date_string[0];
+ buf[1] = date_string[1];
+ buf[2] = date_string[2];
+ buf[3] = date_string[3];
+ buf[4] = '-';
+ buf[5] = date_string[4];
+ buf[6] = date_string[5];
+ buf[7] = '-';
+ buf[8] = date_string[6];
+ buf[9] = date_string[7];
+ buf[10] = 'T';
+ buf[11] = date_string[8];
+ buf[12] = date_string[9];
+ buf[13] = ':';
+ buf[14] = date_string[10];
+ buf[15] = date_string[11];
+ buf[16] = ':';
+ buf[17] = date_string[12];
+ buf[18] = date_string[13];
+ buf[19] = date_string[14];
+ buf[20] = date_string[15];
+ buf[21] = date_string[16];
+ buf[22] = ':';
+ buf[23] = date_string[18];
+ buf[24] = date_string[19];
+ buf[25] = '\0';
+
+ tracker_string_to_date (buf, NULL, &error);
+
+ if (error != NULL) {
+ g_error_free (error);
+ return NULL;
+ }
+
+ return g_strdup (buf);
+ } else if ((len == 24) && (date_string[3] == ' ')) {
+ /* Check for msoffice date format "Mon Feb 9 10:10:00 2004" */
+ gint num_month;
+ gchar mon1;
+ gchar day1;
+
+ num_month = parse_month (date_string + 4);
+
+ mon1 = imonths[num_month];
+
+ if (date_string[8] == ' ') {
+ day1 = '0';
+ } else {
+ day1 = date_string[8];
+ }
+
+ buf[0] = date_string[20];
+ buf[1] = date_string[21];
+ buf[2] = date_string[22];
+ buf[3] = date_string[23];
+ buf[4] = '-';
+
+ if (num_month < 10) {
+ buf[5] = '0';
+ buf[6] = mon1;
+ } else {
+ buf[5] = '1';
+ buf[6] = mon1;
+ }
+
+ buf[7] = '-';
+ buf[8] = day1;
+ buf[9] = date_string[9];
+ buf[10] = 'T';
+ buf[11] = date_string[11];
+ buf[12] = date_string[12];
+ buf[13] = ':';
+ buf[14] = date_string[14];
+ buf[15] = date_string[15];
+ buf[16] = ':';
+ buf[17] = date_string[17];
+ buf[18] = date_string[18];
+ buf[19] = '\0';
+
+ tracker_string_to_date (buf, NULL, &error);
+
+ if (error != NULL) {
+ g_error_free (error);
+ return NULL;
+ }
+
+ return g_strdup (buf);
+ } else if ((len == 19) && (date_string[4] == ':') && (date_string[7] == ':')) {
+ /* Check for Exif date format "2005:04:29 14:56:54" */
+ buf[0] = date_string[0];
+ buf[1] = date_string[1];
+ buf[2] = date_string[2];
+ buf[3] = date_string[3];
+ buf[4] = '-';
+ buf[5] = date_string[5];
+ buf[6] = date_string[6];
+ buf[7] = '-';
+ buf[8] = date_string[8];
+ buf[9] = date_string[9];
+ buf[10] = 'T';
+ buf[11] = date_string[11];
+ buf[12] = date_string[12];
+ buf[13] = ':';
+ buf[14] = date_string[14];
+ buf[15] = date_string[15];
+ buf[16] = ':';
+ buf[17] = date_string[17];
+ buf[18] = date_string[18];
+ buf[19] = '\0';
+
+ tracker_string_to_date (buf, NULL, &error);
+
+ if (error != NULL) {
+ g_error_free (error);
+ return NULL;
+ }
+
+ return g_strdup (buf);
+ } else if ((len == 28) && (date_string[4] == '-') && (date_string[10] == 'T')
+ && (date_string[19] == '.') ) {
+ /* The fraction of seconds ISO 8601 "YYYY-MM-DDThh:mm:ss.ff+zz:zz" */
+ buf[0] = date_string[0];
+ buf[1] = date_string[1];
+ buf[2] = date_string[2];
+ buf[3] = date_string[3];
+ buf[4] = '-';
+ buf[5] = date_string[5];
+ buf[6] = date_string[6];
+ buf[7] = '-';
+ buf[8] = date_string[8];
+ buf[9] = date_string[9];
+ buf[10] = 'T';
+ buf[11] = date_string[11];
+ buf[12] = date_string[12];
+ buf[13] = ':';
+ buf[14] = date_string[14];
+ buf[15] = date_string[15];
+ buf[16] = ':';
+ buf[17] = date_string[17];
+ buf[18] = date_string[18];
+ buf[19] = date_string[22];
+ buf[20] = date_string[23];
+ buf[21] = date_string[24];
+ buf[22] = ':';
+ buf[23] = date_string[26];
+ buf[24] = date_string[27];
+ buf[25] = '\0';
+
+ tracker_string_to_date (buf, NULL, &error);
+
+ if (error != NULL) {
+ g_error_free (error);
+ return NULL;
+ }
+
+ return g_strdup (buf);
+ }
+
+ tracker_string_to_date (date_string, NULL, &error);
+
+ if (error != NULL) {
+ g_error_free (error);
+ return NULL;
+ }
+
+ return g_strdup (date_string);
+}
diff --git a/src/libtracker-extract/tracker-utils.h b/src/libtracker-extract/tracker-utils.h
index f247cba..ab114fc 100644
--- a/src/libtracker-extract/tracker-utils.h
+++ b/src/libtracker-extract/tracker-utils.h
@@ -39,6 +39,10 @@ gchar * tracker_extract_text_normalize (const gchar *text,
guint max_words,
guint *n_words);
+gchar * tracker_extract_guess_date (const gchar *date_string);
+gchar * tracker_extract_date_format_to_iso8601 (const gchar *date_string,
+ const gchar *format);
+
G_END_DECLS
#endif /* __LIBTRACKER_EXTRACT_UTILS_H__ */
diff --git a/src/libtracker-extract/tracker-xmp.c b/src/libtracker-extract/tracker-xmp.c
index 1880459..58527b0 100644
--- a/src/libtracker-extract/tracker-xmp.c
+++ b/src/libtracker-extract/tracker-xmp.c
@@ -267,7 +267,7 @@ iterate_simple (const gchar *uri,
if (!data->title2 && g_ascii_strcasecmp (name, "Title") == 0) {
data->title2 = g_strdup (value);
} else if (g_ascii_strcasecmp (name, "DateTimeOriginal") == 0 && !data->time_original) {
- data->time_original = g_strdup (value);
+ data->time_original = tracker_extract_guess_date (value);
} else if (!data->artist && g_ascii_strcasecmp (name, "Artist") == 0) {
data->artist = g_strdup (value);
/* } else if (g_ascii_strcasecmp (name, "Software") == 0) {
@@ -318,7 +318,7 @@ iterate_simple (const gchar *uri,
} else if (!data->description && g_ascii_strcasecmp (name, "description") == 0) {
data->description = g_strdup (value);
} else if (!data->date && g_ascii_strcasecmp (name, "date") == 0) {
- data->date = g_strdup (value);
+ data->date = tracker_extract_guess_date (value);
} else if (!data->keywords && g_ascii_strcasecmp (name, "keywords") == 0) {
data->keywords = g_strdup (value);
} else if (!data->subject && g_ascii_strcasecmp (name, "subject") == 0) {
diff --git a/src/tracker-extract/tracker-extract-flac.c b/src/tracker-extract/tracker-extract-flac.c
index 840e209..2df9f33 100644
--- a/src/tracker-extract/tracker-extract-flac.c
+++ b/src/tracker-extract/tracker-extract-flac.c
@@ -121,7 +121,7 @@ parse_vorbis_comments (FLAC__StreamMetadata_VorbisComment *comment,
} else if (g_ascii_strncasecmp (entry.entry, "albumpeakgain", 13) == 0) {
fd->albumpeakgain = g_strdup (entry.entry + 14);
} else if (g_ascii_strncasecmp (entry.entry, "date", 4) == 0) {
- fd->date = g_strdup (entry.entry + 5);
+ fd->date = tracker_extract_guess_date (entry.entry + 5);
} else if (g_ascii_strncasecmp (entry.entry, "comment", 7) == 0) {
fd->comment = g_strdup (entry.entry + 8);
} else if (g_ascii_strncasecmp (entry.entry, "genre", 5) == 0) {
@@ -268,7 +268,7 @@ extract_flac (const gchar *uri,
add_tuple (metadata, "nmm:albumGain", fd.albumgain);
add_tuple (metadata, "nmm:albumPeakGain", fd.albumpeakgain);
add_tuple (metadata, "nie:comment", fd.comment);
- add_tuple (metadata, "nie:contentCreated", "2003-08-22T19:52:10Z");
+ add_tuple (metadata, "nie:contentCreated", fd.date);
add_tuple (metadata, "nfo:genre", fd.genre);
add_tuple (metadata, "nie:plainTextContent", fd.lyrics);
add_tuple (metadata, "nie:copyright", fd.copyright);
diff --git a/src/tracker-extract/tracker-extract-libxine.c b/src/tracker-extract/tracker-extract-libxine.c
index 31942b1..85897b5 100644
--- a/src/tracker-extract/tracker-extract-libxine.c
+++ b/src/tracker-extract/tracker-extract-libxine.c
@@ -60,7 +60,7 @@ tracker_extract_xine (const gchar *uri,
const char *title;
const char *author;
const char *album;
- const char *year;
+ gchar *year;
const char *genre;
const char *track;
@@ -248,10 +248,11 @@ tracker_extract_xine (const gchar *uri,
tracker_sparql_builder_object_unvalidated (metadata, title);
}
- year = xine_get_meta_info (stream, XINE_META_INFO_YEAR);
+ year = tracker_extract_guess_date (xine_get_meta_info (stream, XINE_META_INFO_YEAR));
if (year) {
tracker_sparql_builder_predicate (metadata, "nie:contentCreated");
tracker_sparql_builder_object_unvalidated (metadata, year);
+ g_free (year);
}
genre = xine_get_meta_info (stream, XINE_META_INFO_GENRE);
diff --git a/src/tracker-extract/tracker-extract-mp3.c b/src/tracker-extract/tracker-extract-mp3.c
index 2c78104..338f35b 100644
--- a/src/tracker-extract/tracker-extract-mp3.c
+++ b/src/tracker-extract/tracker-extract-mp3.c
@@ -742,7 +742,7 @@ get_id3 (const gchar *data,
pos += 30;
year = g_convert (pos, 4, "UTF-8", encoding, NULL, NULL, NULL);
if (atoi (year) > 0) {
- id3->recording_time = tracker_date_format (year);
+ id3->recording_time = tracker_extract_guess_date (year);
}
g_free (year);
@@ -1235,11 +1235,12 @@ get_id3v24_tags (const gchar *data,
tag->copyright = word;
break;
case ID3V24_TDRC:
- tag->recording_time = tracker_date_format (word);
+ tag->recording_time = tracker_extract_guess_date (word);
g_free (word);
break;
case ID3V24_TDRL:
- tag->release_time = word;
+ tag->release_time = tracker_extract_guess_date (word);
+ g_free (word);
break;
case ID3V24_TEXT:
tag->text = word;
@@ -1286,7 +1287,7 @@ get_id3v24_tags (const gchar *data,
}
case ID3V24_TYER:
if (atoi (word) > 0) {
- tag->recording_time = tracker_date_format (word);
+ tag->recording_time = tracker_extract_guess_date (word);
}
g_free (word);
break;
@@ -1488,7 +1489,7 @@ get_id3v23_tags (const gchar *data,
}
case ID3V24_TYER:
if (atoi (word) > 0) {
- tag->recording_time = tracker_date_format (word);
+ tag->recording_time = tracker_extract_guess_date (word);
}
g_free (word);
break;
@@ -1623,7 +1624,7 @@ get_id3v20_tags (const gchar *data,
break;
case ID3V2_TYE:
if (atoi (word) > 0) {
- tag->recording_time = tracker_date_format (word);
+ tag->recording_time = tracker_extract_guess_date (word);
}
g_free (word);
break;
diff --git a/src/tracker-extract/tracker-extract-mplayer.c b/src/tracker-extract/tracker-extract-mplayer.c
index 73786ed..f43ddb2 100644
--- a/src/tracker-extract/tracker-extract-mplayer.c
+++ b/src/tracker-extract/tracker-extract-mplayer.c
@@ -83,7 +83,7 @@ static const gchar *info_tags[][2] = {
{ "Album", "nie:title" },
{ "Year", "nie:contentCreated" },
{ "copyright", "nie:copyright" },
- { NULL, NULL, }
+ { NULL, NULL, }
};
typedef struct {
@@ -220,7 +220,10 @@ extract_mplayer (const gchar *uri,
equal_char_pos = strchr (next_line, '=');
- data = g_strdup (equal_char_pos + 1);
+ if (g_strcmp0 (info_tags[i][0], "Year") == 0)
+ date = tracker_extract_guess_date (equal_char_pos + 1);
+ else
+ data = g_strdup (equal_char_pos + 1);
if (data) {
if (data[0] != '\0') {
diff --git a/src/tracker-extract/tracker-extract-msoffice.c b/src/tracker-extract/tracker-extract-msoffice.c
index f9e828c..fbe2ef9 100644
--- a/src/tracker-extract/tracker-extract-msoffice.c
+++ b/src/tracker-extract/tracker-extract-msoffice.c
@@ -109,7 +109,8 @@ add_gvalue_in_metadata (TrackerSparqlBuilder *metadata,
const gchar *key,
GValue const *val,
const gchar *type,
- const gchar *predicate)
+ const gchar *predicate,
+ gboolean is_date)
{
gchar *s;
@@ -137,17 +138,32 @@ add_gvalue_in_metadata (TrackerSparqlBuilder *metadata,
len = strlen (s);
if (s[len - 1] == '"') {
- str_val = (len > 2 ? g_strndup (s + 1, len - 2) : NULL);
+ if (is_date) {
+ if (len > 2) {
+ gchar *str = g_strndup (s + 1, len - 2);
+ str_val = tracker_extract_guess_date (str);
+ g_free (str);
+ } else {
+ str_val = NULL;
+ }
+ } else
+ str_val = (len > 2 ? g_strndup (s + 1, len - 2) : NULL);
} else {
/* We have a string that begins with a double
* quote but which finishes by something
* different... We copy the string from the
* beginning. */
- str_val = g_strdup (s);
+ if (is_date)
+ str_val = tracker_extract_guess_date (s);
+ else
+ str_val = g_strdup (s);
}
} else {
/* Here, we probably have a number */
- str_val = g_strdup (s);
+ if (is_date)
+ str_val = tracker_extract_guess_date (s);
+ else
+ str_val = g_strdup (s);
}
if (str_val) {
@@ -191,11 +207,11 @@ metadata_cb (gpointer key,
val = gsf_doc_prop_get_val (property);
if (g_strcmp0 (name, "dc:title") == 0) {
- add_gvalue_in_metadata (metadata, uri, "nie:title", val, NULL, NULL);
+ add_gvalue_in_metadata (metadata, uri, "nie:title", val, NULL, NULL, FALSE);
} else if (g_strcmp0 (name, "dc:subject") == 0) {
- add_gvalue_in_metadata (metadata, uri, "nie:subject", val, NULL, NULL);
+ add_gvalue_in_metadata (metadata, uri, "nie:subject", val, NULL, NULL, FALSE);
} else if (g_strcmp0 (name, "dc:creator") == 0) {
- add_gvalue_in_metadata (metadata, uri, "nco:creator", val, "nco:Contact", "nco:fullname");
+ add_gvalue_in_metadata (metadata, uri, "nco:creator", val, "nco:Contact", "nco:fullname", FALSE);
} else if (g_strcmp0 (name, "dc:keywords") == 0) {
gchar *keywords = g_strdup_value_contents (val);
char *lasts, *keyw;
@@ -220,15 +236,15 @@ metadata_cb (gpointer key,
g_free (keyw);
} else if (g_strcmp0 (name, "dc:description") == 0) {
- add_gvalue_in_metadata (metadata, uri, "nie:comment", val, NULL, NULL);
+ add_gvalue_in_metadata (metadata, uri, "nie:comment", val, NULL, NULL, FALSE);
} else if (g_strcmp0 (name, "gsf:page-count") == 0) {
- add_gvalue_in_metadata (metadata, uri, "nfo:pageCount", val, NULL, NULL);
+ add_gvalue_in_metadata (metadata, uri, "nfo:pageCount", val, NULL, NULL, FALSE);
} else if (g_strcmp0 (name, "gsf:word-count") == 0) {
- add_gvalue_in_metadata (metadata, uri, "nfo:wordCount", val, NULL, NULL);
+ add_gvalue_in_metadata (metadata, uri, "nfo:wordCount", val, NULL, NULL, FALSE);
} else if (g_strcmp0 (name, "meta:creation-date") == 0) {
- add_gvalue_in_metadata (metadata, uri, "nie:contentCreated", val, NULL, NULL);
+ add_gvalue_in_metadata (metadata, uri, "nie:contentCreated", val, NULL, NULL, TRUE);
} else if (g_strcmp0 (name, "meta:generator") == 0) {
- add_gvalue_in_metadata (metadata, uri, "nie:generator", val, NULL, NULL);
+ add_gvalue_in_metadata (metadata, uri, "nie:generator", val, NULL, NULL, FALSE);
}
}
@@ -250,7 +266,7 @@ doc_metadata_cb (gpointer key,
val = gsf_doc_prop_get_val (property);
if (g_strcmp0 (name, "CreativeCommons_LicenseURL") == 0) {
- add_gvalue_in_metadata (metadata, uri, "nie:license", val, NULL, NULL);
+ add_gvalue_in_metadata (metadata, uri, "nie:license", val, NULL, NULL, FALSE);
}
}
diff --git a/src/tracker-extract/tracker-extract-oasis.c b/src/tracker-extract/tracker-extract-oasis.c
index 62eadc7..64f994e 100644
--- a/src/tracker-extract/tracker-extract-oasis.c
+++ b/src/tracker-extract/tracker-extract-oasis.c
@@ -240,8 +240,9 @@ text_handler (GMarkupParseContext *context,
GError **error)
{
ODTParseInfo *data;
- TrackerSparqlBuilder *metadata;
- const gchar *uri;
+ TrackerSparqlBuilder *metadata;
+ const gchar *uri;
+ gchar *date;
data = user_data;
metadata = data->metadata;
@@ -283,8 +284,10 @@ text_handler (GMarkupParseContext *context,
tracker_sparql_builder_object_unvalidated (metadata, text);
break;
case READ_CREATED:
+ date = tracker_extract_guess_date (text);
tracker_sparql_builder_predicate (metadata, "nie:contentCreated");
- tracker_sparql_builder_object_unvalidated (metadata, text);
+ tracker_sparql_builder_object_unvalidated (metadata, date);
+ g_free (date);
break;
case READ_GENERATOR:
tracker_sparql_builder_predicate (metadata, "nie:generator");
diff --git a/src/tracker-extract/tracker-extract-png.c b/src/tracker-extract/tracker-extract-png.c
index 643b90a..411f84c 100644
--- a/src/tracker-extract/tracker-extract-png.c
+++ b/src/tracker-extract/tracker-extract-png.c
@@ -98,7 +98,7 @@ rfc1123_to_iso8601_date (gchar *date)
/* From: ex. RFC1123 date: "22 May 1997 18:07:10 -0600"
* To : ex. ISO8601 date: "2007-05-22T18:07:10-0600"
*/
- return tracker_date_format_to_iso8601 (date, RFC1123_DATE_FORMAT);
+ return tracker_extract_date_format_to_iso8601 (date, RFC1123_DATE_FORMAT);
}
static void
diff --git a/src/tracker-extract/tracker-extract-ps.c b/src/tracker-extract/tracker-extract-ps.c
index ed936f6..3e422ea 100644
--- a/src/tracker-extract/tracker-extract-ps.c
+++ b/src/tracker-extract/tracker-extract-ps.c
@@ -145,7 +145,7 @@ hour_day_str_day (const gchar *date)
/* From: ex. date: "(18:07 Tuesday 22 May 2007)"
* To : ex. ISO8601 date: "2007-05-22T18:07:10-0600"
*/
- return tracker_date_format_to_iso8601 (date, "(%H:%M %A %d %B %Y)");
+ return tracker_extract_date_format_to_iso8601 (date, "(%H:%M %A %d %B %Y)");
}
static gchar *
@@ -154,7 +154,7 @@ day_str_month_day (const gchar *date)
/* From: ex. date: "Tue May 22 18:07:10 2007"
* To : ex. ISO8601 date: "2007-05-22T18:07:10-0600"
*/
- return tracker_date_format_to_iso8601 (date, "%A %B %d %H:%M:%S %Y");
+ return tracker_extract_date_format_to_iso8601 (date, "%A %B %d %H:%M:%S %Y");
}
static gchar *
@@ -163,7 +163,7 @@ day_month_year_date (const gchar *date)
/* From: ex. date: "22 May 1997 18:07:10 -0600"
* To : ex. ISO8601 date: "2007-05-22T18:07:10-0600"
*/
- return tracker_date_format_to_iso8601 (date, "%d %B %Y %H:%M:%S %z");
+ return tracker_extract_date_format_to_iso8601 (date, "%d %B %Y %H:%M:%S %z");
}
static gchar *
@@ -172,7 +172,7 @@ hour_month_day_date (const gchar *date)
/* From: ex. date: "6:07 PM May 22, 2007"
* To : ex. ISO8601 date: "2007-05-22T18:07:10-0600"
*/
- return tracker_date_format_to_iso8601 (date, "%I:%M %p %B %d, %Y");
+ return tracker_extract_date_format_to_iso8601 (date, "%I:%M %p %B %d, %Y");
}
static gchar *
diff --git a/src/tracker-extract/tracker-extract-tiff.c b/src/tracker-extract/tracker-extract-tiff.c
index d385e12..78c35d4 100644
--- a/src/tracker-extract/tracker-extract-tiff.c
+++ b/src/tracker-extract/tracker-extract-tiff.c
@@ -334,8 +334,11 @@ extract_tiff (const gchar *uri,
tiff_data.artist = get_value (image, TIFFTAG_ARTIST, TIFF_TAGTYPE_STRING);
if (!tiff_data.copyright)
tiff_data.copyright = get_value (image, TIFFTAG_COPYRIGHT, TIFF_TAGTYPE_STRING);
- if (!tiff_data.datetime)
- tiff_data.datetime = get_value (image, TIFFTAG_DATETIME, TIFF_TAGTYPE_STRING);
+ if (!tiff_data.datetime) {
+ gchar *date = get_value (image, TIFFTAG_DATETIME, TIFF_TAGTYPE_STRING);
+ tiff_data.datetime = tracker_extract_guess_date (date);
+ g_free (date);
+ }
if (!tiff_data.documentname)
tiff_data.documentname = get_value (image, TIFFTAG_DOCUMENTNAME, TIFF_TAGTYPE_STRING);
if (!tiff_data.imagedescription)
@@ -355,8 +358,11 @@ extract_tiff (const gchar *uri,
exif_data.fnumber = get_value (image, EXIFTAG_FNUMBER, TIFF_TAGTYPE_DOUBLE);
if (!exif_data.iso_speed_ratings)
exif_data.iso_speed_ratings = get_value (image, EXIFTAG_ISOSPEEDRATINGS, TIFF_TAGTYPE_C16_UINT16);
- if (!exif_data.time_original)
- exif_data.time_original = get_value (image, EXIFTAG_DATETIMEORIGINAL, TIFF_TAGTYPE_STRING);
+ if (!exif_data.time_original) {
+ gchar *date = get_value (image, EXIFTAG_DATETIMEORIGINAL, TIFF_TAGTYPE_STRING);
+ exif_data.time_original = tracker_extract_guess_date (date);
+ g_free (date);
+ }
if (!exif_data.metering_mode)
exif_data.metering_mode = get_metering_mode (image);
if (!exif_data.flash)
diff --git a/src/tracker-extract/tracker-extract-vorbis.c b/src/tracker-extract/tracker-extract-vorbis.c
index 4ab00cf..7fbe1c5 100644
--- a/src/tracker-extract/tracker-extract-vorbis.c
+++ b/src/tracker-extract/tracker-extract-vorbis.c
@@ -112,6 +112,7 @@ extract_vorbis (const char *uri,
}
if ((comment = ov_comment (&vf, -1)) != NULL) {
+ gchar *date;
vorbis_data.title = ogg_get_comment (comment, "title");
vorbis_data.artist = ogg_get_comment (comment, "artist");
vorbis_data.album = ogg_get_comment (comment, "album");
@@ -124,7 +125,9 @@ extract_vorbis (const char *uri,
vorbis_data.TrackPeakGain = ogg_get_comment (comment, "TrackPeakGain");
vorbis_data.AlbumGain = ogg_get_comment (comment, "AlbumGain");
vorbis_data.AlbumPeakGain = ogg_get_comment (comment, "AlbumPeakGain");
- vorbis_data.date = ogg_get_comment (comment, "date");
+ date = ogg_get_comment (comment, "date");
+ vorbis_data.date = tracker_extract_guess_date (date);
+ g_free (date);
vorbis_data.comment = ogg_get_comment (comment, "comment");
vorbis_data.genre = ogg_get_comment (comment, "genre");
vorbis_data.Codec = ogg_get_comment (comment, "Codec");
diff --git a/tests/Makefile.am b/tests/Makefile.am
index df9a5e9..d51f877 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -3,6 +3,7 @@ include $(top_srcdir)/Makefile.decl
SUBDIRS = \
common \
libtracker-common \
+ libtracker-extract \
libtracker-data \
libtracker-db \
libtracker-fts \
diff --git a/tests/libtracker-common/tracker-type-utils-test.c b/tests/libtracker-common/tracker-type-utils-test.c
index ba1cfc7..ed1cd1b 100644
--- a/tests/libtracker-common/tracker-type-utils-test.c
+++ b/tests/libtracker-common/tracker-type-utils-test.c
@@ -27,45 +27,6 @@
#include <tracker-test-helpers.h>
-static void
-test_date_format (void)
-{
- gchar *result;
-
- result = tracker_date_format ("");
- g_assert (result == NULL);
-
- /* Fails
- result = tracker_date_format ("1978"); //Audio.ReleaseDate
- g_assert (tracker_test_helpers_cmpstr_equal (result, "1978-01-01T00:00:00"));
- */
-
- result = tracker_date_format ("2008-06-14");
- g_assert (tracker_test_helpers_cmpstr_equal (result, "2008-06-14T00:00:00"));
- g_free (result);
-
- result = tracker_date_format ("20080614000000");
- g_assert (tracker_test_helpers_cmpstr_equal (result, "2008-06-14T00:00:00"));
- g_free (result);
-
- result = tracker_date_format ("20080614000000Z");
- g_assert (tracker_test_helpers_cmpstr_equal (result, "2008-06-14T00:00:00Z"));
- g_free (result);
-
- result = tracker_date_format ("Mon Jun 14 04:20:20 2008"); /* MS Office */
- g_assert (tracker_test_helpers_cmpstr_equal (result, "2008-06-14T04:20:20"));
- g_free (result);
-
- result = tracker_date_format ("2008:06:14 04:20:20"); /* Exif style */
- g_assert (tracker_test_helpers_cmpstr_equal (result, "2008-06-14T04:20:20"));
- g_free (result);
-
- if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR)) {
- result = tracker_date_format (NULL);
- }
-
- g_test_trap_assert_failed ();
-}
static void
test_string_to_date (void)
@@ -423,8 +384,6 @@ main (int argc, char **argv)
test_int_to_string);
g_test_add_func ("/libtracker-common/tracker-type-utils/long_to_string",
test_long_to_string);
- g_test_add_func ("/libtracker-common/tracker-type-utils/date_format",
- test_date_format);
g_test_add_func ("/libtracker-common/tracker-type-utils/date_to_string",
test_date_to_string);
g_test_add_func ("/libtracker-common/tracker-type-utils/string_to_date",
diff --git a/tests/libtracker-extract/Makefile.am b/tests/libtracker-extract/Makefile.am
new file mode 100644
index 0000000..da8b180
--- /dev/null
+++ b/tests/libtracker-extract/Makefile.am
@@ -0,0 +1,33 @@
+include $(top_srcdir)/Makefile.decl
+
+noinst_PROGRAMS = $(TEST_PROGS)
+
+TEST_PROGS += \
+ tracker-utils
+
+INCLUDES = \
+ -DG_LOG_DOMAIN=\"Tracker\" \
+ -DTRACKER_COMPILATION \
+ -I$(top_srcdir)/src \
+ -I$(top_srcdir)/tests/common \
+ $(WARN_CFLAGS) \
+ $(GLIB2_CFLAGS) \
+ $(GCOV_CFLAGS) \
+ $(GMODULE_CFLAGS) \
+ $(GTHREAD_CFLAGS) \
+ $(PANGO_CFLAGS) \
+ $(DBUS_CFLAGS)
+
+tracker_utils_SOURCES = \
+ tracker-utils-test.c
+
+tracker_utils_LDADD = \
+ $(top_builddir)/tests/common/libtracker-testcommon.la \
+ $(top_builddir)/src/libtracker-common/libtracker-common.la \
+ $(top_builddir)/src/libtracker-extract/libtracker-extract- TRACKER_API_VERSION@.la \
+ $(GMODULE_LIBS) \
+ $(GTHREAD_LIBS) \
+ $(GOBJECT_LIBS) \
+ $(GLIB2_LIBS) \
+ $(GCOV_LIBS)
+
diff --git a/tests/libtracker-extract/tracker-utils-test.c b/tests/libtracker-extract/tracker-utils-test.c
new file mode 100644
index 0000000..0424854
--- /dev/null
+++ b/tests/libtracker-extract/tracker-utils-test.c
@@ -0,0 +1,81 @@
+/*
+ * Copyright (C) 2009, Nokia
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ * Authors: Philip Van Hoof <philip codeminded be>
+ */
+
+#include <time.h>
+#include <string.h>
+
+#include <glib-object.h>
+
+#include <libtracker-common/tracker-date-time.h>
+#include <libtracker-extract/tracker-utils.h>
+
+#include <tracker-test-helpers.h>
+
+static void
+test_guess_date (void)
+{
+ gchar *result;
+
+ result = tracker_extract_guess_date ("");
+ g_assert (result == NULL);
+
+ result = tracker_extract_guess_date ("2008-06-14");
+ g_assert (tracker_test_helpers_cmpstr_equal (result, "2008-06-14T00:00:00"));
+ g_free (result);
+
+ result = tracker_extract_guess_date ("20080614000000");
+ g_assert (tracker_test_helpers_cmpstr_equal (result, "2008-06-14T00:00:00"));
+ g_free (result);
+
+ result = tracker_extract_guess_date ("20080614000000Z");
+ g_assert (tracker_test_helpers_cmpstr_equal (result, "2008-06-14T00:00:00Z"));
+ g_free (result);
+
+ result = tracker_extract_guess_date ("Mon Jun 14 04:20:20 2008"); /* MS Office */
+ g_assert (tracker_test_helpers_cmpstr_equal (result, "2008-06-14T04:20:20"));
+ g_free (result);
+
+ result = tracker_extract_guess_date ("2008:06:14 04:20:20"); /* Exif style */
+ g_assert (tracker_test_helpers_cmpstr_equal (result, "2008-06-14T04:20:20"));
+ g_free (result);
+
+ if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR)) {
+ result = tracker_extract_guess_date (NULL);
+ }
+
+ g_test_trap_assert_failed ();
+}
+
+int
+main (int argc, char **argv)
+{
+ gint result;
+
+ g_type_init ();
+ g_test_init (&argc, &argv, NULL);
+
+ g_test_add_func ("/libtracker-extract/tracker-utils/guess_date",
+ test_guess_date);
+
+ result = g_test_run ();
+
+ return result;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]