mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-16 18:25:11 -06:00
Change gnc_pricedb_convert_balance_nearest_price from timespec to time64.
This commit is contained in:
parent
74ddb671e4
commit
ca22d5531b
@ -142,8 +142,6 @@ gnc_ui_accounts_recurse (Account *parent, GList **currency_list,
|
||||
GNCCurrencyAcc *non_curr_accum = NULL;
|
||||
GList *children, *node;
|
||||
gboolean non_currency = FALSE;
|
||||
Timespec end_timespec;
|
||||
Timespec start_timespec;
|
||||
|
||||
if (parent == NULL) return;
|
||||
|
||||
@ -190,12 +188,11 @@ gnc_ui_accounts_recurse (Account *parent, GList **currency_list,
|
||||
case ACCT_TYPE_PAYABLE:
|
||||
case ACCT_TYPE_RECEIVABLE:
|
||||
end_amount = xaccAccountGetBalanceAsOfDate(account, options.end_date);
|
||||
timespecFromTime64(&end_timespec, options.end_date);
|
||||
end_amount_default_currency =
|
||||
gnc_pricedb_convert_balance_nearest_price (pricedb, end_amount,
|
||||
account_currency,
|
||||
to_curr,
|
||||
end_timespec);
|
||||
options.end_date);
|
||||
|
||||
if (!non_currency || options.non_currency)
|
||||
{
|
||||
@ -226,20 +223,18 @@ gnc_ui_accounts_recurse (Account *parent, GList **currency_list,
|
||||
case ACCT_TYPE_INCOME:
|
||||
case ACCT_TYPE_EXPENSE:
|
||||
start_amount = xaccAccountGetBalanceAsOfDate(account, options.start_date);
|
||||
timespecFromTime64(&start_timespec, options.start_date);
|
||||
start_amount_default_currency =
|
||||
gnc_pricedb_convert_balance_nearest_price (pricedb,
|
||||
start_amount,
|
||||
account_currency,
|
||||
to_curr,
|
||||
start_timespec);
|
||||
options.start_date);
|
||||
end_amount = xaccAccountGetBalanceAsOfDate(account, options.end_date);
|
||||
timespecFromTime64(&end_timespec, options.end_date);
|
||||
end_amount_default_currency =
|
||||
gnc_pricedb_convert_balance_nearest_price (pricedb, end_amount,
|
||||
account_currency,
|
||||
to_curr,
|
||||
end_timespec);
|
||||
options.end_date);
|
||||
|
||||
if (!non_currency || options.non_currency)
|
||||
{
|
||||
|
@ -3433,11 +3433,8 @@ xaccAccountConvertBalanceToCurrencyAsOfDate(const Account *acc, /* for book */
|
||||
book = gnc_account_get_book (acc);
|
||||
pdb = gnc_pricedb_get_db (book);
|
||||
|
||||
ts.tv_sec = date;
|
||||
ts.tv_nsec = 0;
|
||||
|
||||
balance = gnc_pricedb_convert_balance_nearest_price(
|
||||
pdb, balance, balance_currency, new_currency, ts);
|
||||
pdb, balance, balance_currency, new_currency, date);
|
||||
|
||||
return balance;
|
||||
}
|
||||
|
@ -26,6 +26,7 @@
|
||||
|
||||
#include <glib.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include "gnc-date.h"
|
||||
#include "gnc-pricedb-p.h"
|
||||
#include <qofinstance-p.h>
|
||||
@ -2501,7 +2502,7 @@ gnc_pricedb_lookup_latest_before (GNCPriceDB *db,
|
||||
static gnc_numeric
|
||||
direct_balance_conversion (GNCPriceDB *db, gnc_numeric bal,
|
||||
const gnc_commodity *from, const gnc_commodity *to,
|
||||
Timespec *t)
|
||||
time64 t)
|
||||
{
|
||||
GNCPrice *price;
|
||||
gnc_numeric retval = gnc_numeric_zero();
|
||||
@ -2509,8 +2510,8 @@ direct_balance_conversion (GNCPriceDB *db, gnc_numeric bal,
|
||||
return retval;
|
||||
if (gnc_numeric_zero_p(bal))
|
||||
return retval;
|
||||
if (t != NULL)
|
||||
price = gnc_pricedb_lookup_nearest_in_time(db, from, to, *t);
|
||||
if (t != INT64_MAX)
|
||||
price = gnc_pricedb_lookup_nearest_in_time64(db, from, to, t);
|
||||
else
|
||||
price = gnc_pricedb_lookup_latest(db, from, to);
|
||||
if (price == NULL)
|
||||
@ -2606,7 +2607,7 @@ convert_balance(gnc_numeric bal, const gnc_commodity *from,
|
||||
static gnc_numeric
|
||||
indirect_balance_conversion (GNCPriceDB *db, gnc_numeric bal,
|
||||
const gnc_commodity *from, const gnc_commodity *to,
|
||||
Timespec *t )
|
||||
time64 t )
|
||||
{
|
||||
GList *from_prices = NULL, *to_prices = NULL;
|
||||
PriceTuple tuple;
|
||||
@ -2615,7 +2616,7 @@ indirect_balance_conversion (GNCPriceDB *db, gnc_numeric bal,
|
||||
return zero;
|
||||
if (gnc_numeric_zero_p(bal))
|
||||
return zero;
|
||||
if (t == NULL)
|
||||
if (t == INT64_MAX)
|
||||
{
|
||||
from_prices = gnc_pricedb_lookup_latest_any_currency(db, from);
|
||||
/* "to" is often the book currency which may have lots of prices,
|
||||
@ -2625,11 +2626,11 @@ indirect_balance_conversion (GNCPriceDB *db, gnc_numeric bal,
|
||||
}
|
||||
else
|
||||
{
|
||||
from_prices = gnc_pricedb_lookup_nearest_in_time_any_currency(db,
|
||||
from, *t);
|
||||
from_prices = gnc_pricedb_lookup_nearest_in_time_any_currency_t64(db,
|
||||
from, t);
|
||||
if (from_prices)
|
||||
to_prices = gnc_pricedb_lookup_nearest_in_time_any_currency(db,
|
||||
to, *t);
|
||||
to_prices = gnc_pricedb_lookup_nearest_in_time_any_currency_t64(db,
|
||||
to, t);
|
||||
}
|
||||
if (from_prices == NULL || to_prices == NULL)
|
||||
return zero;
|
||||
@ -2659,7 +2660,7 @@ gnc_pricedb_convert_balance_latest_price(GNCPriceDB *pdb,
|
||||
|
||||
/* Look for a direct price. */
|
||||
new_value = direct_balance_conversion(pdb, balance, balance_currency,
|
||||
new_currency, NULL);
|
||||
new_currency, INT64_MAX);
|
||||
if (!gnc_numeric_zero_p(new_value))
|
||||
return new_value;
|
||||
|
||||
@ -2668,7 +2669,7 @@ gnc_pricedb_convert_balance_latest_price(GNCPriceDB *pdb,
|
||||
* and convert in two stages
|
||||
*/
|
||||
return indirect_balance_conversion(pdb, balance, balance_currency,
|
||||
new_currency, NULL);
|
||||
new_currency, INT64_MAX);
|
||||
}
|
||||
|
||||
gnc_numeric
|
||||
@ -2676,7 +2677,7 @@ gnc_pricedb_convert_balance_nearest_price(GNCPriceDB *pdb,
|
||||
gnc_numeric balance,
|
||||
const gnc_commodity *balance_currency,
|
||||
const gnc_commodity *new_currency,
|
||||
Timespec t)
|
||||
time64 t)
|
||||
{
|
||||
gnc_numeric new_value;
|
||||
|
||||
@ -2686,7 +2687,7 @@ gnc_pricedb_convert_balance_nearest_price(GNCPriceDB *pdb,
|
||||
|
||||
/* Look for a direct price. */
|
||||
new_value = direct_balance_conversion(pdb, balance, balance_currency,
|
||||
new_currency, &t);
|
||||
new_currency, t);
|
||||
if (!gnc_numeric_zero_p(new_value))
|
||||
return new_value;
|
||||
|
||||
@ -2695,7 +2696,7 @@ gnc_pricedb_convert_balance_nearest_price(GNCPriceDB *pdb,
|
||||
* and convert in two stages
|
||||
*/
|
||||
return indirect_balance_conversion(pdb, balance, balance_currency,
|
||||
new_currency, &t);
|
||||
new_currency, t);
|
||||
}
|
||||
|
||||
|
||||
|
@ -604,7 +604,7 @@ gnc_pricedb_convert_balance_nearest_price(GNCPriceDB *pdb,
|
||||
gnc_numeric balance,
|
||||
const gnc_commodity *balance_currency,
|
||||
const gnc_commodity *new_currency,
|
||||
Timespec t);
|
||||
time64 t);
|
||||
|
||||
typedef gboolean (*GncPriceForeachFunc)(GNCPrice *p, gpointer user_data);
|
||||
|
||||
|
@ -1206,7 +1206,7 @@ gnc_pricedb_convert_balance_nearest_price(GNCPriceDB *pdb,// C: 1 Local: 0:0:0
|
||||
static void
|
||||
test_gnc_pricedb_convert_balance_nearest_price (PriceDBFixture *fixture, gconstpointer pData)
|
||||
{
|
||||
Timespec t = gnc_dmy2timespec(15, 8, 2011);
|
||||
time64 t = gnc_dmy2time64(15, 8, 2011);
|
||||
gnc_numeric from = gnc_numeric_create(10000, 100);
|
||||
gnc_numeric result =
|
||||
gnc_pricedb_convert_balance_nearest_price(fixture->pricedb, from,
|
||||
|
Loading…
Reference in New Issue
Block a user