From d678e866e75e7c6749df15b18976d0581e73a1a9 Mon Sep 17 00:00:00 2001 From: David Hampton Date: Tue, 24 Dec 2002 01:40:46 +0000 Subject: [PATCH] Add a new pricedb lookup function. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@7712 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/engine/gnc-pricedb.c | 49 ++++++++++++++++++++++++++++++++++++++++ src/engine/gnc-pricedb.h | 8 +++++++ 2 files changed, 57 insertions(+) diff --git a/src/engine/gnc-pricedb.c b/src/engine/gnc-pricedb.c index 36d4e10b5b..976aa7c5b9 100644 --- a/src/engine/gnc-pricedb.c +++ b/src/engine/gnc-pricedb.c @@ -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, diff --git a/src/engine/gnc-pricedb.h b/src/engine/gnc-pricedb.h index 851051343f..58f8a3cd44 100644 --- a/src/engine/gnc-pricedb.h +++ b/src/engine/gnc-pricedb.h @@ -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 *