From dda06952851c5908d15fbaae7332170571561080 Mon Sep 17 00:00:00 2001 From: Christopher Lam Date: Sat, 30 Dec 2017 21:59:18 +1100 Subject: [PATCH] ADD-TIME64-API: libgnucash/engine/gnc-pricedb.[ch] --- libgnucash/engine/gnc-pricedb.c | 33 +++++++++++++++++++++++++++++++++ libgnucash/engine/gnc-pricedb.h | 5 +++++ 2 files changed, 38 insertions(+) diff --git a/libgnucash/engine/gnc-pricedb.c b/libgnucash/engine/gnc-pricedb.c index d550f24907..0d4fb502ab 100644 --- a/libgnucash/engine/gnc-pricedb.c +++ b/libgnucash/engine/gnc-pricedb.c @@ -517,6 +517,27 @@ gnc_price_set_time(GNCPrice *p, Timespec t) } } +void +gnc_price_set_time64(GNCPrice *p, time64 t64) +{ + if (!p) return; + if (p->tmspec.tv_sec != t64) // do we need to check nsec as well? + { + /* Changing the datestamp requires the hash table + * position to be modified. The easiest way of doing + * this is to remove and reinsert. */ + gnc_price_ref (p); + remove_price (p->db, p, FALSE); + gnc_price_begin_edit (p); + p->tmspec.tv_sec = t64; + p->tmspec.tv_nsec = 0; + gnc_price_set_dirty(p); + gnc_price_commit_edit (p); + add_price (p->db, p); + gnc_price_unref (p); + } +} + void gnc_price_set_source(GNCPrice *p, PriceSource s) { @@ -2258,6 +2279,18 @@ gnc_pricedb_lookup_day(GNCPriceDB *db, return lookup_nearest_in_time(db, c, currency, t, TRUE); } +GNCPrice * +gnc_pricedb_lookup_day_t64(GNCPriceDB *db, + const gnc_commodity *c, + const gnc_commodity *currency, + time64 t64) +{ + Timespec t; + t.tv_sec = t64; + t.tv_nsec = 0; + return lookup_nearest_in_time(db, c, currency, t, TRUE); +} + GNCPrice * gnc_pricedb_lookup_at_time(GNCPriceDB *db, const gnc_commodity *c, diff --git a/libgnucash/engine/gnc-pricedb.h b/libgnucash/engine/gnc-pricedb.h index f2117f81e7..f4fe839e90 100644 --- a/libgnucash/engine/gnc-pricedb.h +++ b/libgnucash/engine/gnc-pricedb.h @@ -239,6 +239,7 @@ void gnc_price_commit_edit (GNCPrice *p); void gnc_price_set_commodity(GNCPrice *p, gnc_commodity *c); void gnc_price_set_currency(GNCPrice *p, gnc_commodity *c); void gnc_price_set_time(GNCPrice *p, Timespec t); +void gnc_price_set_time64(GNCPrice *p, time64 t64); void gnc_price_set_source(GNCPrice *p, PriceSource source); void gnc_price_set_source_string(GNCPrice *p, const char* s); void gnc_price_set_typestr(GNCPrice *p, const char* type); @@ -495,6 +496,10 @@ GNCPrice * gnc_pricedb_lookup_day(GNCPriceDB *db, const gnc_commodity *currency, Timespec t); +GNCPrice * gnc_pricedb_lookup_day_t64(GNCPriceDB *db, + const gnc_commodity *commodity, + const gnc_commodity *currency, + time64 t64); /** @brief Return the price between the two commoditiesz nearest to the given * time.