AUDIT: r17454 - gnucash/trunk/src/engine - Bug #541970: When finding a "nearest in time" price, break ties by preferring the older price. This has the benefit of using a price that actually existed at the given time, and better addresses the case in which both price times have been defaulted to midnight. Previously, the newer price was preferred.

Charles Day cedayiv at cvs.gnucash.org
Mon Aug 4 12:41:15 EDT 2008


Author: cedayiv
Date: 2008-08-04 12:41:15 -0400 (Mon, 04 Aug 2008)
New Revision: 17454
Trac: http://svn.gnucash.org/trac/changeset/17454

Modified:
   gnucash/trunk/src/engine/gnc-pricedb.c
Log:
Bug #541970: When finding a "nearest in time" price, break ties by preferring the older price. This has the benefit of using a price that actually existed at the given time, and better addresses the case in which both price times have been defaulted to midnight. Previously, the newer price was preferred.
BP


Modified: gnucash/trunk/src/engine/gnc-pricedb.c
===================================================================
--- gnucash/trunk/src/engine/gnc-pricedb.c	2008-08-03 18:10:27 UTC (rev 17453)
+++ gnucash/trunk/src/engine/gnc-pricedb.c	2008-08-04 16:41:15 UTC (rev 17454)
@@ -1578,7 +1578,10 @@
       Timespec abs_current = timespec_abs(&diff_current);
       Timespec abs_next = timespec_abs(&diff_next);
 
-      if (timespec_cmp(&abs_current, &abs_next) <= 0) {
+      /* Choose the price that is closest to the given time. In case of
+       * a tie, prefer the older price since it actually existed at the
+       * time. (This also fixes bug #541970.) */
+      if (timespec_cmp(&abs_current, &abs_next) < 0) {
         result = current_price;
       } else {
         result = next_price;



More information about the gnucash-changes mailing list