ADD-TIME64-API: libgnucash/engine/gnc-pricedb.[ch]

This commit is contained in:
Christopher Lam 2017-12-30 21:59:18 +11:00
parent 46c9fcc8f8
commit dda0695285
2 changed files with 38 additions and 0 deletions

View File

@ -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,

View File

@ -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.