mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Remove Timespec from the main engine classes (Transaction, Split, & Account.
This commit is contained in:
parent
fee589b28c
commit
358cd979d9
@ -63,15 +63,6 @@ add_time64 (xmlNodePtr node, const gchar * tag, time64 time, gboolean always)
|
||||
xmlAddChild (node, time64_to_dom_tree (tag, time));
|
||||
}
|
||||
|
||||
static void
|
||||
add_timespec (xmlNodePtr node, const gchar* tag, Timespec tms, gboolean always)
|
||||
{
|
||||
if (always || tms.tv_sec)
|
||||
{
|
||||
xmlAddChild (node, time64_to_dom_tree (tag, tms.tv_sec));
|
||||
}
|
||||
}
|
||||
|
||||
static xmlNodePtr
|
||||
split_to_dom_tree (const gchar* tag, Split* spl)
|
||||
{
|
||||
@ -113,8 +104,8 @@ split_to_dom_tree (const gchar* tag, Split* spl)
|
||||
BAD_CAST tmp);
|
||||
}
|
||||
|
||||
add_timespec (ret, "split:reconcile-date",
|
||||
xaccSplitRetDateReconciledTS (spl), FALSE);
|
||||
add_time64 (ret, "split:reconcile-date",
|
||||
xaccSplitGetDateReconciled (spl), FALSE);
|
||||
|
||||
add_gnc_num (ret, "split:value", xaccSplitGetValue (spl));
|
||||
|
||||
@ -445,12 +436,11 @@ set_tran_time64 (xmlNodePtr node, Transaction * trn,
|
||||
|
||||
static inline gboolean
|
||||
set_tran_date (xmlNodePtr node, Transaction* trn,
|
||||
void (*func) (Transaction* trn, const Timespec* tm))
|
||||
void (*func) (Transaction* trn, const time64 tm))
|
||||
{
|
||||
time64 time = dom_tree_to_time64 (node);
|
||||
if (!dom_tree_valid_time64 (time, node->name)) time = 0;
|
||||
Timespec ts {time, 0};
|
||||
func (trn, &ts);
|
||||
func (trn, time);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
@ -3311,19 +3311,6 @@ xaccAccountGetBalanceAsOfDate (Account *acc, time64 date)
|
||||
priv = GET_PRIVATE(acc);
|
||||
balance = priv->balance;
|
||||
|
||||
/* Since transaction post times are stored as a Timespec,
|
||||
* convert date into a Timespec as well rather than converting
|
||||
* each transaction's Timespec into a time64.
|
||||
*
|
||||
* FIXME: CAS: I think this comment is a bogus justification for
|
||||
* using xaccTransGetDatePostedTS. There's no benefit to using
|
||||
* Timespec when the input argument is time64, and it's hard to
|
||||
* imagine that casting long long to long and comparing two longs is
|
||||
* worse than comparing two long longs every time. IMO,
|
||||
* xaccAccountGetPresentBalance gets this right, and its algorithm
|
||||
* should be used here.
|
||||
*/
|
||||
|
||||
lp = priv->splits;
|
||||
while ( lp && !found )
|
||||
{
|
||||
@ -3432,7 +3419,6 @@ xaccAccountConvertBalanceToCurrencyAsOfDate(const Account *acc, /* for book */
|
||||
{
|
||||
QofBook *book;
|
||||
GNCPriceDB *pdb;
|
||||
Timespec ts;
|
||||
|
||||
if (gnc_numeric_zero_p (balance) ||
|
||||
gnc_commodity_equiv (balance_currency, new_currency))
|
||||
|
@ -391,23 +391,23 @@ time64
|
||||
recurrenceGetPeriodTime(const Recurrence *r, guint period_num, gboolean end)
|
||||
{
|
||||
GDate date;
|
||||
Timespec ts;
|
||||
time64 time;
|
||||
recurrenceNthInstance(r, period_num + (end ? 1 : 0), &date);
|
||||
if (end)
|
||||
{
|
||||
g_date_subtract_days(&date, 1);
|
||||
ts = gnc_dmy2timespec_end (g_date_get_day(&date),
|
||||
time = gnc_dmy2time64_end (g_date_get_day(&date),
|
||||
g_date_get_month(&date),
|
||||
g_date_get_year (&date));
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
ts = gnc_dmy2timespec (g_date_get_day(&date),
|
||||
time = gnc_dmy2time64 (g_date_get_day(&date),
|
||||
g_date_get_month(&date),
|
||||
g_date_get_year (&date));
|
||||
}
|
||||
return timespecToTime64(ts);
|
||||
return time;
|
||||
}
|
||||
|
||||
gnc_numeric
|
||||
|
@ -115,8 +115,7 @@ gnc_split_init(Split* split)
|
||||
split->amount = gnc_numeric_zero();
|
||||
split->value = gnc_numeric_zero();
|
||||
|
||||
split->date_reconciled.tv_sec = 0;
|
||||
split->date_reconciled.tv_nsec = 0;
|
||||
split->date_reconciled = 0;
|
||||
|
||||
split->balance = gnc_numeric_zero();
|
||||
split->cleared_balance = gnc_numeric_zero();
|
||||
@ -151,6 +150,7 @@ gnc_split_get_property(GObject *object,
|
||||
{
|
||||
Split *split;
|
||||
gchar *key;
|
||||
Time64 t;
|
||||
|
||||
g_return_if_fail(GNC_IS_SPLIT(object));
|
||||
|
||||
@ -170,7 +170,8 @@ gnc_split_get_property(GObject *object,
|
||||
g_value_set_boxed(value, &split->amount);
|
||||
break;
|
||||
case PROP_RECONCILE_DATE:
|
||||
g_value_set_boxed(value, &split->date_reconciled.tv_sec);
|
||||
t.t = split->date_reconciled;
|
||||
g_value_set_boxed(value, &t);
|
||||
break;
|
||||
case PROP_TX:
|
||||
g_value_take_object(value, split->parent);
|
||||
@ -507,8 +508,7 @@ xaccSplitReinit(Split * split)
|
||||
split->amount = gnc_numeric_zero();
|
||||
split->value = gnc_numeric_zero();
|
||||
|
||||
split->date_reconciled.tv_sec = 0;
|
||||
split->date_reconciled.tv_nsec = 0;
|
||||
split->date_reconciled = 0;
|
||||
|
||||
split->balance = gnc_numeric_zero();
|
||||
split->cleared_balance = gnc_numeric_zero();
|
||||
@ -654,6 +654,9 @@ xaccSplitCopyOnto(const Split *from_split, Split *to_split)
|
||||
void
|
||||
xaccSplitDump (const Split *split, const char *tag)
|
||||
{
|
||||
char datebuff[MAX_DATE_LENGTH + 1];
|
||||
memset (datebuff, 0, sizeof(datebuff));
|
||||
qof_print_date_buff (datebuff, sizeof(datebuff), split->date_reconciled);
|
||||
printf(" %s Split %p", tag, split);
|
||||
printf(" Book: %p\n", qof_instance_get_book(split));
|
||||
printf(" Account: %p (%s)\n", split->acc,
|
||||
@ -668,8 +671,8 @@ xaccSplitDump (const Split *split, const char *tag)
|
||||
printf(" Memo: %s\n", split->memo ? split->memo : "(null)");
|
||||
printf(" Action: %s\n", split->action ? split->action : "(null)");
|
||||
printf(" KVP Data: %s\n", qof_instance_kvp_as_string (QOF_INSTANCE (split)));
|
||||
printf(" Recncld: %c (date %s)\n", split->reconciled,
|
||||
gnc_print_date(split->date_reconciled));
|
||||
printf(" Recncld: %c (date %s)\n", split->reconciled, datebuff);
|
||||
|
||||
printf(" Value: %s\n", gnc_numeric_to_string(split->value));
|
||||
printf(" Amount: %s\n", gnc_numeric_to_string(split->amount));
|
||||
printf(" Balance: %s\n", gnc_numeric_to_string(split->balance));
|
||||
@ -708,8 +711,7 @@ xaccFreeSplit (Split *split)
|
||||
split->acc = NULL;
|
||||
split->orig_acc = NULL;
|
||||
|
||||
split->date_reconciled.tv_sec = 0;
|
||||
split->date_reconciled.tv_nsec = 0;
|
||||
split->date_reconciled = 0;
|
||||
G_OBJECT_CLASS (QOF_INSTANCE_GET_CLASS (&split->inst))->dispose(G_OBJECT (split));
|
||||
// Is this right?
|
||||
if (split->gains_split) split->gains_split->gains_split = NULL;
|
||||
@ -818,7 +820,7 @@ xaccSplitEqual(const Split *sa, const Split *sb,
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (timespec_cmp(&(sa->date_reconciled), &(sb->date_reconciled)))
|
||||
if (sa->date_reconciled != sb->date_reconciled)
|
||||
{
|
||||
PINFO ("reconciled date differs");
|
||||
return FALSE;
|
||||
@ -1514,7 +1516,10 @@ xaccSplitOrder (const Split *sa, const Split *sb)
|
||||
if (comp > 0) return +1;
|
||||
|
||||
/* if dates differ, return */
|
||||
DATE_CMP(sa, sb, date_reconciled);
|
||||
if (sa->date_reconciled < sb->date_reconciled)
|
||||
return -1;
|
||||
else if (sa->date_reconciled > sb->date_reconciled)
|
||||
return 1;
|
||||
|
||||
/* else, sort on guid - keeps sort stable. */
|
||||
retval = qof_instance_guid_compare(sa, sb);
|
||||
@ -1772,44 +1777,18 @@ xaccSplitSetDateReconciledSecs (Split *split, time64 secs)
|
||||
if (!split) return;
|
||||
xaccTransBeginEdit (split->parent);
|
||||
|
||||
split->date_reconciled.tv_sec = secs;
|
||||
split->date_reconciled.tv_nsec = 0;
|
||||
split->date_reconciled = secs;
|
||||
qof_instance_set_dirty(QOF_INSTANCE(split));
|
||||
xaccTransCommitEdit(split->parent);
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
xaccSplitSetDateReconciledTS (Split *split, Timespec *ts)
|
||||
{
|
||||
if (!split || !ts) return;
|
||||
xaccTransBeginEdit (split->parent);
|
||||
|
||||
split->date_reconciled = *ts;
|
||||
qof_instance_set_dirty(QOF_INSTANCE(split));
|
||||
xaccTransCommitEdit(split->parent);
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
xaccSplitGetDateReconciledTS (const Split * split, Timespec *ts)
|
||||
{
|
||||
if (!split || !ts) return;
|
||||
*ts = (split->date_reconciled);
|
||||
}
|
||||
|
||||
Timespec
|
||||
xaccSplitRetDateReconciledTS (const Split * split)
|
||||
{
|
||||
Timespec ts = {0, 0};
|
||||
return split ? split->date_reconciled : ts;
|
||||
}
|
||||
|
||||
/*################## Added for Reg2 #################*/
|
||||
time64
|
||||
xaccSplitGetDateReconciled (const Split * split)
|
||||
{
|
||||
return split ? split->date_reconciled.tv_sec : 0;
|
||||
return split ? split->date_reconciled : 0;
|
||||
}
|
||||
/*################## Added for Reg2 #################*/
|
||||
|
||||
@ -2004,7 +1983,7 @@ xaccSplitAddPeerSplit (Split *split, const Split *other_split,
|
||||
guid = qof_instance_get_guid (QOF_INSTANCE (other_split));
|
||||
xaccTransBeginEdit (split->parent);
|
||||
qof_instance_kvp_add_guid (QOF_INSTANCE (split), "lot-split",
|
||||
timespec_now(), "peer_guid", guid_copy(guid));
|
||||
gnc_time(NULL), "peer_guid", guid_copy(guid));
|
||||
mark_split (split);
|
||||
qof_instance_set_dirty (QOF_INSTANCE (split));
|
||||
xaccTransCommitEdit (split->parent);
|
||||
|
@ -191,15 +191,6 @@ char xaccSplitGetReconcile (const Split *split);
|
||||
/** Set the date on which this split was reconciled by specifying the
|
||||
* time as time64. */
|
||||
void xaccSplitSetDateReconciledSecs (Split *split, time64 time);
|
||||
/** Set the date on which this split was reconciled by specifying the
|
||||
* time as Timespec. Caller still owns *ts! */
|
||||
void xaccSplitSetDateReconciledTS (Split *split, Timespec *ts);
|
||||
/** Get the date on which this split was reconciled by having it
|
||||
* written into the Timespec that 'ts' is pointing to. */
|
||||
void xaccSplitGetDateReconciledTS (const Split *split,
|
||||
Timespec *ts);
|
||||
/** Returns the date (as Timespec) on which this split was reconciled. */
|
||||
Timespec xaccSplitRetDateReconciledTS (const Split *split);
|
||||
|
||||
/*################## Added for Reg2 #################*/
|
||||
/** Retrieve the date when the Split was reconciled. */
|
||||
|
@ -93,8 +93,8 @@ struct split_s
|
||||
*/
|
||||
char * action; /* Buy, Sell, Div, etc. */
|
||||
|
||||
Timespec date_reconciled; /* date split was reconciled */
|
||||
char reconciled; /* The reconciled field */
|
||||
time64 date_reconciled; /* date split was reconciled */
|
||||
char reconciled; /* The reconciled field */
|
||||
|
||||
/* gains is a flag used to track the relationship between
|
||||
* capital-gains splits. Depending on its value, this flag indicates
|
||||
@ -202,28 +202,6 @@ void DxaccSplitSetShareAmount (Split *split, double amount);
|
||||
\********************************************************************/
|
||||
|
||||
|
||||
#define DATE_CMP(aaa,bbb,field) { \
|
||||
/* if dates differ, return */ \
|
||||
if ( (aaa->field.tv_sec) < \
|
||||
(bbb->field.tv_sec)) { \
|
||||
return -1; \
|
||||
} else \
|
||||
if ( (aaa->field.tv_sec) > \
|
||||
(bbb->field.tv_sec)) { \
|
||||
return +1; \
|
||||
} \
|
||||
\
|
||||
/* else, seconds match. check nanoseconds */ \
|
||||
if ( (aaa->field.tv_nsec) < \
|
||||
(bbb->field.tv_nsec)) { \
|
||||
return -1; \
|
||||
} else \
|
||||
if ( (aaa->field.tv_nsec) > \
|
||||
(bbb->field.tv_nsec)) { \
|
||||
return +1; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define CHECK_GAINS_STATUS(s) \
|
||||
if (GAINS_STATUS_UNKNOWN == s->gains) xaccSplitDetermineGainStatus(s);
|
||||
|
||||
|
@ -244,7 +244,7 @@ xaccTransWriteLog (Transaction *trans, char flag)
|
||||
|
||||
for (node = trans->splits; node; node = node->next)
|
||||
{
|
||||
Timespec ts;
|
||||
time64 time;
|
||||
Split *split = node->data;
|
||||
const char * accname = "";
|
||||
char acc_guid_str[GUID_ENCODING_LENGTH + 1];
|
||||
@ -261,8 +261,7 @@ xaccTransWriteLog (Transaction *trans, char flag)
|
||||
acc_guid_str[0] = '\0';
|
||||
}
|
||||
|
||||
timespecFromTime64(&ts, split->date_reconciled.tv_sec);
|
||||
gnc_timespec_to_iso8601_buff (ts, drecn);
|
||||
gnc_time64_to_iso8601_buff (split->date_reconciled, drecn);
|
||||
|
||||
guid_to_string_buff (xaccSplitGetGUID(split), split_guid_str);
|
||||
amt = xaccSplitGetAmount (split);
|
||||
|
@ -310,6 +310,7 @@ gnc_transaction_get_property(GObject* object,
|
||||
{
|
||||
Transaction* tx;
|
||||
gchar *key;
|
||||
Time64 time;
|
||||
|
||||
g_return_if_fail(GNC_IS_TRANSACTION(object));
|
||||
|
||||
@ -326,10 +327,12 @@ gnc_transaction_get_property(GObject* object,
|
||||
g_value_take_object(value, tx->common_currency);
|
||||
break;
|
||||
case PROP_POST_DATE:
|
||||
g_value_set_boxed(value, &tx->date_posted);
|
||||
time.t = tx->date_posted;
|
||||
g_value_set_boxed(value, &time);
|
||||
break;
|
||||
case PROP_ENTER_DATE:
|
||||
g_value_set_boxed(value, &tx->date_entered);
|
||||
time.t = tx->date_entered;
|
||||
g_value_set_boxed(value, &time);
|
||||
break;
|
||||
case PROP_INVOICE:
|
||||
qof_instance_get_kvp (QOF_INSTANCE (tx), value, 2, GNC_INVOICE_ID, GNC_INVOICE_GUID);
|
||||
@ -530,8 +533,12 @@ xaccTransDump (const Transaction *trans, const char *tag)
|
||||
GList *node;
|
||||
|
||||
printf("%s Trans %p", tag, trans);
|
||||
printf(" Entered: %s\n", gnc_print_date(trans->date_entered));
|
||||
printf(" Posted: %s\n", gnc_print_date(trans->date_posted));
|
||||
memset(datebuff, 0, sizeof(datebuff));
|
||||
qof_print_date_buff(datebuff, sizeof(datebuff), trans->date_entered);
|
||||
printf(" Entered: %s\n", datebuff);
|
||||
memset(datebuff, 0, sizeof(datebuff));
|
||||
qof_print_date_buff(datebuff, sizeof(datebuff), trans->date_posted);
|
||||
printf(" Posted: %s\n", datebuff);
|
||||
printf(" Num: %s\n", trans->num ? trans->num : "(null)");
|
||||
printf(" Description: %s\n",
|
||||
trans->description ? trans->description : "(null)");
|
||||
@ -1955,7 +1962,7 @@ xaccTransSetDatePostedSecs (Transaction *trans, time64 secs)
|
||||
{
|
||||
if (!trans) return;
|
||||
xaccTransSetDateInternal(trans, &trans->date_posted, secs);
|
||||
set_gains_date_dirty (trans);
|
||||
set_gains_date_dirty(trans);
|
||||
}
|
||||
|
||||
void
|
||||
@ -1974,7 +1981,7 @@ xaccTransSetDatePostedGDate (Transaction *trans, GDate date)
|
||||
|
||||
/* We additionally save this date into a kvp frame to ensure in
|
||||
* the future a date which was set as *date* (without time) can
|
||||
* clearly be distinguished from the Timespec. */
|
||||
* clearly be distinguished from the time64. */
|
||||
g_value_init (&v, G_TYPE_DATE);
|
||||
g_value_set_boxed (&v, &date);
|
||||
qof_instance_set_kvp (QOF_INSTANCE(trans), &v, 1, TRANS_DATE_POSTED);
|
||||
@ -1992,25 +1999,21 @@ xaccTransSetDateEnteredSecs (Transaction *trans, time64 secs)
|
||||
}
|
||||
|
||||
static void
|
||||
qofTransSetDatePosted (Transaction *trans, Timespec ts)
|
||||
qofTransSetDatePosted (Transaction *trans, time64 time)
|
||||
{
|
||||
if (!trans) return;
|
||||
if ((ts.tv_nsec == 0) && (ts.tv_sec == 0)) return;
|
||||
if (!qof_begin_edit(&trans->inst)) return;
|
||||
xaccTransSetDateInternal(trans, &trans->date_posted, ts.tv_sec);
|
||||
xaccTransSetDateInternal(trans, &trans->date_posted, time);
|
||||
set_gains_date_dirty(trans);
|
||||
qof_commit_edit(&trans->inst);
|
||||
}
|
||||
|
||||
static void
|
||||
qofTransSetDateEntered (Transaction *trans, Timespec ts)
|
||||
qofTransSetDateEntered (Transaction *trans, time64 time)
|
||||
{
|
||||
/*This is called from the query framework, so we'll leave the timespec
|
||||
* until the query framework is converted, too.*/
|
||||
if (!trans) return;
|
||||
if ((ts.tv_nsec == 0) && (ts.tv_sec == 0)) return;
|
||||
if (!qof_begin_edit(&trans->inst)) return;
|
||||
xaccTransSetDateInternal(trans, &trans->date_entered, ts.tv_sec);
|
||||
xaccTransSetDateInternal(trans, &trans->date_entered, time);
|
||||
qof_commit_edit(&trans->inst);
|
||||
}
|
||||
|
||||
@ -2383,7 +2386,7 @@ xaccTransGetDatePostedGDate (const Transaction *trans)
|
||||
/* Well, this txn doesn't have a GDate saved in a
|
||||
* slot. Avoid getting the date in the local TZ by
|
||||
* converting to UTC before generating the
|
||||
* date. (timespec_to_gdate doesn't do this so don't use
|
||||
* date. (time64_to_gdate doesn't do this so don't use
|
||||
* it.
|
||||
*/
|
||||
time64 time = xaccTransGetDate(trans);
|
||||
@ -2414,7 +2417,7 @@ xaccTransRetDateDue(const Transaction *trans)
|
||||
if (!trans) return 0;
|
||||
qof_instance_get_kvp (QOF_INSTANCE (trans), &v, 1, TRANS_DATE_DUE_KVP);
|
||||
if (G_VALUE_HOLDS_BOXED (&v))
|
||||
ret = ((Timespec*)g_value_get_boxed (&v))->tv_sec;
|
||||
ret = ((Time64*)g_value_get_boxed (&v))->t;
|
||||
if (!ret)
|
||||
return xaccTransRetDatePosted (trans);
|
||||
return ret;
|
||||
@ -2654,7 +2657,7 @@ xaccTransVoid(Transaction *trans, const char *reason)
|
||||
g_value_set_string (&v, reason);
|
||||
qof_instance_set_kvp (QOF_INSTANCE (trans), &v, 1, void_reason_str);
|
||||
|
||||
gnc_timespec_to_iso8601_buff (timespec_now (), iso8601_str);
|
||||
gnc_time64_to_iso8601_buff (gnc_time(NULL), iso8601_str);
|
||||
g_value_set_string (&v, iso8601_str);
|
||||
qof_instance_set_kvp (QOF_INSTANCE (trans), &v, 1, void_time_str);
|
||||
|
||||
@ -2939,39 +2942,6 @@ trans_is_balanced_p (const Transaction *trans)
|
||||
return trans ? xaccTransIsBalanced(trans) : FALSE;
|
||||
}
|
||||
|
||||
static Timespec
|
||||
xaccTransRetDateEnteredTS (Transaction * trans)
|
||||
{
|
||||
Timespec ret = {xaccTransRetDateEntered (trans), 0};
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void
|
||||
qofTransSetDateEnteredTS (Transaction * trans, Timespec t)
|
||||
{
|
||||
xaccTransSetDateEnteredSecs (trans, t.tv_sec);
|
||||
}
|
||||
|
||||
static Timespec
|
||||
xaccTransRetDatePostedTS (Transaction * trans)
|
||||
{
|
||||
Timespec ret = {xaccTransRetDatePosted (trans), 0};
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void
|
||||
qofTransSetDatePostedTS (Transaction * trans, Timespec t)
|
||||
{
|
||||
xaccTransSetDatePostedSecs (trans, t.tv_sec);
|
||||
}
|
||||
|
||||
static Timespec
|
||||
xaccTransRetDateDueTS (Transaction * trans)
|
||||
{
|
||||
Timespec ret = {xaccTransRetDateDue (trans), 0};
|
||||
return ret;
|
||||
}
|
||||
|
||||
gboolean xaccTransRegister (void)
|
||||
{
|
||||
static QofParam params[] =
|
||||
|
@ -106,23 +106,21 @@ struct find_lot_s
|
||||
{
|
||||
GNCLot *lot;
|
||||
gnc_commodity *currency;
|
||||
Timespec ts;
|
||||
time64 time;
|
||||
int (*numeric_pred)(gnc_numeric);
|
||||
gboolean (*date_pred)(Timespec e, Timespec tr);
|
||||
gboolean (*date_pred)(time64 e, time64 tr);
|
||||
};
|
||||
|
||||
static gboolean
|
||||
earliest_pred (Timespec earl, Timespec tran)
|
||||
earliest_pred (time64 earl, time64 tran)
|
||||
{
|
||||
return ((earl.tv_sec > tran.tv_sec) ||
|
||||
((earl.tv_sec == tran.tv_sec) && (earl.tv_nsec > tran.tv_nsec)));
|
||||
return earl > tran;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
latest_pred (Timespec earl, Timespec tran)
|
||||
latest_pred (time64 earl, time64 tran)
|
||||
{
|
||||
return ((earl.tv_sec < tran.tv_sec) ||
|
||||
((earl.tv_sec == tran.tv_sec) && (earl.tv_nsec < tran.tv_nsec)));
|
||||
return earl < tran;
|
||||
}
|
||||
|
||||
static gpointer
|
||||
@ -133,7 +131,7 @@ finder_helper (GNCLot *lot, gpointer user_data)
|
||||
Transaction *trans;
|
||||
gnc_numeric bal;
|
||||
gboolean opening_is_positive, bal_is_positive;
|
||||
Timespec posted_ts = {0,0};
|
||||
time64 posted = 0;
|
||||
|
||||
if (gnc_lot_is_closed (lot)) return NULL;
|
||||
|
||||
@ -158,10 +156,10 @@ finder_helper (GNCLot *lot, gpointer user_data)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
posted_ts.tv_sec = trans->date_posted;
|
||||
if (els->date_pred (els->ts, posted_ts))
|
||||
posted = trans->date_posted;
|
||||
if (els->date_pred (els->time, posted))
|
||||
{
|
||||
els->ts.tv_sec = trans->date_posted;
|
||||
els->time = trans->date_posted;
|
||||
els->lot = lot;
|
||||
}
|
||||
|
||||
@ -172,14 +170,13 @@ static inline GNCLot *
|
||||
xaccAccountFindOpenLot (Account *acc, gnc_numeric sign,
|
||||
gnc_commodity *currency,
|
||||
gint64 guess,
|
||||
gboolean (*date_pred)(Timespec, Timespec))
|
||||
gboolean (*date_pred)(time64, time64))
|
||||
{
|
||||
struct find_lot_s es;
|
||||
|
||||
es.lot = NULL;
|
||||
es.currency = currency;
|
||||
es.ts.tv_sec = guess;
|
||||
es.ts.tv_nsec = 0;
|
||||
es.time = guess;
|
||||
es.date_pred = date_pred;
|
||||
|
||||
if (gnc_numeric_positive_p(sign)) es.numeric_pred = gnc_numeric_negative_p;
|
||||
@ -324,13 +321,12 @@ xaccSplitAssignToLot (Split *split, GNCLot *lot)
|
||||
/* If we are here, then (cmp == +1 iff (amt > baln)) and we need
|
||||
* to split up the split into pieces. Do it. */
|
||||
{
|
||||
time64 now = gnc_time (NULL);
|
||||
time64 now = gnc_time (NULL), time = 0;
|
||||
Split * new_split;
|
||||
gnc_numeric amt_a, amt_b, amt_tot;
|
||||
gnc_numeric val_a, val_b, val_tot;
|
||||
gnc_numeric frac;
|
||||
Transaction *trans;
|
||||
Timespec ts;
|
||||
|
||||
acc = split->acc;
|
||||
xaccAccountBeginEdit (acc);
|
||||
@ -400,8 +396,8 @@ xaccSplitAssignToLot (Split *split, GNCLot *lot)
|
||||
* split-action which is the same as xaccSplitGetAction */
|
||||
gnc_set_num_action(NULL, new_split, NULL, gnc_get_num_action(NULL, split));
|
||||
xaccSplitSetReconcile (new_split, xaccSplitGetReconcile (split));
|
||||
ts = xaccSplitRetDateReconciledTS (split);
|
||||
xaccSplitSetDateReconciledTS (new_split, &ts);
|
||||
time = xaccSplitGetDateReconciled (split);
|
||||
xaccSplitSetDateReconciledSecs (new_split, time);
|
||||
|
||||
/* Set the lot-split and peer_guid properties on the two
|
||||
* splits to indicate that they're linked.
|
||||
|
@ -51,34 +51,6 @@ cannot be considered "standard" or public parts of QOF. */
|
||||
|
||||
static QofLogModule log_module = GNC_MOD_ENGINE;
|
||||
|
||||
Timespec
|
||||
gnc_transaction_get_date_posted(const Transaction *t)
|
||||
{
|
||||
Timespec ret = {xaccTransRetDatePosted(t), 0};
|
||||
return ret;
|
||||
}
|
||||
|
||||
Timespec
|
||||
gnc_transaction_get_date_entered(const Transaction *t)
|
||||
{
|
||||
Timespec result = {xaccTransRetDateEntered(t), 0};
|
||||
return result;
|
||||
}
|
||||
|
||||
Timespec
|
||||
gnc_split_get_date_reconciled(const Split *s)
|
||||
{
|
||||
Timespec result;
|
||||
xaccSplitGetDateReconciledTS(s, &result);
|
||||
return(result);
|
||||
}
|
||||
|
||||
void
|
||||
gnc_transaction_set_date(Transaction *t, Timespec ts)
|
||||
{
|
||||
xaccTransSetDatePostedSecs(t, ts.tv_sec);
|
||||
}
|
||||
|
||||
/** Gets the transaction Number or split Action based on book option:
|
||||
* if the book option is TRUE (split action is used for NUM) and a
|
||||
* split is provided, split-action is returned; if book option is FALSE
|
||||
|
@ -34,13 +34,6 @@
|
||||
|
||||
typedef void (*GncBOCb) (gpointer new_val, gpointer user_data);
|
||||
|
||||
Timespec gnc_transaction_get_date_posted(const Transaction *t);
|
||||
Timespec gnc_transaction_get_date_entered(const Transaction *t);
|
||||
|
||||
Timespec gnc_split_get_date_reconciled(const Split *s);
|
||||
|
||||
void gnc_transaction_set_date(Transaction *t, Timespec ts);
|
||||
|
||||
/** Gets the transaction Number or split Action based on book option:
|
||||
* if the book option is TRUE (split action is used for NUM) and a
|
||||
* split is provided, split-action is returned; if book option is FALSE
|
||||
|
@ -144,7 +144,7 @@ int qof_instance_compare_kvp (const QofInstance *a, const QofInstance *b);
|
||||
/** Returns a g_strdup'd string which must be g_freed. */
|
||||
char* qof_instance_kvp_as_string (const QofInstance *inst);
|
||||
void qof_instance_kvp_add_guid (const QofInstance *inst, const char* path,
|
||||
const Timespec time, const char* key,
|
||||
time64 time, const char* key,
|
||||
const GncGUID *guid);
|
||||
void qof_instance_kvp_remove_guid (const QofInstance *inst, const char *path,
|
||||
const char* key, const GncGUID *guid);
|
||||
|
@ -1138,13 +1138,13 @@ qof_instance_kvp_as_string (const QofInstance *inst)
|
||||
|
||||
void
|
||||
qof_instance_kvp_add_guid (const QofInstance *inst, const char* path,
|
||||
const Timespec time, const char *key,
|
||||
time64 time, const char *key,
|
||||
const GncGUID *guid)
|
||||
{
|
||||
g_return_if_fail (inst->kvp_data != NULL);
|
||||
|
||||
auto container = new KvpFrame;
|
||||
Time64 t{time.tv_sec};
|
||||
Time64 t{time};
|
||||
container->set({key}, new KvpValue(const_cast<GncGUID*>(guid)));
|
||||
container->set({"date"}, new KvpValue(t));
|
||||
delete inst->kvp_data->set_path({path}, new KvpValue(container));
|
||||
|
@ -1267,7 +1267,7 @@ get_random_split(QofBook *book, Account *acct, Transaction *trn)
|
||||
const gchar *str;
|
||||
gnc_commodity *com;
|
||||
int scu, denom;
|
||||
Timespec *ts;
|
||||
time64 time;
|
||||
|
||||
com = xaccTransGetCurrency (trn);
|
||||
scu = gnc_commodity_get_fraction(com);
|
||||
@ -1281,9 +1281,8 @@ get_random_split(QofBook *book, Account *acct, Transaction *trn)
|
||||
|
||||
xaccSplitSetReconcile(ret, possible_chars[get_random_int_in_range(0, 3)]);
|
||||
|
||||
ts = get_random_timespec();
|
||||
xaccSplitSetDateReconciledTS(ret, ts);
|
||||
g_free(ts);
|
||||
time = get_random_time();
|
||||
xaccSplitSetDateReconciledSecs (ret, time);
|
||||
|
||||
/* Split must be in an account before we can set an amount */
|
||||
/* and in a transaction before it can be added to an account. */
|
||||
@ -1364,7 +1363,7 @@ void
|
||||
make_random_changes_to_split (Split *split)
|
||||
{
|
||||
Transaction *trans;
|
||||
Timespec *ts;
|
||||
time64 time;
|
||||
|
||||
g_return_if_fail (split);
|
||||
|
||||
@ -1377,9 +1376,8 @@ make_random_changes_to_split (Split *split)
|
||||
|
||||
xaccSplitSetReconcile (split, possible_chars[get_random_int_in_range(0, 3)]);
|
||||
|
||||
ts = get_random_timespec();
|
||||
xaccSplitSetDateReconciledTS (split, ts);
|
||||
g_free(ts);
|
||||
time = get_random_time();
|
||||
xaccSplitSetDateReconciledSecs (split, time);
|
||||
|
||||
qof_instance_set_slots (QOF_INSTANCE (split), get_random_kvp_frame());
|
||||
|
||||
|
@ -65,7 +65,7 @@ setup (Fixture *fixture, gconstpointer pData)
|
||||
GNCLot *lot = gnc_lot_new (book);
|
||||
gnc_numeric value = gnc_numeric_create (123, 240);
|
||||
gnc_numeric amount = gnc_numeric_create (321, 1000);
|
||||
Timespec time = timespec_now ();
|
||||
time64 time = gnc_time(NULL);
|
||||
Split *gains_split = xaccMallocSplit (book);
|
||||
fixture->curr = gnc_commodity_new (book, "Gnu Rand", "CURRENCY", "GNR", "", 240);
|
||||
fixture->comm = gnc_commodity_new (book, "Wildebeest Fund", "FUND", "WBFXX", "", 1000);
|
||||
@ -303,7 +303,7 @@ test_xaccDupeSplit (Fixture *fixture, gconstpointer pData)
|
||||
g_assert_cmpstr (split->action, ==, f_split->action);
|
||||
g_assert (compare (split->inst.kvp_data, f_split->inst.kvp_data) == 0);
|
||||
g_assert_cmpint (split->reconciled, ==, f_split->reconciled);
|
||||
g_assert (timespec_equal (&(split->date_reconciled), &(f_split->date_reconciled)));
|
||||
g_assert_cmpint (split->date_reconciled, ==, f_split->date_reconciled);
|
||||
g_assert (gnc_numeric_equal (split->value, f_split->value));
|
||||
g_assert (gnc_numeric_equal (split->amount, f_split->amount));
|
||||
/* xaccDupeSplit intentionally doesn't copy the balances */
|
||||
@ -338,7 +338,7 @@ test_xaccSplitCloneNoKvp (Fixture *fixture, gconstpointer pData)
|
||||
g_assert_cmpstr (split->action, ==, f_split->action);
|
||||
g_assert (split->inst.kvp_data->empty());
|
||||
g_assert_cmpint (split->reconciled, ==, f_split->reconciled);
|
||||
g_assert (timespec_equal (&(split->date_reconciled), &(f_split->date_reconciled)));
|
||||
g_assert_cmpint (split->date_reconciled, == , f_split->date_reconciled);
|
||||
g_assert (gnc_numeric_equal (split->value, f_split->value));
|
||||
g_assert (gnc_numeric_equal (split->amount, f_split->amount));
|
||||
g_assert (gnc_numeric_equal (split->balance, f_split->balance));
|
||||
@ -1204,14 +1204,14 @@ test_xaccSplitOrder (Fixture *fixture, gconstpointer pData)
|
||||
o_split->value = split->value;
|
||||
/* Make sure that it doesn't crash if o_split->date_reconciled == NULL */
|
||||
g_assert_cmpint (xaccSplitOrder (split, o_split), ==, 1);
|
||||
o_split->date_reconciled = timespec_now();
|
||||
o_split->date_reconciled.tv_sec -= 50;
|
||||
o_split->date_reconciled = gnc_time(NULL);
|
||||
o_split->date_reconciled -= 50;
|
||||
g_assert_cmpint (xaccSplitOrder (split, o_split), ==, 1);
|
||||
o_split->date_reconciled.tv_sec += 100;
|
||||
o_split->date_reconciled += 100;
|
||||
g_assert_cmpint (xaccSplitOrder (split, o_split), ==, -1);
|
||||
|
||||
o_split->date_reconciled.tv_sec = split->date_reconciled.tv_sec;
|
||||
o_split->date_reconciled.tv_nsec = split->date_reconciled.tv_nsec;
|
||||
o_split->date_reconciled = split->date_reconciled;
|
||||
o_split->date_reconciled = split->date_reconciled;
|
||||
|
||||
g_assert_cmpint (xaccSplitOrder (split, o_split), ==,
|
||||
qof_instance_guid_compare (split, o_split));
|
||||
|
@ -408,7 +408,8 @@ test_gnc_transaction_set_get_property (Fixture *fixture, gconstpointer pData)
|
||||
gchar *t_num = NULL, *t_desc = NULL;
|
||||
gnc_commodity *curr = gnc_commodity_new (book, "Gnu Rand", "CURRENCY",
|
||||
"GNR", "", 240), *t_curr = NULL;
|
||||
Timespec now = timespec_now (), *t_entered = NULL, *t_posted = NULL;
|
||||
time64 now = gnc_time(NULL);
|
||||
Time64 *t_entered, *t_posted;
|
||||
g_assert_cmpstr (txn->num, ==, "");
|
||||
g_assert_cmpstr (txn->description, ==, "");
|
||||
g_assert (txn->common_currency == NULL);
|
||||
@ -427,8 +428,8 @@ test_gnc_transaction_set_get_property (Fixture *fixture, gconstpointer pData)
|
||||
g_assert_cmpstr (txn->num, ==, num);
|
||||
g_assert_cmpstr (txn->description, ==, desc);
|
||||
g_assert (txn->common_currency == curr);
|
||||
g_assert (txn->date_entered == now.tv_sec);
|
||||
g_assert (txn->date_posted == now.tv_sec);
|
||||
g_assert (txn->date_entered == now);
|
||||
g_assert (txn->date_posted == now);
|
||||
|
||||
g_object_get (G_OBJECT (txn),
|
||||
"num", &t_num,
|
||||
@ -441,8 +442,8 @@ test_gnc_transaction_set_get_property (Fixture *fixture, gconstpointer pData)
|
||||
g_assert_cmpstr (t_num, ==, num);
|
||||
g_assert_cmpstr (t_desc, ==, desc);
|
||||
g_assert (t_curr == curr);
|
||||
g_assert (t_entered->tv_sec == now.tv_sec);
|
||||
g_assert (t_posted->tv_sec == now.tv_sec);
|
||||
g_assert_cmpint (t_entered->t, ==, now);
|
||||
g_assert_cmpint (t_posted->t, ==, now);
|
||||
xaccTransRollbackEdit (txn);
|
||||
test_destroy (txn);
|
||||
test_destroy (curr);
|
||||
@ -1772,10 +1773,7 @@ test_xaccTransOrder_num_action (Fixture *fixture, gconstpointer pData)
|
||||
* xaccTransSetDatePostedSecs C: 17 in 13 Local: 0:0:0
|
||||
* xaccTransSetDatePostedGDate C: 1 Local: 1:0:0
|
||||
* xaccTransSetDateEnteredSecs C: 10 in 9 Local: 0:0:0
|
||||
* xaccTransSetDatePostedTS C: 9 in 8 Local: 2:0:0
|
||||
* xaccTransSetDateEnteredTS C: 3 in 3 Local: 1:0:0
|
||||
* xaccTransSetDate C: 43 in 23 SCM: 2 in 2 Local: 0:0:0
|
||||
* xaccTransSetDateDueTS C: 2 in 2 Local: 0:0:0
|
||||
* xaccTransSetTxnType C: 4 in 3 Local: 0:0:0
|
||||
* xaccTransClearReadOnly C: 4 in 2 Local: 1:0:0
|
||||
* xaccTransSetReadOnly C: 2 in 2 Local: 1:0:0
|
||||
@ -1843,7 +1841,7 @@ test_xaccTransVoid (Fixture *fixture, gconstpointer pData)
|
||||
auto frame = fixture->txn->inst.kvp_data;
|
||||
auto void_reason = "Voided for Unit Test";
|
||||
auto txn_notes = g_strdup (frame->get_slot({trans_notes_str})->get<const char*>());
|
||||
Timespec now = timespec_now ();
|
||||
time64 now = gnc_time(NULL);
|
||||
char iso8601_str[ISO_DATELENGTH + 1] = "";
|
||||
GList *split = NULL;
|
||||
|
||||
@ -1854,7 +1852,7 @@ test_xaccTransVoid (Fixture *fixture, gconstpointer pData)
|
||||
==, txn_notes);
|
||||
g_assert_cmpstr (frame->get_slot({void_reason_str})->get<const char*>(), ==,
|
||||
void_reason);
|
||||
gnc_timespec_to_iso8601_buff (now, iso8601_str);
|
||||
gnc_time64_to_iso8601_buff (now, iso8601_str);
|
||||
g_assert_cmpstr (frame->get_slot({void_time_str})->get<const char*>(), ==,
|
||||
iso8601_str);
|
||||
g_assert_cmpstr (frame->get_slot({TRANS_READ_ONLY_REASON})->get<const char*>(),
|
||||
|
Loading…
Reference in New Issue
Block a user