Transaction members Timespec->time64

This commit is contained in:
lmat 2017-12-31 07:37:02 -05:00 committed by Christopher Lam
parent 9a86dd222b
commit 1f050fd1e5
30 changed files with 262 additions and 369 deletions

View File

@ -1504,7 +1504,7 @@ create_transaction(XferDialog *xferData, Timespec *ts,
xaccTransBeginEdit(trans);
xaccTransSetCurrency(trans, xferData->from_commodity);
xaccTransSetDatePostedTS(trans, ts);
xaccTransSetDatePostedSecs(trans, ts->tv_sec);
/* Trans-Num or Split-Action set with gnc_set_num_action below per book
* option */

View File

@ -1521,7 +1521,7 @@ static gboolean gtcsr_move_current_entry_updown(GncTreeViewSplitReg *view,
/* Only continue if both have the same date and num, because the
* "standard ordering" is tied to the date anyway. */
{
Timespec t1, t2;
time64 time1, time2;
GDate d1 = xaccTransGetDatePostedGDate(current_trans),
d2 = xaccTransGetDatePostedGDate(target_trans);
if (g_date_compare(&d1, &d2) != 0)
@ -1540,9 +1540,9 @@ static gboolean gtcsr_move_current_entry_updown(GncTreeViewSplitReg *view,
dates as timespec. See the comment in gncEntrySetDateGDate() for the
reason: Some code used the timespec at noon for the EntryDate, other
code used the timespec at the start of day. */
t1 = xaccTransRetDatePostedTS(current_trans);
t2 = xaccTransRetDatePostedTS(target_trans);
if (really_do_it && !timespec_equal(&t1, &t2))
time1 = xaccTransRetDatePosted(current_trans);
time2 = xaccTransRetDatePosted(target_trans);
if (really_do_it && time1 != time2)
{
/* Timespecs are not equal, even though the GDates were equal? Then
we set the GDates again. This will force the timespecs to be equal
@ -1587,12 +1587,12 @@ static gboolean gtcsr_move_current_entry_updown(GncTreeViewSplitReg *view,
/* Swap the date-entered of both entries. That's already
* sufficient! */
{
Timespec time_current = xaccTransRetDateEnteredTS(current_trans);
Timespec time_target = xaccTransRetDateEnteredTS(target_trans);
time64 time_current = xaccTransRetDateEntered(current_trans);
time64 time_target = xaccTransRetDateEntered(target_trans);
/* Special treatment for identical times (potentially caused
* by the "duplicate entry" command) */
if (timespec_equal(&time_current, &time_target))
if (time_current == time_target)
{
g_warning("Surprise - both DateEntered are equal.");
/* We just increment the DateEntered of the previously
@ -1600,14 +1600,14 @@ static gboolean gtcsr_move_current_entry_updown(GncTreeViewSplitReg *view,
* issues if multiple entries had this problem, but
* whatever. */
if (move_up)
time_current.tv_sec++;
++time_current;
else
time_target.tv_sec++;
++time_target;
}
/* Write the new DateEntered. */
xaccTransSetDateEnteredTS(current_trans, &time_target);
xaccTransSetDateEnteredTS(target_trans, &time_current);
xaccTransSetDateEnteredSecs(current_trans, time_target);
xaccTransSetDateEnteredSecs(target_trans, time_current);
/* FIXME: Do we need to notify anyone about the changed ordering? */
}

View File

@ -832,7 +832,6 @@ gnc_tree_model_split_reg_get_tooltip (GncTreeModelSplitReg *model, gint position
Transaction *trans;
const gchar *date_text;
const gchar *desc_text;
Timespec ts = {0,0};
GList *node;
priv = model->priv;
@ -849,7 +848,7 @@ gnc_tree_model_split_reg_get_tooltip (GncTreeModelSplitReg *model, gint position
return g_strconcat ("Blank Transaction", NULL);
else
{
xaccTransGetDatePostedTS (trans, &ts);
Timespec ts = {xaccTransRetDatePosted (trans), 0};
date_text = gnc_print_date (ts);
desc_text = xaccTransGetDescription (trans);
model->current_trans = trans;

View File

@ -192,7 +192,7 @@ gtu_sr_handle_exchange_rate (GncTreeViewSplitReg *view, gnc_numeric amount, Tran
/* Get per book option */
gnc_xfer_dialog_set_num (xfer, gnc_get_num_action (trans, split));
gnc_xfer_dialog_set_date (xfer, timespecToTime64 (xaccTransRetDatePostedTS (trans)));
gnc_xfer_dialog_set_date (xfer, xaccTransRetDatePosted (trans));
value = amount;
if (gnc_xfer_dialog_run_exchange_dialog (xfer, &rate_split, value, reg_acc, trans, xfer_comm, expanded))

View File

@ -1474,33 +1474,23 @@ gtv_sr_cdf0 (GtkTreeViewColumn *col, GtkCellRenderer *cell, GtkTreeModel *s_mode
show_extra_dates = TRUE;
if (is_trow1) {
Timespec ts = {0,0};
xaccTransGetDatePostedTS (trans, &ts);
Timespec ts = {xaccTransRetDatePosted (trans),0};
//If the time returned by xaccTransGetDatePostedTS is 0 then assume it
//is a new transaction and set the time to current time to show current
//date on new transactions
if (ts.tv_sec == 0)
{
ts.tv_sec = gnc_time (NULL);
//xaccTransSetDatePostedSecs (trans, ts.tv_sec);
}//if
s = gnc_print_date (ts);
editable = TRUE;
}
else if (is_trow2 && show_extra_dates) {
Timespec ts = {0,0};
Timespec ts = {xaccTransRetDateEntered (trans),0};
g_object_set (cell, "cell-background", YELLOWCELL, (gchar*)NULL);
xaccTransGetDateEnteredTS (trans, &ts);
//If the time returned by xaccTransGetDateEnteredTS is 0 then assume it
//is a new transaction and set the time to current time to show current
//date on new transactions
if (ts.tv_sec == 0)
{
ts.tv_sec = gnc_time (NULL);
//xaccTransSetDateEnteredSecs (trans, ts.tv_sec);
}//if
s = gnc_print_date (ts);
editable = FALSE;
}
@ -1559,12 +1549,10 @@ gtv_sr_cdf0 (GtkTreeViewColumn *col, GtkCellRenderer *cell, GtkTreeModel *s_mode
g_object_set (cell, "cell-background", "white", (gchar*)NULL);
if (is_trow1) {
Timespec ts = {0,0};
/* Only print the due date for invoice transactions */
if (type == TXN_TYPE_INVOICE)
{
xaccTransGetDateDueTS (trans, &ts);
Timespec ts = {xaccTransRetDateDue (trans), 0};
s = gnc_print_date (ts);
editable = FALSE;
}
@ -2518,21 +2506,18 @@ gtv_sr_begin_edit (GncTreeViewSplitReg *view, Transaction *trans)
if (trans != view->priv->dirty_trans)
{
Timespec ts = {0,0};
xaccTransGetDatePostedTS (trans, &ts);
time64 time = xaccTransRetDatePosted (trans);
if (!xaccTransIsOpen (trans))
xaccTransBeginEdit (trans);
view->priv->dirty_trans = trans;
if (ts.tv_sec == 0)
if (!time)
{
//If the time returned by xaccTransGetDatePostedTS is 0 then assume it
//is a new transaction and set the time to current time to show current
//date on new transactions
ts.tv_sec = gnc_time (NULL);
xaccTransSetDatePostedSecs (trans, ts.tv_sec);
time = gnc_time (NULL);
xaccTransSetDatePostedSecs (trans, time);
}
}
LEAVE(" ");

View File

@ -344,8 +344,7 @@ get_trans_info (AssocDialog *assoc_dialog)
{
gchar *uri_u;
gboolean rel = FALSE;
Timespec ts = {0,0};
xaccTransGetDatePostedTS (trans, &ts);
Timespec ts = {xaccTransRetDatePosted (trans),0};
if (ts.tv_sec == 0)
ts.tv_sec = gnc_time (NULL);

View File

@ -552,10 +552,10 @@ static void trans_add_split (Transaction* trans, Account* account, GncNumeric am
value = amount * *price;
else
{
auto tts = xaccTransRetDatePostedTS (trans);
Timespec ts = {xaccTransRetDatePosted (trans), 0};
/* Import data didn't specify price, let's lookup the nearest in time */
auto nprice = gnc_pricedb_lookup_nearest_in_time(gnc_pricedb_get_db(book),
acct_comm, trans_curr, tts);
acct_comm, trans_curr, ts);
if (nprice)
{
/* Found a usable price. Let's check if the conversion direction is right */

View File

@ -98,16 +98,13 @@ gnc_split_register_save_due_date_cell (BasicCell * cell,
SRSaveData *sd = save_data;
const char *value;
time64 time;
Timespec ts;
g_return_if_fail (gnc_basic_cell_has_name (cell, DDUE_CELL));
value = gnc_basic_cell_get_value (cell);
/* commit any pending changes */
gnc_date_cell_commit ((DateCell *) cell);
DEBUG ("DATE: %s", value ? value : "(null)");
gnc_date_cell_get_date ((DateCell *) cell, &time);
ts.tv_sec = time;
ts.tv_nsec = 0;
xaccTransSetDateDueTS (sd->trans, &ts);
xaccTransSetDateDue (sd->trans, time);
}
static void

View File

@ -829,7 +829,7 @@ gnc_split_register_get_due_date_entry (VirtualLocation virt_loc,
SplitRegister *reg = user_data;
Transaction *trans;
Split *split;
Timespec ts;
Timespec ts = {0, 0};
gboolean is_current;
char type;
@ -866,7 +866,7 @@ gnc_split_register_get_due_date_entry (VirtualLocation virt_loc,
return NULL;
}
xaccTransGetDateDueTS (trans, &ts);
ts.tv_sec = xaccTransRetDateDue (trans);
//PWARN ("returning valid due_date entry");
return gnc_print_date (ts);
@ -881,14 +881,14 @@ gnc_split_register_get_date_entry (VirtualLocation virt_loc,
SplitRegister *reg = user_data;
Transaction *trans;
Split *split;
Timespec ts;
Timespec ts = {0, 0};
split = gnc_split_register_get_split (reg, virt_loc.vcell_loc);
trans = xaccSplitGetParent (split);
if (!trans)
return NULL;
xaccTransGetDatePostedTS (trans, &ts);
ts.tv_sec = xaccTransRetDatePosted (trans);
return gnc_print_date (ts);
}

View File

@ -56,6 +56,13 @@ add_gnc_num (xmlNodePtr node, const gchar* tag, gnc_numeric num)
xmlAddChild (node, gnc_numeric_to_dom_tree (tag, &num));
}
static void
add_time64 (xmlNodePtr node, const gchar * tag, time64 time, gboolean always)
{
if (always || time)
xmlAddChild (node, time64_to_dom_tree (tag, time));
}
static void
add_timespec (xmlNodePtr node, const gchar* tag, Timespec tms, gboolean always)
{
@ -172,10 +179,10 @@ gnc_transaction_dom_tree_create (Transaction* trn)
}
g_free (str);
add_timespec (ret, "trn:date-posted", xaccTransRetDatePostedTS (trn), TRUE);
add_time64 (ret, "trn:date-posted", xaccTransRetDatePosted (trn), TRUE);
add_timespec (ret, "trn:date-entered",
xaccTransRetDateEnteredTS (trn), TRUE);
add_time64 (ret, "trn:date-entered",
xaccTransRetDateEntered (trn), TRUE);
str = g_strdup (xaccTransGetDescription (trn));
if (str)
@ -426,6 +433,16 @@ set_tran_string (xmlNodePtr node, Transaction* trn,
return TRUE;
}
static gboolean
set_tran_time64 (xmlNodePtr node, Transaction * trn,
void (*func) (Transaction *, time64))
{
time64 time = dom_tree_to_time64 (node);
if (!dom_tree_valid_time64 (time, node->name)) return FALSE;
func (trn, time);
return TRUE;
}
static inline gboolean
set_tran_date (xmlNodePtr node, Transaction* trn,
void (*func) (Transaction* trn, const Timespec* tm))
@ -481,7 +498,7 @@ trn_date_posted_handler (xmlNodePtr node, gpointer trans_pdata)
struct trans_pdata* pdata = static_cast<decltype (pdata)> (trans_pdata);
Transaction* trn = pdata->trans;
return set_tran_date (node, trn, xaccTransSetDatePostedTS);
return set_tran_time64 (node, trn, xaccTransSetDatePostedSecs);
}
static gboolean
@ -490,7 +507,7 @@ trn_date_entered_handler (xmlNodePtr node, gpointer trans_pdata)
struct trans_pdata* pdata = static_cast<decltype (pdata)> (trans_pdata);
Transaction* trn = pdata->trans;
return set_tran_date (node, trn, xaccTransSetDateEnteredTS);
return set_tran_time64 (node, trn, xaccTransSetDateEnteredSecs);
}
static gboolean

View File

@ -277,10 +277,9 @@ equals_node_val_vs_kvp_frame (xmlNodePtr node, const KvpFrame* frm)
}
gboolean
equals_node_val_vs_date (xmlNodePtr node, const Timespec tm)
equals_node_val_vs_date (xmlNodePtr node, time64 time)
{
time64 time = dom_tree_to_time64 (node);
return time == tm.tv_sec;
return time == dom_tree_to_time64 (node);
}
/***********************************************************************/

View File

@ -57,7 +57,7 @@ gboolean equals_node_val_vs_guid (xmlNodePtr node, const GncGUID* id);
gboolean equals_node_val_vs_commodity (xmlNodePtr node,
const gnc_commodity* com, QofBook*);
gboolean equals_node_val_vs_kvp_frame (xmlNodePtr node, const KvpFrame* frm);
gboolean equals_node_val_vs_date (xmlNodePtr node, const Timespec tm);
gboolean equals_node_val_vs_date (xmlNodePtr node, time64);
gboolean equals_node_val_vs_int (xmlNodePtr node, gint64 val);
gboolean equals_node_val_vs_boolean (xmlNodePtr node, gboolean val);

View File

@ -287,14 +287,14 @@ node_and_transaction_equal (xmlNodePtr node, Transaction* trn)
}
else if (g_strcmp0 ((char*)mark->name, "trn:date-posted") == 0)
{
if (!equals_node_val_vs_date (mark, xaccTransRetDatePostedTS (trn)))
if (!equals_node_val_vs_date (mark, xaccTransRetDatePosted (trn)))
{
return "posted dates differ";
}
}
else if (g_strcmp0 ((char*)mark->name, "trn:date-entered") == 0)
{
if (!equals_node_val_vs_date (mark, xaccTransRetDateEnteredTS (trn)))
if (!equals_node_val_vs_date (mark, xaccTransRetDateEntered (trn)))
{
return "entered dates differ";
}

View File

@ -3292,7 +3292,6 @@ xaccAccountGetBalanceAsOfDate (Account *acc, time64 date)
*/
AccountPrivate *priv;
GList *lp;
Timespec ts, trans_ts;
gboolean found = FALSE;
gnc_numeric balance;
@ -3316,15 +3315,12 @@ xaccAccountGetBalanceAsOfDate (Account *acc, time64 date)
* xaccAccountGetPresentBalance gets this right, and its algorithm
* should be used here.
*/
ts.tv_sec = date;
ts.tv_nsec = 0;
lp = priv->splits;
while ( lp && !found )
{
xaccTransGetDatePostedTS( xaccSplitGetParent( (Split *)lp->data ),
&trans_ts );
if ( timespec_cmp( &trans_ts, &ts ) >= 0 )
time64 trans_time = xaccTransRetDatePosted( xaccSplitGetParent( (Split *)lp->data ));
if ( trans_time >= date )
found = TRUE;
else
lp = lp->next;

View File

@ -597,13 +597,13 @@ xaccQueryGetEarliestDateFound(QofQuery * q)
/* Safe until 2038 on archs where time64 is 32bit */
sp = spl->data;
earliest = sp->parent->date_posted.tv_sec;
earliest = sp->parent->date_posted;
for (; spl; spl = spl->next)
{
sp = spl->data;
if (sp->parent->date_posted.tv_sec < earliest)
if (sp->parent->date_posted < earliest)
{
earliest = sp->parent->date_posted.tv_sec;
earliest = sp->parent->date_posted;
}
}
return earliest;
@ -627,9 +627,9 @@ xaccQueryGetLatestDateFound(QofQuery * q)
for (; spl; spl = spl->next)
{
sp = spl->data;
if (sp->parent->date_posted.tv_sec > latest)
if (sp->parent->date_posted > latest)
{
latest = sp->parent->date_posted.tv_sec;
latest = sp->parent->date_posted;
}
}
return latest;

View File

@ -1399,11 +1399,11 @@ xaccTransScrubPostedDate (Transaction *trans)
{
time64 orig = xaccTransGetDate(trans);
GDate date = xaccTransGetDatePostedGDate(trans);
Timespec ts = gdate_to_timespec(date);
if (orig && orig != ts.tv_sec)
time64 time = gdate_to_time64(date);
if (orig && orig != time)
{
/* xaccTransSetDatePostedTS handles committing the change. */
xaccTransSetDatePostedTS(trans, &ts);
xaccTransSetDatePostedSecs(trans, time);
}
}

View File

@ -1538,11 +1538,9 @@ xaccSplitOrderDateOnly (const Split *sa, const Split *sb)
if ( !tb ) return -1;
if ( !ta ) return +1;
/* if dates differ, return */
DATE_CMP(ta, tb, date_posted);
/* If the dates are the same, do not change the order */
return -1;
if (ta->date_posted == tb->date_posted)
return -1; // Keep the same order
return (ta->date_posted > tb->date_posted) - (ta->date_posted < tb->date_posted);
}
static gboolean

View File

@ -227,7 +227,6 @@ xaccTransWriteLog (Transaction *trans, char flag)
char split_guid_str[GUID_ENCODING_LENGTH + 1];
const char *trans_notes;
char dnow[100], dent[100], dpost[100], drecn[100];
Timespec ts;
if (!gen_logs)
{
@ -236,21 +235,16 @@ xaccTransWriteLog (Transaction *trans, char flag)
}
if (!trans_log) return;
timespecFromTime64(&ts, gnc_time (NULL));
gnc_timespec_to_iso8601_buff (ts, dnow);
timespecFromTime64(&ts, trans->date_entered.tv_sec);
gnc_timespec_to_iso8601_buff (ts, dent);
timespecFromTime64(&ts, trans->date_posted.tv_sec);
gnc_timespec_to_iso8601_buff (ts, dpost);
gnc_time64_to_iso8601_buff (gnc_time(NULL), dnow);
gnc_time64_to_iso8601_buff (trans->date_entered, dent);
gnc_time64_to_iso8601_buff (trans->date_posted, dpost);
guid_to_string_buff (xaccTransGetGUID(trans), trans_guid_str);
trans_notes = xaccTransGetNotes(trans);
fprintf (trans_log, "===== START\n");
for (node = trans->splits; node; node = node->next)
{
Timespec ts;
Split *split = node->data;
const char * accname = "";
char acc_guid_str[GUID_ENCODING_LENGTH + 1];

View File

@ -275,16 +275,10 @@ gnc_transaction_init(Transaction* trans)
/* Fill in some sane defaults */
trans->num = CACHE_INSERT("");
trans->description = CACHE_INSERT("");
trans->common_currency = NULL;
trans->splits = NULL;
trans->date_entered.tv_sec = 0;
trans->date_entered.tv_nsec = 0;
trans->date_posted.tv_sec = 0;
trans->date_posted.tv_nsec = 0;
trans->date_entered = 0;
trans->date_posted = 0;
trans->marker = 0;
trans->orig = NULL;
LEAVE (" ");
@ -316,6 +310,7 @@ gnc_transaction_get_property(GObject* object,
{
Transaction* tx;
gchar *key;
Timespec ts = {0,0};
g_return_if_fail(GNC_IS_TRANSACTION(object));
@ -332,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);
ts.tv_sec = tx->date_posted;
g_value_set_boxed(value, &ts);
break;
case PROP_ENTER_DATE:
g_value_set_boxed(value, &tx->date_entered);
ts.tv_sec = tx->date_entered;
g_value_set_boxed(value, &ts);
break;
case PROP_INVOICE:
qof_instance_get_kvp (QOF_INSTANCE (tx), value, 2, GNC_INVOICE_ID, GNC_INVOICE_GUID);
@ -378,10 +375,10 @@ gnc_transaction_set_property(GObject* object,
xaccTransSetCurrency(tx, g_value_get_object(value));
break;
case PROP_POST_DATE:
xaccTransSetDatePostedTS(tx, g_value_get_boxed(value));
xaccTransSetDatePostedSecs(tx, ((Timespec*)g_value_get_boxed(value))->tv_sec);
break;
case PROP_ENTER_DATE:
xaccTransSetDateEnteredTS(tx, g_value_get_boxed(value));
xaccTransSetDateEnteredSecs(tx, ((Timespec*)g_value_get_boxed(value))->tv_sec);
break;
case PROP_INVOICE:
qof_instance_set_kvp (QOF_INSTANCE (tx), value, 2, GNC_INVOICE_ID, GNC_INVOICE_GUID);
@ -741,7 +738,6 @@ void
xaccTransCopyFromClipBoard(const Transaction *from_trans, Transaction *to_trans,
const Account *from_acc, Account *to_acc, gboolean no_date)
{
Timespec ts = {0,0};
gboolean change_accounts = FALSE;
GList *node;
@ -764,8 +760,7 @@ xaccTransCopyFromClipBoard(const Transaction *from_trans, Transaction *to_trans,
xaccTransSetNotes(to_trans, xaccTransGetNotes(from_trans));
if(!no_date)
{
xaccTransGetDatePostedTS(from_trans, &ts);
xaccTransSetDatePostedTS(to_trans, &ts);
xaccTransSetDatePostedSecs(to_trans, xaccTransRetDatePosted (from_trans));
}
/* Each new split will be parented to 'to' */
@ -813,12 +808,8 @@ xaccFreeTransaction (Transaction *trans)
/* Just in case someone looks up freed memory ... */
trans->num = (char *) 1;
trans->description = NULL;
trans->date_entered.tv_sec = 0;
trans->date_entered.tv_nsec = 0;
trans->date_posted.tv_sec = 0;
trans->date_posted.tv_nsec = 0;
trans->date_entered = 0;
trans->date_posted = 0;
if (trans->orig)
{
xaccFreeTransaction (trans->orig);
@ -892,24 +883,24 @@ xaccTransEqual(const Transaction *ta, const Transaction *tb,
return FALSE;
}
if (timespec_cmp(&(ta->date_entered), &(tb->date_entered)))
if (ta->date_entered != tb->date_entered)
{
char buf1[100];
char buf2[100];
(void)gnc_timespec_to_iso8601_buff(ta->date_entered, buf1);
(void)gnc_timespec_to_iso8601_buff(tb->date_entered, buf2);
(void)gnc_time64_to_iso8601_buff(ta->date_entered, buf1);
(void)gnc_time64_to_iso8601_buff(tb->date_entered, buf2);
PINFO ("date entered differs: '%s' vs '%s'", buf1, buf2);
return FALSE;
}
if (timespec_cmp(&(ta->date_posted), &(tb->date_posted)))
if (ta->date_posted != tb->date_posted)
{
char buf1[100];
char buf2[100];
(void)gnc_timespec_to_iso8601_buff(ta->date_posted, buf1);
(void)gnc_timespec_to_iso8601_buff(tb->date_posted, buf2);
(void)gnc_time64_to_iso8601_buff(ta->date_posted, buf1);
(void)gnc_time64_to_iso8601_buff(tb->date_posted, buf2);
PINFO ("date posted differs: '%s' vs '%s'", buf1, buf2);
return FALSE;
}
@ -1683,9 +1674,9 @@ xaccTransCommitEdit (Transaction *trans)
}
/* Record the time of last modification */
if (0 == trans->date_entered.tv_sec)
if (0 == trans->date_entered)
{
trans->date_entered.tv_sec = gnc_time(NULL);
trans->date_entered = gnc_time(NULL);
qof_instance_set_dirty(QOF_INSTANCE(trans));
}
@ -1890,8 +1881,8 @@ xaccTransOrder_num_action (const Transaction *ta, const char *actna,
if ( !ta && tb ) return +1;
if ( !ta && !tb ) return 0;
/* if dates differ, return */
DATE_CMP(ta, tb, date_posted);
if (ta->date_posted != tb->date_posted)
return (ta->date_posted > tb->date_posted) - (ta->date_posted < tb->date_posted);
/* otherwise, sort on number string */
if (actna && actnb) /* split action string, if not NULL */
@ -1907,8 +1898,8 @@ xaccTransOrder_num_action (const Transaction *ta, const char *actna,
if (na < nb) return -1;
if (na > nb) return +1;
/* if dates differ, return */
DATE_CMP(ta, tb, date_entered);
if (ta->date_entered != tb->date_entered)
return (ta->date_entered > tb->date_entered) - (ta->date_entered < tb->date_entered);
/* otherwise, sort on description string */
da = ta->description ? ta->description : "";
@ -1925,7 +1916,7 @@ xaccTransOrder_num_action (const Transaction *ta, const char *actna,
\********************************************************************/
static inline void
xaccTransSetDateInternal(Transaction *trans, Timespec *dadate, Timespec val)
xaccTransSetDateInternal(Transaction *trans, time64 *dadate, time64 val)
{
xaccTransBeginEdit(trans);
@ -1962,9 +1953,8 @@ set_gains_date_dirty (Transaction *trans)
void
xaccTransSetDatePostedSecs (Transaction *trans, time64 secs)
{
Timespec ts = {secs, 0};
if (!trans) return;
xaccTransSetDateInternal(trans, &trans->date_posted, ts);
xaccTransSetDateInternal(trans, &trans->date_posted, secs);
set_gains_date_dirty (trans);
}
@ -1990,16 +1980,15 @@ xaccTransSetDatePostedGDate (Transaction *trans, GDate date)
qof_instance_set_kvp (QOF_INSTANCE(trans), &v, 1, TRANS_DATE_POSTED);
/* mark dirty and commit handled by SetDateInternal */
xaccTransSetDateInternal(trans, &trans->date_posted,
gdate_to_timespec(date));
gdate_to_time64(date));
set_gains_date_dirty (trans);
}
void
xaccTransSetDateEnteredSecs (Transaction *trans, time64 secs)
{
Timespec ts = {secs, 0};
if (!trans) return;
xaccTransSetDateInternal(trans, &trans->date_entered, ts);
xaccTransSetDateInternal(trans, &trans->date_entered, secs);
}
static void
@ -2008,36 +1997,23 @@ qofTransSetDatePosted (Transaction *trans, Timespec ts)
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);
xaccTransSetDateInternal(trans, &trans->date_posted, ts.tv_sec);
set_gains_date_dirty(trans);
qof_commit_edit(&trans->inst);
}
void
xaccTransSetDatePostedTS (Transaction *trans, const Timespec *ts)
{
if (!trans || !ts) return;
xaccTransSetDateInternal(trans, &trans->date_posted, *ts);
set_gains_date_dirty (trans);
}
static void
qofTransSetDateEntered (Transaction *trans, Timespec ts)
{
/*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);
xaccTransSetDateInternal(trans, &trans->date_entered, ts.tv_sec);
qof_commit_edit(&trans->inst);
}
void
xaccTransSetDateEnteredTS (Transaction *trans, const Timespec *ts)
{
if (!trans || !ts) return;
xaccTransSetDateInternal(trans, &trans->date_entered, *ts);
}
void
xaccTransSetDate (Transaction *trans, int day, int mon, int year)
{
@ -2057,18 +2033,12 @@ xaccTransSetDate (Transaction *trans, int day, int mon, int year)
void
xaccTransSetDateDue (Transaction * trans, time64 time)
{
Timespec ts_send = {time, 0};
xaccTransSetDateDueTS (trans, &ts_send);
}
void
xaccTransSetDateDueTS (Transaction *trans, const Timespec *ts)
{
GValue v = G_VALUE_INIT;
if (!trans || !ts) return;
Timespec send_ts = {time, 0};
if (!trans) return;
g_value_init (&v, GNC_TYPE_TIMESPEC);
g_value_set_boxed (&v, ts);
g_value_set_boxed (&v, &send_ts);
xaccTransBeginEdit(trans);
qof_instance_set_kvp (QOF_INSTANCE (trans), &v, 1, TRANS_DATE_DUE_KVP);
qof_instance_set_dirty(QOF_INSTANCE(trans));
@ -2377,42 +2347,21 @@ xaccTransGetIsClosingTxn (const Transaction *trans)
time64
xaccTransGetDate (const Transaction *trans)
{
return trans ? trans->date_posted.tv_sec : 0;
return trans ? trans->date_posted : 0;
}
/*################## Added for Reg2 #################*/
time64
xaccTransGetDateEntered (const Transaction *trans)
{
return trans ? trans->date_entered.tv_sec : 0;
return trans ? trans->date_entered : 0;;
}
/*################## Added for Reg2 #################*/
void
xaccTransGetDatePostedTS (const Transaction *trans, Timespec *ts)
{
if (trans && ts)
*ts = trans->date_posted;
}
void
xaccTransGetDateEnteredTS (const Transaction *trans, Timespec *ts)
{
if (trans && ts)
*ts = trans->date_entered;
}
Timespec
xaccTransRetDatePostedTS (const Transaction *trans)
{
Timespec ts = {0, 0};
return trans ? trans->date_posted : ts;
}
time64
xaccTransRetDatePosted (const Transaction *trans)
{
return trans ? trans->date_posted.tv_sec : 0;
return trans ? trans->date_posted : 0;
}
GDate
@ -2451,44 +2400,24 @@ xaccTransGetDatePostedGDate (const Transaction *trans)
return result;
}
Timespec
xaccTransRetDateEnteredTS (const Transaction *trans)
{
Timespec ts = {0, 0};
return trans ? trans->date_entered : ts;
}
time64
xaccTransRetDateEntered (const Transaction *trans)
{
return trans ? trans->date_entered.tv_sec : 0;
}
void
xaccTransGetDateDueTS (const Transaction *trans, Timespec *ts)
{
GValue v = G_VALUE_INIT;
if (!trans || !ts) return;
qof_instance_get_kvp (QOF_INSTANCE (trans), &v, 1, TRANS_DATE_DUE_KVP);
if (G_VALUE_HOLDS_BOXED (&v))
*ts = *(Timespec*)g_value_get_boxed (&v);
if (ts->tv_sec == 0)
xaccTransGetDatePostedTS (trans, ts);
return trans ? trans->date_entered : 0;
}
time64
xaccTransRetDateDue(const Transaction *trans)
{
return xaccTransRetDateDueTS (trans).tv_sec;
}
Timespec
xaccTransRetDateDueTS (const Transaction *trans)
{
Timespec ts = {0, 0};
if (trans) xaccTransGetDateDueTS (trans, &ts);
return ts;
time64 ret = 0;
GValue v = G_VALUE_INIT;
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;
if (!ret)
return xaccTransRetDatePosted (trans);
return ret;
}
char
@ -2596,7 +2525,7 @@ gboolean xaccTransInFutureByPostedDate (const Transaction *trans)
present = gnc_time64_get_today_end ();
if (trans->date_posted.tv_sec > present)
if (trans->date_posted > present)
result = TRUE;
else
result = FALSE;
@ -2881,8 +2810,6 @@ static void
xaccTransScrubGainsDate (Transaction *trans)
{
SplitList *node;
Timespec ts = {0, 0};
//restart_search:
for (node = trans->splits; node; node = node->next)
{
Split *s = node->data;
@ -2896,13 +2823,10 @@ xaccTransScrubGainsDate (Transaction *trans)
(s->gains & GAINS_STATUS_DATE_DIRTY)))
{
Transaction *source_trans = s->gains_split->parent;
ts = source_trans->date_posted;
s->gains &= ~GAINS_STATUS_DATE_DIRTY;
s->gains_split->gains &= ~GAINS_STATUS_DATE_DIRTY;
xaccTransSetDatePostedTS(trans, &ts);
xaccTransSetDatePostedSecs(trans, source_trans->date_posted);
FOR_EACH_SPLIT(trans, s->gains &= ~GAINS_STATUS_DATE_DIRTY);
//goto restart_search;
}
}
}
@ -3015,6 +2939,39 @@ 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[] =
@ -3033,12 +2990,12 @@ gboolean xaccTransRegister (void)
{
TRANS_DATE_ENTERED, QOF_TYPE_DATE,
(QofAccessFunc)xaccTransRetDateEnteredTS,
(QofSetterFunc)qofTransSetDateEntered
(QofSetterFunc)qofTransSetDateEnteredTS
},
{
TRANS_DATE_POSTED, QOF_TYPE_DATE,
(QofAccessFunc)xaccTransRetDatePostedTS,
(QofSetterFunc)qofTransSetDatePosted
(QofSetterFunc)qofTransSetDatePostedTS
},
{
TRANS_DATE_DUE, QOF_TYPE_DATE,

View File

@ -625,21 +625,11 @@ void xaccTransSetDatePostedSecs (Transaction *trans, time64 time);
* The posted date is the date when this transaction was posted at the bank. */
void xaccTransSetDatePostedSecsNormalized (Transaction *trans, time64 time);
/** The xaccTransSetDatePostedTS() method does the same thing as
xaccTransSetDatePostedSecs(), but takes a struct timespec64. */
void xaccTransSetDatePostedTS (Transaction *trans,
const Timespec *ts);
/** Modify the date of when the transaction was entered. The entered
* date is the date when the register entry was made. */
void xaccTransSetDateEnteredSecs (Transaction *trans, time64 time);
/** Modify the date of when the transaction was entered. The entered
* date is the date when the register entry was made. */
void xaccTransSetDateEnteredTS (Transaction *trans,
const Timespec *ts);
/** Dates and txn-type for A/R and A/P "invoice" postings */
void xaccTransSetDateDueTS (Transaction *trans, const Timespec *ts);
void xaccTransSetDateDue (Transaction * trans, time64 time);
/** Retrieve the posted date of the transaction. The posted date is
@ -651,12 +641,6 @@ time64 xaccTransGetDate (const Transaction *trans);
the date when this transaction was posted at the bank. (Although
having different function names, GetDate and GetDatePosted refer
to the same single date.)*/
void xaccTransGetDatePostedTS (const Transaction *trans, Timespec *ts);
/** Retrieve the posted date of the transaction. The posted date is
the date when this transaction was posted at the bank. (Although
having different function names, GetDate and GetDatePosted refer
to the same single date.)*/
Timespec xaccTransRetDatePostedTS (const Transaction *trans);
time64 xaccTransRetDatePosted (const Transaction *trans);
/** Retrieve the posted date of the transaction. The posted date is
the date when this transaction was posted at the bank. */
@ -669,17 +653,10 @@ time64 xaccTransGetDateEntered (const Transaction *trans);
/*################## Added for Reg2 #################*/
/** Retrieve the date of when the transaction was entered. The entered
* date is the date when the register entry was made.*/
void xaccTransGetDateEnteredTS (const Transaction *trans, Timespec *ts);
/** Retrieve the date of when the transaction was entered. The entered
* date is the date when the register entry was made.*/
Timespec xaccTransRetDateEnteredTS (const Transaction *trans);
time64 xaccTransRetDateEntered (const Transaction *trans);
/** Dates and txn-type for A/R and A/P "invoice" postings */
Timespec xaccTransRetDateDueTS (const Transaction *trans);
time64 xaccTransRetDateDue (const Transaction *trans);
/** Dates and txn-type for A/R and A/P "invoice" postings */
void xaccTransGetDateDueTS (const Transaction *trans, Timespec *ts);
/** @} */

View File

@ -75,8 +75,8 @@ struct transaction_s
{
QofInstance inst; /* glbally unique id */
Timespec date_entered; /* date register entry was made */
Timespec date_posted; /* date transaction was posted at bank */
time64 date_entered; /* date register entry was made */
time64 date_posted; /* date transaction was posted at bank */
/* The num field is a arbitrary user-assigned field.
* It is intended to store a short id number, typically the check number,

View File

@ -133,6 +133,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};
if (gnc_lot_is_closed (lot)) return NULL;
@ -157,9 +158,10 @@ finder_helper (GNCLot *lot, gpointer user_data)
return NULL;
}
if (els->date_pred (els->ts, trans->date_posted))
posted_ts.tv_sec = trans->date_posted;
if (els->date_pred (els->ts, posted_ts))
{
els->ts = trans->date_posted;
els->ts.tv_sec = trans->date_posted;
els->lot = lot;
}
@ -762,7 +764,6 @@ xaccSplitComputeCapGains(Split *split, Account *gain_acc)
{
Transaction *trans;
Split *lot_split, *gain_split;
Timespec ts;
gboolean new_gain_split;
gnc_numeric negvalue = gnc_numeric_neg (value);
@ -869,8 +870,8 @@ xaccSplitComputeCapGains(Split *split, Account *gain_acc)
if (new_gain_split)
{
/* Common to both */
ts = xaccTransRetDatePostedTS (split->parent);
xaccTransSetDatePostedTS (trans, &ts);
time64 time = xaccTransRetDatePosted (split->parent);
xaccTransSetDatePostedSecs (trans, time);
xaccTransSetDateEnteredSecs (trans, gnc_time (NULL));
xaccSplitSetAmount (lot_split, zero);

View File

@ -54,17 +54,15 @@ static QofLogModule log_module = GNC_MOD_ENGINE;
Timespec
gnc_transaction_get_date_posted(const Transaction *t)
{
Timespec result;
xaccTransGetDatePostedTS(t, &result);
return(result);
Timespec ret = {xaccTransRetDatePosted(t), 0};
return ret;
}
Timespec
gnc_transaction_get_date_entered(const Transaction *t)
{
Timespec result;
xaccTransGetDateEnteredTS(t, &result);
return(result);
Timespec result = {xaccTransRetDateEntered(t), 0};
return result;
}
Timespec
@ -78,7 +76,7 @@ gnc_split_get_date_reconciled(const Split *s)
void
gnc_transaction_set_date(Transaction *t, Timespec ts)
{
xaccTransSetDatePostedTS(t, &ts);
xaccTransSetDatePostedSecs(t, ts.tv_sec);
}
/** Gets the transaction Number or split Action based on book option:

View File

@ -1223,6 +1223,13 @@ gnc_iso8601_to_time64_gmt(const char *cstr)
/********************************************************************\
\********************************************************************/
char *
gnc_time64_to_iso8601_buff (time64 time, char * buff)
{
Timespec ts = {time, 0};
return gnc_timespec_to_iso8601_buff (ts, buff);
}
char *
gnc_timespec_to_iso8601_buff (Timespec ts, char * buff)
{

View File

@ -414,6 +414,7 @@ time64 gnc_iso8601_to_time64_gmt(const gchar *);
* on the machine on which it is executing to create the time string.
*/
gchar * gnc_timespec_to_iso8601_buff (Timespec ts, gchar * buff);
gchar * gnc_time64_to_iso8601_buff (time64, char * buff);
/** Set the proleptic Gregorian day, month, and year from a Timespec
* \param ts: input timespec

View File

@ -712,12 +712,12 @@ gncOwnerLotsSortFunc (GNCLot *lotA, GNCLot *lotB)
if (ia)
da = gncInvoiceGetDateDue (ia);
else
da = xaccTransRetDatePostedTS (xaccSplitGetParent (gnc_lot_get_earliest_split (lotA))).tv_sec;
da = xaccTransRetDatePosted (xaccSplitGetParent (gnc_lot_get_earliest_split (lotA)));
if (ib)
db = gncInvoiceGetDateDue (ib);
else
db = xaccTransRetDatePostedTS (xaccSplitGetParent (gnc_lot_get_earliest_split (lotB))).tv_sec;
db = xaccTransRetDatePosted (xaccSplitGetParent (gnc_lot_get_earliest_split (lotB)));
return (da > db) - (da < db);
}
@ -814,7 +814,7 @@ gncOwnerCreatePaymentLot (const GncOwner *owner, Transaction **preset_txn,
/* set per book option */
xaccTransSetCurrency (txn, commodity);
xaccTransSetDateEnteredSecs (txn, gnc_time (NULL));
xaccTransSetDatePostedTS (txn, &date);
xaccTransSetDatePostedSecs (txn, date.tv_sec);
/* The split for the transfer account */
@ -1100,7 +1100,7 @@ gncOwnerCreateLotLink (GNCLot *from_lot, GNCLot *to_lot, const GncOwner *owner)
const gchar *name = gncOwnerGetName (gncOwnerGetEndOwner (owner));
Transaction *ll_txn = NULL;
gnc_numeric from_lot_bal, to_lot_bal;
Timespec from_ts, to_ts;
time64 from_time, to_time;
time64 time_posted;
Split *split;
@ -1110,12 +1110,12 @@ gncOwnerCreateLotLink (GNCLot *from_lot, GNCLot *to_lot, const GncOwner *owner)
return;
/* Determine transaction date based on lot splits */
from_ts = xaccTransRetDatePostedTS (xaccSplitGetParent (gnc_lot_get_latest_split (from_lot)));
to_ts = xaccTransRetDatePostedTS (xaccSplitGetParent (gnc_lot_get_latest_split (to_lot)));
if (timespecToTime64 (from_ts) >= timespecToTime64 (to_ts))
time_posted = timespecToTime64 (from_ts);
from_time = xaccTransRetDatePosted (xaccSplitGetParent (gnc_lot_get_latest_split (from_lot)));
to_time = xaccTransRetDatePosted (xaccSplitGetParent (gnc_lot_get_latest_split (to_lot)));
if (from_time >= to_time)
time_posted = from_time;
else
time_posted = timespecToTime64 (to_ts);
time_posted = to_time;
/* Figure out how much we can offset between the lots */
from_lot_bal = gnc_lot_get_balance (from_lot);
@ -1137,31 +1137,22 @@ gncOwnerCreateLotLink (GNCLot *from_lot, GNCLot *to_lot, const GncOwner *owner)
if (!ll_txn)
{
/* No pre-existing lot link. Create one. */
Timespec ts;
timespecFromTime64 (&ts, time_posted);
ll_txn = xaccMallocTransaction (gnc_lot_get_book (from_lot));
xaccTransBeginEdit (ll_txn);
xaccTransSetDescription (ll_txn, name ? name : "(Unknown)");
xaccTransSetCurrency (ll_txn, xaccAccountGetCommodity(acct));
xaccTransSetDateEnteredSecs (ll_txn, gnc_time (NULL));
xaccTransSetDatePostedTS (ll_txn, &ts);
xaccTransSetDatePostedSecs (ll_txn, time_posted);
xaccTransSetTxnType (ll_txn, TXN_TYPE_LINK);
}
else
{
Timespec ts = xaccTransRetDatePostedTS (ll_txn);
time64 time = xaccTransRetDatePosted (ll_txn);
xaccTransBeginEdit (ll_txn);
/* Maybe we need to update the post date of the transaction ? */
if (time_posted > timespecToTime64 (ts))
{
timespecFromTime64 (&ts, time_posted);
xaccTransSetDatePostedTS (ll_txn, &ts);
}
if (time_posted > time)
xaccTransSetDatePostedSecs (ll_txn, time_posted);
}
/* Create a split for the from_lot */

View File

@ -114,7 +114,7 @@ DirectionPolicyGetSplit (GNCPolicy *pcy, GNCLot *lot, short reverse)
gnc_numeric baln;
Split *osplit;
Transaction *otrans;
Timespec open_ts;
time64 open_time;
Account* lot_account;
if (!pcy || !lot || !gnc_lot_get_split_list(lot)) return NULL;
@ -136,7 +136,7 @@ DirectionPolicyGetSplit (GNCPolicy *pcy, GNCLot *lot, short reverse)
and the lot may end up too thin or too fat. */
osplit = gnc_lot_get_latest_split (lot);
otrans = osplit ? xaccSplitGetParent (osplit) : 0;
open_ts = xaccTransRetDatePostedTS (otrans);
open_time = xaccTransRetDatePosted (otrans);
/* Walk over *all* splits in the account, till we find one that
* hasn't been assigned to a lot. Return that split.
@ -151,15 +151,13 @@ DirectionPolicyGetSplit (GNCPolicy *pcy, GNCLot *lot, short reverse)
{
gboolean is_match;
gboolean is_positive;
Timespec this_ts;
time64 this_time;
split = node->data;
if (split->lot) goto donext;
/* Skip it if it's too early */
this_ts = xaccTransRetDatePostedTS ( xaccSplitGetParent (split));
if ((this_ts.tv_sec < open_ts.tv_sec) ||
((this_ts.tv_sec == open_ts.tv_sec) &&
(this_ts.tv_nsec < open_ts.tv_nsec)))
this_time = xaccTransRetDatePosted ( xaccSplitGetParent (split));
if (this_time < open_time)
{
if (reverse)
/* Going backwards, no point in looking further */

View File

@ -1420,16 +1420,10 @@ set_tran_random_string_from_array(
(func)(trn, tmp_str);
}
static void
trn_add_ran_timespec(Transaction *trn, void (*func)(Transaction*,
const Timespec*))
trn_add_ran_time (Transaction *trn, void (*func)(Transaction*, time64))
{
Timespec *to_set;
to_set = get_random_timespec();
func(trn, to_set);
g_free(to_set);
func(trn, get_random_time());
}
@ -1471,8 +1465,8 @@ get_random_transaction_with_currency(QofBook *book,
xaccTransSetNum(trans, numstr);
set_tran_random_string_from_array(trans, xaccTransSetDescription,
sane_descriptions);
trn_add_ran_timespec(trans, xaccTransSetDatePostedTS);
trn_add_ran_timespec(trans, xaccTransSetDateEnteredTS);
trn_add_ran_time(trans, xaccTransSetDatePostedSecs);
trn_add_ran_time(trans, xaccTransSetDateEnteredSecs);
f = get_random_kvp_frame();
qof_instance_set_slots (QOF_INSTANCE (trans), f);
@ -1531,8 +1525,8 @@ make_random_changes_to_transaction (QofBook *book, Transaction *trans)
set_tran_random_string (trans, xaccTransSetNum);
trn_add_ran_timespec (trans, xaccTransSetDatePostedTS);
trn_add_ran_timespec (trans, xaccTransSetDateEnteredTS);
trn_add_ran_time (trans, xaccTransSetDatePostedSecs);
trn_add_ran_time (trans, xaccTransSetDateEnteredSecs);
set_tran_random_string (trans, xaccTransSetDescription);
@ -2055,10 +2049,8 @@ make_trans_query (Transaction *trans, TestQueryTypes query_types)
}
{
Timespec ts;
xaccTransGetDatePostedTS (trans, &ts);
xaccQueryAddDateMatchTS (q, TRUE, ts, TRUE, ts, QOF_QUERY_AND);
time64 time = xaccTransRetDatePosted (trans);
xaccQueryAddDateMatchTT (q, TRUE, time, TRUE, time, QOF_QUERY_AND);
}
if (xaccSplitGetMemo(s) && *xaccSplitGetMemo(s) != '\0')

View File

@ -1125,7 +1125,7 @@ test_xaccSplitOrder (Fixture *fixture, gconstpointer pData)
* split-action based on book option.
*/
o_split->parent = o_txn;
split->parent->date_posted = timespec_now ();
split->parent->date_posted = gnc_time (NULL);
o_split->parent->date_posted = split->parent->date_posted;
/* The book_use_split_action_for_num_field book option hasn't been set so it
@ -1249,13 +1249,13 @@ test_xaccSplitOrderDateOnly (Fixture *fixture, gconstpointer pData)
g_assert_cmpint (xaccSplitOrderDateOnly (split, o_split), ==, 1);
split->parent = txn;
txn->date_posted = timespec_now ();
o_txn->date_posted = timespec_now ();
o_txn->date_posted.tv_sec -= 50;
txn->date_posted = gnc_time (nullptr);
o_txn->date_posted = gnc_time (nullptr);
o_txn->date_posted -= 50;
g_assert_cmpint (xaccSplitOrderDateOnly (split, o_split), ==, 1);
o_txn->date_posted.tv_sec += 100;
o_txn->date_posted += 100;
g_assert_cmpint (xaccSplitOrderDateOnly (split, o_split), ==, -1);
o_txn->date_posted.tv_sec -= 50;
o_txn->date_posted -= 50;
g_assert_cmpint (xaccSplitOrderDateOnly (split, o_split), ==, -1);
test_destroy (o_split);

View File

@ -119,8 +119,8 @@ setup (Fixture *fixture, gconstpointer pData)
QofBook *book = qof_book_new ();
TransMockBackend *mbe = new TransMockBackend;
Transaction *txn;
Timespec entered = gnc_dmy2timespec (20, 4, 2012);
Timespec posted = gnc_dmy2timespec (21, 4, 2012);
time64 entered = gnc_dmy2time64 (20, 4, 2012);
time64 posted = gnc_dmy2time64 (21, 4, 2012);
auto frame = new KvpFrame ();
qof_book_set_backend (book, mbe);
@ -134,10 +134,8 @@ setup (Fixture *fixture, gconstpointer pData)
fixture->acc2 = xaccMallocAccount (book);
xaccAccountSetCommodity (fixture->acc1, fixture->comm);
xaccAccountSetCommodity (fixture->acc2, fixture->curr);
txn->date_posted.tv_sec = posted.tv_sec;
txn->date_posted.tv_nsec = posted.tv_nsec;
txn->date_entered.tv_sec = entered.tv_sec;
txn->date_entered.tv_nsec = entered.tv_nsec;
txn->date_posted = posted;
txn->date_entered = entered;
split1->memo = static_cast<char*>(CACHE_INSERT ("foo"));
split1->action = static_cast<char*>(CACHE_INSERT ("bar"));
split1->amount = gnc_numeric_create (100000, 1000);
@ -343,10 +341,8 @@ test_gnc_transaction_init ()
g_assert_cmpstr (txn->description, ==, "");
g_assert (txn->common_currency == NULL);
g_assert (txn->splits == NULL);
g_assert_cmpint (txn->date_entered.tv_sec, ==, 0);
g_assert_cmpint (txn->date_entered.tv_nsec, ==, 0);
g_assert_cmpint (txn->date_posted.tv_sec, ==, 0);
g_assert_cmpint (txn->date_posted.tv_nsec, ==, 0);
g_assert_cmpint (txn->date_entered, ==, 0);
g_assert_cmpint (txn->date_posted, ==, 0);
g_assert_cmpint (txn->marker, ==, 0);
g_assert (txn->orig == NULL);
@ -416,10 +412,8 @@ test_gnc_transaction_set_get_property (Fixture *fixture, gconstpointer pData)
g_assert_cmpstr (txn->num, ==, "");
g_assert_cmpstr (txn->description, ==, "");
g_assert (txn->common_currency == NULL);
g_assert_cmpint (txn->date_entered.tv_sec, ==, 0);
g_assert_cmpint (txn->date_entered.tv_nsec, ==, 0);
g_assert_cmpint (txn->date_posted.tv_sec, ==, 0);
g_assert_cmpint (txn->date_posted.tv_nsec, ==, 0);
g_assert_cmpint (txn->date_entered, ==, 0);
g_assert_cmpint (txn->date_posted, ==, 0);
/* Kick up the edit counter to keep from committing */
xaccTransBeginEdit (txn);
g_object_set (G_OBJECT (txn),
@ -433,8 +427,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 (timespec_equal (&(txn->date_entered), &now));
g_assert (timespec_equal (&(txn->date_posted), &now));
g_assert (txn->date_entered == now.tv_sec);
g_assert (txn->date_posted == now.tv_sec);
g_object_get (G_OBJECT (txn),
"num", &t_num,
@ -447,13 +441,12 @@ 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 (timespec_equal (t_entered, &now));
g_assert (timespec_equal (t_posted, &now));
g_assert (t_entered->tv_sec == now.tv_sec);
g_assert (t_posted->tv_sec == now.tv_sec);
xaccTransRollbackEdit (txn);
test_destroy (txn);
test_destroy (curr);
qof_book_destroy (book);
g_free (t_entered);
}
/* gnc_transaction_class_init
* xaccInitTransaction
@ -554,8 +547,8 @@ dupe_trans (const Transaction *from)// Local: 1:0:0
static void
test_dupe_trans (Fixture *fixture, gconstpointer pData)
{
Timespec posted = gnc_dmy2timespec (12, 7, 2011);
Timespec entered = gnc_dmy2timespec (14, 7, 2011);
time64 posted = gnc_dmy2time64 (12, 7, 2011);
time64 entered = gnc_dmy2time64 (14, 7, 2011);
Transaction *newtxn = NULL, *oldtxn = fixture->txn;
QofBook *old_book = qof_instance_get_book (QOF_INSTANCE (oldtxn));
GList *newnode, *oldnode = oldtxn->splits;
@ -579,8 +572,8 @@ test_dupe_trans (Fixture *fixture, gconstpointer pData)
}
g_assert (newnode == NULL);
g_assert (oldnode == NULL);
g_assert (timespec_equal (&(newtxn->date_posted), &posted));
g_assert (timespec_equal (&(newtxn->date_entered), &entered));
g_assert (newtxn->date_posted == posted);
g_assert (newtxn->date_entered == entered);
g_assert (qof_instance_version_cmp (QOF_INSTANCE (newtxn),
QOF_INSTANCE (oldtxn)) == 0);
g_assert (newtxn->orig == NULL);
@ -600,8 +593,8 @@ xaccTransClone (const Transaction *from)// C: 1 Local: 1:0:0
static void
test_xaccTransClone (Fixture *fixture, gconstpointer pData)
{
Timespec posted = gnc_dmy2timespec (12, 7, 2011);
Timespec entered = gnc_dmy2timespec (14, 7, 2011);
time64 posted = gnc_dmy2time64 (12, 7, 2011);
time64 entered = gnc_dmy2time64 (14, 7, 2011);
Transaction *newtxn = NULL, *oldtxn = fixture->txn;
QofBook *old_book = qof_instance_get_book (QOF_INSTANCE (oldtxn));
GList *newnode, *oldnode;
@ -631,8 +624,8 @@ test_xaccTransClone (Fixture *fixture, gconstpointer pData)
}
g_assert (newnode == NULL);
g_assert (oldnode == NULL);
g_assert (timespec_equal (&(newtxn->date_posted), &posted));
g_assert (timespec_equal (&(newtxn->date_entered), &entered));
g_assert (newtxn->date_posted == posted);
g_assert (newtxn->date_entered == entered);
g_assert (qof_instance_version_cmp (QOF_INSTANCE (newtxn),
QOF_INSTANCE (oldtxn)) == 0);
g_assert_cmpint (qof_instance_get_version_check (newtxn), ==,
@ -665,16 +658,16 @@ test_xaccTransCopyFromClipBoard (Fixture *fixture, gconstpointer pData)
QofBook *book = qof_instance_get_book (QOF_INSTANCE (txn));
Account *acc1 = xaccMallocAccount (book);
Transaction *to_txn = xaccMallocTransaction (book);
Timespec now = timespec_now();
Timespec never = {0, 0};
time64 now = gnc_time (nullptr);
time64 never = 0;
auto to_frame = to_txn->inst.kvp_data;
xaccAccountSetCommodity (acc1, fixture->comm);
xaccTransCopyFromClipBoard (txn, to_txn, fixture->acc1, acc1, FALSE);
g_assert (gnc_commodity_equal (txn->common_currency,
to_txn->common_currency));
g_assert (timespec_equal (&(to_txn->date_entered), &now));
g_assert (timespec_equal (&(to_txn->date_posted), &txn->date_posted));
g_assert (to_txn->date_entered == now);
g_assert (to_txn->date_posted == txn->date_posted);
g_assert_cmpstr (txn->num, ==, to_txn->num);
/* Notes also tests that KVP is copied */
g_assert_cmpstr (xaccTransGetNotes (txn), ==, xaccTransGetNotes (to_txn));
@ -692,15 +685,15 @@ test_xaccTransCopyFromClipBoard_no_start (Fixture *fixture, gconstpointer pData)
QofBook *book = qof_instance_get_book (QOF_INSTANCE (txn));
Account *acc1 = xaccMallocAccount (book);
Transaction *to_txn = xaccMallocTransaction (book);
Timespec now = timespec_now();
Timespec never = {0, 0};
time64 now = gnc_time (nullptr);
time64 never = 0;
xaccAccountSetCommodity (acc1, fixture->comm);
xaccTransCopyFromClipBoard (txn, to_txn, fixture->acc1, acc1, TRUE);
g_assert (gnc_commodity_equal (txn->common_currency,
to_txn->common_currency));
g_assert (timespec_equal (&(to_txn->date_entered), &now));
g_assert (timespec_equal (&(to_txn->date_posted), &never));
g_assert (to_txn->date_entered == now);
g_assert (to_txn->date_posted == never);
g_assert_cmpstr (to_txn->num, ==, txn->num);
/* Notes also tests that KVP is copied */
g_assert_cmpstr (xaccTransGetNotes (txn), ==, xaccTransGetNotes (to_txn));
@ -736,10 +729,8 @@ test_xaccFreeTransaction (Fixture *fixture, gconstpointer pData)
g_assert (txn->splits == NULL);
g_assert_cmpint (GPOINTER_TO_INT(txn->num), ==, 1);
g_assert (txn->description == NULL);
g_assert_cmpint (txn->date_entered.tv_sec, ==, 0);
g_assert_cmpint (txn->date_entered.tv_nsec, ==, 0);
g_assert_cmpint (txn->date_posted.tv_sec, ==, 0);
g_assert_cmpint (txn->date_posted.tv_nsec, ==, 0);
g_assert_cmpint (txn->date_entered, ==, 0);
g_assert_cmpint (txn->date_posted, ==, 0);
g_assert_cmpint (GPOINTER_TO_INT(orig->num), ==, 1);
g_assert (txn->orig == NULL);
test_destroy (orig);
@ -818,13 +809,13 @@ test_xaccTransEqual (Fixture *fixture, gconstpointer pData)
g_assert (!xaccTransEqual (clone, txn0, TRUE, FALSE, TRUE, TRUE));
g_assert_cmpint (check->hits, ==, 2);
gnc_timespec_to_iso8601_buff (clone->date_posted, posted);
gnc_timespec_to_iso8601_buff (clone->date_entered, entered);
gnc_time64_to_iso8601_buff (clone->date_posted, posted);
gnc_time64_to_iso8601_buff (clone->date_entered, entered);
xaccTransBeginEdit (clone);
cleanup->msg = g_strdup_printf (cleanup_fmt, clone->orig);
/* This puts the value of the first split back, but leaves the amount changed */
xaccTransSetCurrency (clone, fixture->curr);
clone->date_posted.tv_sec = txn0->date_entered.tv_sec;
clone->date_posted = txn0->date_entered;
xaccTransCommitEdit (clone);
g_free (cleanup->msg);
g_free (check->msg);
@ -834,8 +825,8 @@ test_xaccTransEqual (Fixture *fixture, gconstpointer pData)
xaccTransBeginEdit (clone);
cleanup->msg = g_strdup_printf (cleanup_fmt, clone->orig);
clone->date_posted.tv_sec = txn0->date_posted.tv_sec;
clone->date_entered.tv_sec = txn0->date_posted.tv_sec;
clone->date_posted = txn0->date_posted;
clone->date_entered = txn0->date_posted;
xaccTransCommitEdit (clone);
g_free (cleanup->msg);
g_free (check->msg);
@ -845,7 +836,7 @@ test_xaccTransEqual (Fixture *fixture, gconstpointer pData)
xaccTransBeginEdit (clone);
cleanup->msg = g_strdup_printf (cleanup_fmt, clone->orig);
clone->date_entered.tv_sec = txn0->date_entered.tv_sec;
clone->date_entered = txn0->date_entered;
clone->num = g_strdup("123");
xaccTransCommitEdit (clone);
g_free (cleanup->msg);
@ -1590,7 +1581,7 @@ test_xaccTransCommitEdit (void)
gnc_commodity *comm = gnc_commodity_new (book, "Wildebeest Fund",
"FUND", "WBFXX", "", 1000);
Timespec posted = gnc_dmy2timespec (21, 4, 2012);
time64 posted = gnc_dmy2time64 (21, 4, 2012);
auto sig_1_modify = test_signal_new (QOF_INSTANCE (split1),
QOF_EVENT_MODIFY, NULL);
@ -1602,8 +1593,7 @@ test_xaccTransCommitEdit (void)
xaccAccountSetCommodity (acc1, comm);
xaccAccountSetCommodity (acc2, curr);
txn->date_posted.tv_sec = posted.tv_sec;
txn->date_posted.tv_nsec = posted.tv_nsec;
txn->date_posted = posted;
split1->memo = static_cast<char*>(CACHE_INSERT ("foo"));
split1->action = static_cast<char*>(CACHE_INSERT ("bar"));
split1->amount = gnc_numeric_create (100000, 1000);
@ -1626,7 +1616,7 @@ test_xaccTransCommitEdit (void)
/* Setup's done, now test: */
xaccTransCommitEdit (txn);
g_assert_cmpint (txn->date_entered.tv_sec, !=, 0);
g_assert_cmpint (txn->date_entered, !=, 0);
/* Signals make sure that trans_cleanup_commit got called */
g_assert_cmpint (test_signal_return_hits (sig_1_modify), ==, 1);
g_assert_cmpint (test_signal_return_hits (sig_2_modify), ==, 1);
@ -1659,10 +1649,10 @@ test_xaccTransRollbackEdit (Fixture *fixture, gconstpointer pData)
Transaction *txn = fixture->txn;
Transaction *orig = NULL;
QofBook *book = qof_instance_get_book (txn);
Timespec new_post = timespec_now ();
Timespec new_entered = timespecCanonicalDayTime (timespec_now ());
Timespec orig_post = txn->date_posted;
Timespec orig_entered = txn->date_entered;
time64 new_post = gnc_time (nullptr);
time64 new_entered = time64CanonicalDayTime (new_post);
time64 orig_post = txn->date_posted;
time64 orig_entered = txn->date_entered;
KvpFrame *base_frame = NULL;
auto sig_account = test_signal_new (QOF_INSTANCE (fixture->acc1),
GNC_EVENT_ITEM_CHANGED, NULL);
@ -1705,8 +1695,8 @@ test_xaccTransRollbackEdit (Fixture *fixture, gconstpointer pData)
g_assert_cmpstr (txn->description, ==, "Waldo Pepper");
g_assert (txn->inst.kvp_data == base_frame);
g_assert (txn->common_currency == fixture->curr);
g_assert (timespec_equal (&(txn->date_posted), &orig_post));
g_assert (timespec_equal (&(txn->date_entered), &orig_entered));
g_assert (txn->date_posted == orig_post);
g_assert (txn->date_entered == orig_entered);
g_assert_cmpuint (test_signal_return_hits (sig_account), ==, 1);
g_assert_cmpuint (g_list_length (txn->splits), ==, 2);
g_assert_cmpint (GPOINTER_TO_INT(split_02->memo), ==, 1);
@ -1771,14 +1761,14 @@ test_xaccTransOrder_num_action (Fixture *fixture, gconstpointer pData)
qof_instance_guid_compare (txnA, txnB));
txnB->description = static_cast<char*>(CACHE_INSERT ("Salt Peanuts"));
g_assert_cmpint (xaccTransOrder_num_action (txnA, NULL, txnB, NULL), >=, 1);
txnB->date_entered.tv_sec += 1;
txnB->date_entered += 1;
g_assert_cmpint (xaccTransOrder_num_action (txnA, NULL, txnB, NULL), ==, -1);
txnB->num = static_cast<char*>(CACHE_INSERT ("101"));
g_assert_cmpint (xaccTransOrder_num_action (txnA, NULL, txnB, NULL), ==, 1);
txnB->num = static_cast<char*>(CACHE_INSERT ("one-oh-one"));
g_assert_cmpint (xaccTransOrder_num_action (txnA, NULL, txnB, NULL), ==, 1);
g_assert_cmpint (xaccTransOrder_num_action (txnA, "24", txnB, "42"), ==, -1);
txnB->date_posted.tv_sec -= 1;
txnB->date_posted -= 1;
g_assert_cmpint (xaccTransOrder_num_action (txnA, "24", txnB, "42"), ==, 1);
fixture->func->xaccFreeTransaction (txnB);
@ -1954,8 +1944,7 @@ test_xaccTransScrubGainsDate_no_dirty (GainsFixture *fixture,
fixture->base.func->xaccTransScrubGainsDate (fixture->base.txn);
g_assert (!timespec_equal (&(fixture->base.txn->date_posted),
&(fixture->gains_txn->date_posted)));
g_assert (fixture->base.txn->date_posted != fixture->gains_txn->date_posted);
g_assert_cmphex (base_split->gains & GAINS_STATUS_DATE_DIRTY, ==, 0);
g_assert_cmphex (base_split->gains_split->gains & GAINS_STATUS_DATE_DIRTY,
==, 0);
@ -1973,8 +1962,7 @@ test_xaccTransScrubGainsDate_base_dirty (GainsFixture *fixture,
fixture->base.func->xaccTransScrubGainsDate (fixture->base.txn);
g_assert (timespec_equal (&(fixture->base.txn->date_posted),
&(fixture->gains_txn->date_posted)));
g_assert (fixture->base.txn->date_posted == fixture->gains_txn->date_posted);
g_assert_cmphex (base_split->gains & GAINS_STATUS_DATE_DIRTY, ==, 0);
g_assert_cmphex (base_split->gains_split->gains & GAINS_STATUS_DATE_DIRTY,
==, 0);
@ -1992,8 +1980,7 @@ test_xaccTransScrubGainsDate_gains_dirty (GainsFixture *fixture,
fixture->base.func->xaccTransScrubGainsDate (fixture->base.txn);
g_assert (timespec_equal (&(fixture->base.txn->date_posted),
&(fixture->gains_txn->date_posted)));
g_assert (fixture->base.txn->date_posted == fixture->gains_txn->date_posted);
g_assert_cmphex (base_split->gains & GAINS_STATUS_DATE_DIRTY, ==, 0);
g_assert_cmphex (base_split->gains_split->gains & GAINS_STATUS_DATE_DIRTY,
==, 0);