[tracker/tracker-0.10] libtracker-common: Fix tracker_date_to_string for timestamps before 1970
- From: JÃrg Billeter <juergbi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/tracker-0.10] libtracker-common: Fix tracker_date_to_string for timestamps before 1970
- Date: Fri, 2 Dec 2011 11:07:03 +0000 (UTC)
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]