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


git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@17454 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Charles Day
2008-08-04 16:41:15 +00:00
parent 1f96188647
commit 96863860d0

View File

@@ -1578,7 +1578,10 @@ gnc_pricedb_lookup_nearest_in_time(GNCPriceDB *db,
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;