Timespec->time64 in business code.

This commit is contained in:
John Ralls 2018-08-02 13:55:24 -07:00
parent c8b372e390
commit 92a8cf330a
9 changed files with 48 additions and 47 deletions

View File

@ -973,9 +973,9 @@ gnc_payment_ok_cb (G_GNUC_UNUSED GtkWidget *widget, gpointer data)
else else
auto_pay = gnc_prefs_get_bool (GNC_PREFS_GROUP_BILL, GNC_PREF_AUTO_PAY); auto_pay = gnc_prefs_get_bool (GNC_PREFS_GROUP_BILL, GNC_PREF_AUTO_PAY);
gncOwnerApplyPayment (&pw->owner, &(pw->tx_info->txn), selected_lots, gncOwnerApplyPaymentSecs (&pw->owner, &(pw->tx_info->txn), selected_lots,
pw->post_acct, pw->xfer_acct, pw->amount_tot, pw->post_acct, pw->xfer_acct, pw->amount_tot,
exch, t, memo, num, auto_pay); exch, t, memo, num, auto_pay);
} }
gnc_resume_gui_refresh (); gnc_resume_gui_refresh ();

View File

@ -764,7 +764,7 @@ compute_monthyear (const GncBillTerm *term, time64 post_date,
gnc_localtime_r (&post_date, &tm); gnc_localtime_r (&post_date, &tm);
iday = tm.tm_mday; iday = tm.tm_mday;
imonth = tm.tm_mon + 1; imonth = tm.tm_mon + 1;
iyear = tm.tm_year + 1; iyear = tm.tm_year + 1900;
if (cutoff <= 0) if (cutoff <= 0)
cutoff += gnc_date_get_last_mday (imonth - 1, iyear); cutoff += gnc_date_get_last_mday (imonth - 1, iyear);
@ -801,23 +801,23 @@ compute_monthyear (const GncBillTerm *term, time64 post_date,
* detailed explanation of proximo. * detailed explanation of proximo.
*/ */
static Timespec static time64
compute_time (const GncBillTerm *term, Timespec post_date, int days) compute_time (const GncBillTerm *term, time64 post_date, int days)
{ {
Timespec res = post_date; time64 res = post_date;
int day, month, year; int day, month, year;
switch (term->type) switch (term->type)
{ {
case GNC_TERM_TYPE_DAYS: case GNC_TERM_TYPE_DAYS:
res.tv_sec += (SECS_PER_DAY * days); res += (SECS_PER_DAY * days);
break; break;
case GNC_TERM_TYPE_PROXIMO: case GNC_TERM_TYPE_PROXIMO:
compute_monthyear (term, post_date.tv_sec, &month, &year); compute_monthyear (term, post_date, &month, &year);
day = gnc_date_get_last_mday (month - 1, year); day = gnc_date_get_last_mday (month - 1, year);
if (days < day) if (days < day)
day = days; day = days;
res = gnc_dmy2timespec (day, month, year); res = gnc_dmy2time64 (day, month, year);
break; break;
} }
return res; return res;
@ -826,9 +826,8 @@ compute_time (const GncBillTerm *term, Timespec post_date, int days)
time64 time64
gncBillTermComputeDueDate (const GncBillTerm *term, time64 post_date) gncBillTermComputeDueDate (const GncBillTerm *term, time64 post_date)
{ {
Timespec pass = {post_date, 0};
if (!term) return post_date; if (!term) return post_date;
return compute_time (term, pass, term->due_days).tv_sec; return compute_time (term, post_date, term->due_days);
} }
/* Package-Private functions */ /* Package-Private functions */

View File

@ -1324,20 +1324,20 @@ gncEntryRecomputeValues (GncEntry *entry)
/* See if either tax table changed since we last computed values */ /* See if either tax table changed since we last computed values */
if (entry->i_tax_table) if (entry->i_tax_table)
{ {
Timespec modtime = gncTaxTableLastModified (entry->i_tax_table); time64 modtime = gncTaxTableLastModifiedSecs (entry->i_tax_table);
if (entry->i_taxtable_modtime != modtime.tv_sec) if (entry->i_taxtable_modtime != modtime)
{ {
entry->values_dirty = TRUE; entry->values_dirty = TRUE;
entry->i_taxtable_modtime = modtime.tv_sec; entry->i_taxtable_modtime = modtime;
} }
} }
if (entry->b_tax_table) if (entry->b_tax_table)
{ {
Timespec modtime = gncTaxTableLastModified (entry->b_tax_table); time64 modtime = gncTaxTableLastModifiedSecs (entry->b_tax_table);
if (entry->b_taxtable_modtime == modtime.tv_sec) if (entry->b_taxtable_modtime == modtime)
{ {
entry->values_dirty = TRUE; entry->values_dirty = TRUE;
entry->b_taxtable_modtime = modtime.tv_sec; entry->b_taxtable_modtime = modtime;
} }
} }

View File

@ -1943,9 +1943,10 @@ gncInvoiceApplyPayment (const GncInvoice *invoice, Transaction *txn,
g_return_if_fail (owner->owner.undefined); g_return_if_fail (owner->owner.undefined);
/* Create a lot for this payment */ /* Create a lot for this payment */
payment_lot = gncOwnerCreatePaymentLot (owner, &txn, invoice->posted_acc, payment_lot = gncOwnerCreatePaymentLotSecs (owner, &txn,
xfer_acc, amount, exch, invoice->posted_acc,
date, memo, num); xfer_acc, amount, exch,
date, memo, num);
/* Select the invoice as only payment candidate */ /* Select the invoice as only payment candidate */
selected_lots = g_list_prepend (selected_lots, invoice->posted_lot); selected_lots = g_list_prepend (selected_lots, invoice->posted_lot);

View File

@ -246,7 +246,7 @@ gncInvoiceAutoApplyPayments (GncInvoice *invoice);
* or payments for the owner will be considered * or payments for the owner will be considered
* to balance the payment. * to balance the payment.
* *
* This code is actually a convenience wrapper around gncOwnerCreatePaymentLot * This code is actually a convenience wrapper around gncOwnerCreatePaymentLotSecs
* and gncOwnerAutoApplyPaymentsWithLots. See their descriptions for more * and gncOwnerAutoApplyPaymentsWithLots. See their descriptions for more
* details on what happens exactly. * details on what happens exactly.
*/ */

View File

@ -723,10 +723,10 @@ gncOwnerLotsSortFunc (GNCLot *lotA, GNCLot *lotB)
} }
GNCLot * GNCLot *
gncOwnerCreatePaymentLot (const GncOwner *owner, Transaction **preset_txn, gncOwnerCreatePaymentLotSecs (const GncOwner *owner, Transaction **preset_txn,
Account *posted_acc, Account *xfer_acc, Account *posted_acc, Account *xfer_acc,
gnc_numeric amount, gnc_numeric exch, time64 date, gnc_numeric amount, gnc_numeric exch, time64 date,
const char *memo, const char *num) const char *memo, const char *num)
{ {
QofBook *book; QofBook *book;
Split *split; Split *split;
@ -1376,10 +1376,10 @@ void gncOwnerAutoApplyPaymentsWithLots (const GncOwner *owner, GList *lots)
* then all open lots for the owner are considered. * then all open lots for the owner are considered.
*/ */
void void
gncOwnerApplyPayment (const GncOwner *owner, Transaction **preset_txn, GList *lots, gncOwnerApplyPaymentSecs (const GncOwner *owner, Transaction **preset_txn,
Account *posted_acc, Account *xfer_acc, GList *lots, Account *posted_acc, Account *xfer_acc,
gnc_numeric amount, gnc_numeric exch, time64 date, gnc_numeric amount, gnc_numeric exch, time64 date,
const char *memo, const char *num, gboolean auto_pay) const char *memo, const char *num, gboolean auto_pay)
{ {
GNCLot *payment_lot = NULL; GNCLot *payment_lot = NULL;
GList *selected_lots = NULL; GList *selected_lots = NULL;
@ -1391,8 +1391,10 @@ gncOwnerApplyPayment (const GncOwner *owner, Transaction **preset_txn, GList *lo
/* If there's a real amount to transfer create a lot for this payment */ /* If there's a real amount to transfer create a lot for this payment */
if (!gnc_numeric_zero_p (amount)) if (!gnc_numeric_zero_p (amount))
payment_lot = gncOwnerCreatePaymentLot (owner, preset_txn, posted_acc, xfer_acc, payment_lot = gncOwnerCreatePaymentLotSecs (owner, preset_txn,
amount, exch, date, memo, num); posted_acc, xfer_acc,
amount, exch, date, memo,
num);
if (lots) if (lots)
selected_lots = lots; selected_lots = lots;

View File

@ -214,10 +214,10 @@ gboolean gncOwnerGetOwnerFromTypeGuid (QofBook *book, GncOwner *owner, QofIdType
* split in the transfer account). * split in the transfer account).
*/ */
GNCLot * GNCLot *
gncOwnerCreatePaymentLot (const GncOwner *owner, Transaction **preset_txn, gncOwnerCreatePaymentLotSecs (const GncOwner *owner, Transaction **preset_txn,
Account *posted_acc, Account *xfer_acc, Account *posted_acc, Account *xfer_acc,
gnc_numeric amount, gnc_numeric exch, time64 date, gnc_numeric amount, gnc_numeric exch, time64 date,
const char *memo, const char *num); const char *memo, const char *num);
/** /**
* Given a list of lots, try to balance as many of them as possible * Given a list of lots, try to balance as many of them as possible
@ -267,10 +267,10 @@ void gncOwnerAutoApplyPaymentsWithLots (const GncOwner *owner, GList *lots);
* details on what happens exactly. * details on what happens exactly.
*/ */
void void
gncOwnerApplyPayment (const GncOwner *owner, Transaction **preset_txn, GList *lots, gncOwnerApplyPaymentSecs (const GncOwner *owner, Transaction **preset_txn,
Account *posted_acc, Account *xfer_acc, GList *lots, Account *posted_acc, Account *xfer_acc,
gnc_numeric amount, gnc_numeric exch, time64 date, gnc_numeric amount, gnc_numeric exch, time64 date,
const char *memo, const char *num, gboolean auto_pay); const char *memo, const char *num, gboolean auto_pay);
/** Helper function to find a split in lot that best offsets target_value /** Helper function to find a split in lot that best offsets target_value
* Obviously it should be of opposite sign. * Obviously it should be of opposite sign.

View File

@ -39,7 +39,7 @@ struct _gncTaxTable
QofInstance inst; QofInstance inst;
char * name; char * name;
GncTaxTableEntryList* entries; GncTaxTableEntryList* entries;
Timespec modtime; /* internal date of last modtime */ time64 modtime; /* internal date of last modtime */
/* See src/doc/business.txt for an explanation of the following */ /* See src/doc/business.txt for an explanation of the following */
/* Code that handles this is *identical* to that in gncBillTerm */ /* Code that handles this is *identical* to that in gncBillTerm */
@ -165,7 +165,7 @@ maybe_resort_list (GncTaxTable *table)
static inline void static inline void
mod_table (GncTaxTable *table) mod_table (GncTaxTable *table)
{ {
timespecFromTime64 (&table->modtime, gnc_time (NULL)); table->modtime = gnc_time (NULL);
} }
static inline void addObj (GncTaxTable *table) static inline void addObj (GncTaxTable *table)
@ -761,10 +761,9 @@ gint64 gncTaxTableGetRefcount (const GncTaxTable *table)
return table->refcount; return table->refcount;
} }
Timespec gncTaxTableLastModified (const GncTaxTable *table) time64 gncTaxTableLastModifiedSecs (const GncTaxTable *table)
{ {
Timespec ts = { 0 , 0 }; if (!table) return 0;
if (!table) return ts;
return table->modtime; return table->modtime;
} }

View File

@ -41,7 +41,7 @@ is *identical* to that in ::GncBillTerm
@param QofInstance inst; @param QofInstance inst;
@param char * name; @param char * name;
@param GncTaxTableEntryList* entries; @param GncTaxTableEntryList* entries;
@param Timespec modtime; @param time64 modtime;
@param gint64 refcount; @param gint64 refcount;
@param GncTaxTable * parent; if non-null, we are an immutable child @param GncTaxTable * parent; if non-null, we are an immutable child
@param GncTaxTable * child; if non-null, we have not changed @param GncTaxTable * child; if non-null, we have not changed
@ -162,7 +162,7 @@ GncTaxTable *gncTaxTableReturnChild (GncTaxTable *table, gboolean make_new);
typedef GList GncTaxTableEntryList; typedef GList GncTaxTableEntryList;
GncTaxTableEntryList* gncTaxTableGetEntries (const GncTaxTable *table); GncTaxTableEntryList* gncTaxTableGetEntries (const GncTaxTable *table);
gint64 gncTaxTableGetRefcount (const GncTaxTable *table); gint64 gncTaxTableGetRefcount (const GncTaxTable *table);
Timespec gncTaxTableLastModified (const GncTaxTable *table); time64 gncTaxTableLastModifiedSecs (const GncTaxTable *table);
Account * gncTaxTableEntryGetAccount (const GncTaxTableEntry *entry); Account * gncTaxTableEntryGetAccount (const GncTaxTableEntry *entry);
GncAmountType gncTaxTableEntryGetType (const GncTaxTableEntry *entry); GncAmountType gncTaxTableEntryGetType (const GncTaxTableEntry *entry);