Commit e72dd546 authored by Jürg Billeter's avatar Jürg Billeter

libtracker-common: Fix tracker_date_to_string for timestamps before 1970

parent b27902da
......@@ -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" */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment