r17520 - gnucash/branches/2.2/src/engine - [r17454] Bug #541970: When finding a "nearest in time" price, break ties by preferring the older price.

Andreas Köhler andi5 at cvs.gnucash.org
Sun Sep 14 17:30:54 EDT 2008


Author: andi5
Date: 2008-09-14 17:30:54 -0400 (Sun, 14 Sep 2008)
New Revision: 17520
Trac: http://svn.gnucash.org/trac/changeset/17520

Modified:
   gnucash/branches/2.2/src/engine/gnc-pricedb.c
Log:
[r17454] 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.

Committed by cedayiv.

Modified: gnucash/branches/2.2/src/engine/gnc-pricedb.c
===================================================================
--- gnucash/branches/2.2/src/engine/gnc-pricedb.c	2008-09-14 21:30:46 UTC (rev 17519)
+++ gnucash/branches/2.2/src/engine/gnc-pricedb.c	2008-09-14 21:30:54 UTC (rev 17520)
@@ -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