[tracker/tracker-0.10] libtracker-common: Fix tracker_date_to_string for timestamps before 1970



commit e72dd5465edcbc8b2b9d19e8c8521bf6d5932a70
Author: JÃrg Billeter <j bitron ch>
Date:   Thu Dec 1 15:56:56 2011 +0100

    libtracker-common: Fix tracker_date_to_string for timestamps before 1970

 src/libtracker-common/tracker-date-time.c |    9 +++++++--
 1 files changed, 7 insertions(+), 2 deletions(-)
---
diff --git a/src/libtracker-common/tracker-date-time.c b/src/libtracker-common/tracker-date-time.c
index 8e42bd2..c1570b9 100644
--- a/src/libtracker-common/tracker-date-time.c
+++ b/src/libtracker-common/tracker-date-time.c
@@ -200,6 +200,7 @@ tracker_date_to_string (gdouble date_time)
 {
 	gchar     buffer[30];
 	time_t seconds;
+	gint64 total_milliseconds;
 	gint milliseconds;
 	struct tm utc_time;
 	size_t    count;
@@ -207,8 +208,12 @@ tracker_date_to_string (gdouble date_time)
 	memset (buffer, '\0', sizeof (buffer));
 	memset (&utc_time, 0, sizeof (struct tm));
 
-	seconds = (time_t) date_time;
-	milliseconds = (gint) (fmod (date_time, 1) * 1000);
+	total_milliseconds = (gint64) round (date_time * 1000);
+	milliseconds = total_milliseconds % 1000;
+	if (milliseconds < 0) {
+		milliseconds += 1000;
+	}
+	seconds = (time_t) ((total_milliseconds - milliseconds) / 1000);
 	gmtime_r (&seconds, &utc_time);
 
 	/* Output is ISO 8601 format : "YYYY-MM-DDThh:mm:ss" */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]