Add a new pricedb lookup function.

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@7712 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
David Hampton 2002-12-24 01:40:46 +00:00
parent 6f8fca355e
commit d678e866e7
2 changed files with 57 additions and 0 deletions

View File

@ -1026,6 +1026,55 @@ gnc_pricedb_get_prices(GNCPriceDB *db,
return result;
}
GList *
gnc_pricedb_lookup_day(GNCPriceDB *db,
gnc_commodity *c,
gnc_commodity *currency,
Timespec t)
{
GList *price_list;
GList *result = NULL;
GList *item = NULL;
GHashTable *currency_hash;
ENTER ("db=%p commodity=%p currency=%p", db, c, currency);
if(!db || !c || !currency) return NULL;
/* Convert to noon local time. */
t = timespecCanonicalDayTime(t);
if (db->book && db->book->backend && db->book->backend->price_lookup)
{
GNCPriceLookup pl;
pl.type = LOOKUP_AT_TIME;
pl.prdb = db;
pl.commodity = c;
pl.currency = currency;
pl.date = t;
(db->book->backend->price_lookup) (db->book->backend, &pl);
}
currency_hash = g_hash_table_lookup(db->commodity_hash, c);
if(!currency_hash) return NULL;
price_list = g_hash_table_lookup(currency_hash, currency);
if(!price_list) return NULL;
item = price_list;
while(item) {
GNCPrice *p = item->data;
Timespec price_time = timespecCanonicalDayTime(gnc_price_get_time(p));
if(timespec_equal(&price_time, &t)) {
result = g_list_prepend(result, p);
gnc_price_ref(p);
}
item = item->next;
}
LEAVE (" ");
return result;
}
GList *
gnc_pricedb_lookup_at_time(GNCPriceDB *db,
gnc_commodity *c,

View File

@ -259,6 +259,14 @@ GList * gnc_pricedb_lookup_at_time(GNCPriceDB *db,
gnc_commodity *currency,
Timespec t);
/* gnc_pricedb_lookup_day - return all prices that match the given
commodity, currency, and timespec. Prices will be returned as a
GNCPrice list (see above). */
GList * gnc_pricedb_lookup_day(GNCPriceDB *db,
gnc_commodity *commodity,
gnc_commodity *currency,
Timespec t);
/* gnc_pricedb_lookup_nearest_in_time - return the price for the given
commodity in the given currency nearest to the given time t. */
GNCPrice *