r22612 - gnucash/trunk/src/libqof/qof - Work around the way g_date_time_new truncates microseconds.

John Ralls jralls at code.gnucash.org
Sat Dec 1 17:43:25 EST 2012


Author: jralls
Date: 2012-12-01 17:43:25 -0500 (Sat, 01 Dec 2012)
New Revision: 22612
Trac: http://svn.gnucash.org/trac/changeset/22612

Modified:
   gnucash/trunk/src/libqof/qof/gnc-date.c
Log:
Work around the way g_date_time_new truncates microseconds.

Modified: gnucash/trunk/src/libqof/qof/gnc-date.c
===================================================================
--- gnucash/trunk/src/libqof/qof/gnc-date.c	2012-12-01 22:43:16 UTC (rev 22611)
+++ gnucash/trunk/src/libqof/qof/gnc-date.c	2012-12-01 22:43:25 UTC (rev 22612)
@@ -162,6 +162,13 @@
 	return gdt;
     tz = gnc_g_time_zone_adjust_for_dst (tz, gdt);
     g_date_time_unref (gdt);
+/* g_date_time_new truncates nanoseconds to microseconds. Sometimes in
+ * converting (particularly when parsing from a string) the
+ * nanoseconds will have lost 1/2 a femtosecond or so. Adding 1/2 a
+ * nano second ensures that the truncation doesn't lose a micorsecond
+ * in translation.
+ */
+    seconds += 5e-10;
     gdt =  g_date_time_new (tz, year, month, day, hour, minute, seconds);
     g_time_zone_unref (tz);
     return gdt;
@@ -1427,7 +1434,10 @@
 	g_time_zone_unref (tz);
     }
     else /* No zone info, assume UTC */
+    {
+	second += 5e-10;
 	gdt = g_date_time_new_utc (year, month, day, hour, minute, second);
+    }
 
     time.tv_sec = g_date_time_to_unix (gdt);
     time.tv_nsec = g_date_time_get_microsecond (gdt) * 1000;



More information about the gnucash-changes mailing list