Remove Timespec from gnucash/gnome-utils.

Plus a bit of bleed into gnome because of deleted functions.
This commit is contained in:
John Ralls 2018-07-31 11:25:45 -07:00
parent dd8732402f
commit e796120359
10 changed files with 79 additions and 115 deletions

View File

@ -282,7 +282,7 @@ gnc_dup_trans_dialog_gdate (GtkWidget * parent, GDate *gdate_p,
time64 tmp_time;
g_assert(gdate_p);
tmp_time = timespecToTime64(gdate_to_timespec(*gdate_p));
tmp_time = gdate_to_time64 (*gdate_p);
return gnc_dup_trans_dialog_internal(parent, NULL, TRUE, &tmp_time, gdate_p,
num, out_num, NULL, NULL);
}
@ -293,7 +293,7 @@ gnc_dup_date_dialog (GtkWidget * parent, const char* title, GDate *gdate_p)
time64 tmp_time;
g_assert(gdate_p);
tmp_time = timespecToTime64(gdate_to_timespec(*gdate_p));
tmp_time = gdate_to_time64(*gdate_p);
return gnc_dup_trans_dialog_internal(parent, title, TRUE, &tmp_time, gdate_p,
NULL, NULL, NULL, NULL);
}

View File

@ -230,7 +230,7 @@ typedef struct
GNCPriceDB *pricedb;
gnc_commodity *from;
gnc_commodity *to;
Timespec ts;
time64 time;
gboolean reverse;
} PriceReq;
@ -243,7 +243,7 @@ price_request_from_xferData(PriceReq *pr, XferDialog *xd)
pr->pricedb = xd->pricedb;
pr->from = xd->from_commodity;
pr->to = xd->to_commodity;
pr->ts = gnc_date_edit_get_date_ts (GNC_DATE_EDIT (xd->date_entry));
pr->time = gnc_date_edit_get_date (GNC_DATE_EDIT (xd->date_entry));
pr->reverse = FALSE;
}
@ -261,12 +261,12 @@ lookup_price(PriceReq *pr, PriceDate pd)
{
default:
case SAME_DAY:
prc = gnc_pricedb_lookup_day (pr->pricedb, pr->from,
pr->to, pr->ts);
prc = gnc_pricedb_lookup_day_t64 (pr->pricedb, pr->from,
pr->to, pr->time);
break;
case NEAREST:
prc = gnc_pricedb_lookup_nearest_in_time (pr->pricedb, pr->from,
pr->to, pr->ts);
prc = gnc_pricedb_lookup_nearest_in_time64 (pr->pricedb, pr->from,
pr->to, pr->time);
break;
case LATEST:
prc = gnc_pricedb_lookup_latest (pr->pricedb, pr->from, pr->to);
@ -1499,7 +1499,7 @@ check_edit(XferDialog *xferData)
}
static void
create_transaction(XferDialog *xferData, Timespec *ts,
create_transaction(XferDialog *xferData, time64 time,
Account *from_account, Account* to_account,
gnc_numeric amount, gnc_numeric to_amount)
{
@ -1513,7 +1513,7 @@ create_transaction(XferDialog *xferData, Timespec *ts,
xaccTransBeginEdit(trans);
xaccTransSetCurrency(trans, xferData->from_commodity);
xaccTransSetDatePostedSecs(trans, ts->tv_sec);
xaccTransSetDatePostedSecs(trans, time);
/* Trans-Num or Split-Action set with gnc_set_num_action below per book
* option */
@ -1601,7 +1601,7 @@ update_price(XferDialog *xferData, PriceReq *pr)
return;
}
gnc_price_begin_edit (pr->price);
gnc_price_set_time (pr->price, pr->ts);
gnc_price_set_time64 (pr->price, pr->time);
gnc_price_set_typestr(pr->price, xferData->price_type);
gnc_price_set_value (pr->price, value);
gnc_price_commit_edit (pr->price);
@ -1613,7 +1613,7 @@ update_price(XferDialog *xferData, PriceReq *pr)
}
static void
new_price(XferDialog *xferData, Timespec ts)
new_price(XferDialog *xferData, time64 time)
{
GNCPrice *price = NULL;
gnc_commodity *from = xferData->from_commodity;
@ -1637,7 +1637,7 @@ new_price(XferDialog *xferData, Timespec ts)
gnc_price_begin_edit (price);
gnc_price_set_commodity (price, from);
gnc_price_set_currency (price, to);
gnc_price_set_time (price, ts);
gnc_price_set_time64 (price, time);
gnc_price_set_source (price, xferData->price_source);
gnc_price_set_typestr (price, xferData->price_type);
gnc_price_set_value (price, value);
@ -1649,7 +1649,7 @@ new_price(XferDialog *xferData, Timespec ts)
}
static void
create_price(XferDialog *xferData, Timespec ts)
create_price(XferDialog *xferData, time64 time)
{
PriceReq pr;
@ -1664,7 +1664,7 @@ create_price(XferDialog *xferData, Timespec ts)
update_price(xferData, &pr);
return;
}
new_price (xferData, ts);
new_price (xferData, time);
}
void
@ -1674,7 +1674,7 @@ gnc_xfer_dialog_response_cb (GtkDialog *dialog, gint response, gpointer data)
Account *to_account;
Account *from_account;
gnc_numeric amount, to_amount;
Timespec ts;
time64 time;
GDate date;
g_return_if_fail (xferData != NULL);
@ -1718,7 +1718,7 @@ gnc_xfer_dialog_response_cb (GtkDialog *dialog, gint response, gpointer data)
}
g_date_clear (&date, 1);
gnc_date_edit_get_gdate (GNC_DATE_EDIT (xferData->date_entry), &date);
ts = gdate_to_timespec (date);
time = gdate_to_time64 (date);
if (!gnc_commodity_equiv(xferData->from_commodity, xferData->to_commodity))
{
@ -1748,12 +1748,12 @@ gnc_xfer_dialog_response_cb (GtkDialog *dialog, gint response, gpointer data)
*(xferData->exch_rate) = gnc_numeric_abs(price_value);
}
else
create_transaction (xferData, &ts, from_account, to_account,
create_transaction (xferData, time, from_account, to_account,
amount, to_amount);
/* try to save this to the pricedb */
if (xferData->pricedb && !gnc_commodity_equal (xferData->from_commodity,
xferData->to_commodity))
create_price(xferData, ts);
create_price(xferData, time);
/* Refresh everything */
gnc_resume_gui_refresh ();

View File

@ -184,13 +184,13 @@ gnc_date_edit_popdown(GNCDateEdit *gde)
static void
day_selected (GtkCalendar *calendar, GNCDateEdit *gde)
{
Timespec t;
time64 t;
guint year, month, day;
gde->in_selected_handler = TRUE;
gtk_calendar_get_date (calendar, &year, &month, &day);
/* GtkCalendar returns a 0-based month */
t = gnc_dmy2timespec (day, month + 1, year);
gnc_date_edit_set_time_ts (gde, t);
t = gnc_dmy2time64 (day, month + 1, year);
gnc_date_edit_set_time (gde, t);
gde->in_selected_handler = FALSE;
}
@ -809,12 +809,6 @@ gnc_date_edit_set_gdate (GNCDateEdit *gde, const GDate *date)
gnc_date_edit_set_time(gde, t);
}
void
gnc_date_edit_set_time_ts (GNCDateEdit *gde, Timespec the_time)
{
gnc_date_edit_set_time (gde, the_time.tv_sec);
}
/**
* gnc_date_edit_set_popup_range:
* @gde: The GNCDateEdit widget
@ -1033,13 +1027,6 @@ gnc_date_edit_new (time64 the_time, int show_time, int use_24_format)
| (use_24_format ? GNC_DATE_EDIT_24_HR : 0)));
}
GtkWidget *
gnc_date_edit_new_ts (Timespec the_time, int show_time, int use_24_format)
{
return gnc_date_edit_new (the_time.tv_sec, show_time, use_24_format);
}
/*
* Create a new GncDateEdit widget from a glade file. The widget
* generated is set to today's date, and will not show a time as part
@ -1193,16 +1180,6 @@ gnc_date_edit_get_gdate (GNCDateEdit *gde, GDate *date)
gnc_gdate_set_time64 (date, t);
}
Timespec
gnc_date_edit_get_date_ts (GNCDateEdit *gde)
{
Timespec ts = { 0, 0 };
ts.tv_sec = gnc_date_edit_get_date (gde);
return ts;
}
/**
* gnc_date_edit_get_date_end:
* @gde: The GNCDateEdit widget
@ -1224,16 +1201,6 @@ gnc_date_edit_get_date_end (GNCDateEdit *gde)
return gnc_mktime (&tm);
}
Timespec
gnc_date_edit_get_date_end_ts (GNCDateEdit *gde)
{
Timespec ts = { 0, 0 };
ts.tv_sec = gnc_date_edit_get_date_end (gde);
return ts;
}
/**
* gnc_date_edit_set_flags:
* @gde: The date editor widget whose flags should be changed.

View File

@ -93,8 +93,6 @@ GType gnc_date_edit_get_type (void);
GtkWidget *gnc_date_edit_new (time64 the_time,
int show_time, int use_24_format);
GtkWidget *gnc_date_edit_new_ts (Timespec the_time,
int show_time, int use_24_format);
/**
* Create a new GncDateEdit widget from a glade file. The widget
@ -121,16 +119,13 @@ GtkWidget *gnc_date_edit_new_flags (time64 the_time,
void gnc_date_edit_set_gdate (GNCDateEdit *gde, const GDate *date);
void gnc_date_edit_set_time (GNCDateEdit *gde, time64 the_time);
void gnc_date_edit_set_time_ts (GNCDateEdit *gde, Timespec the_time);
void gnc_date_edit_set_popup_range (GNCDateEdit *gde,
int low_hour, int up_hour);
int low_hour, int up_hour);
void gnc_date_edit_get_gdate (GNCDateEdit *gde, GDate *date);
time64 gnc_date_edit_get_date (GNCDateEdit *gde);
Timespec gnc_date_edit_get_date_ts (GNCDateEdit *gde);
time64 gnc_date_edit_get_date_end (GNCDateEdit *gde);
Timespec gnc_date_edit_get_date_end_ts (GNCDateEdit *gde);
time64 gnc_date_edit_get_date (GNCDateEdit *gde);
time64 gnc_date_edit_get_date_end (GNCDateEdit *gde);
void gnc_date_edit_set_flags (GNCDateEdit *gde,
GNCDateEditFlags flags);

View File

@ -1537,15 +1537,15 @@ static gboolean gtcsr_move_current_entry_updown(GncTreeViewSplitReg *view,
}
/* Special treatment if the equality doesn't hold if we access the
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. */
dates as time64. See the comment in gncEntrySetDateGDate() for the
reason: Some code used the time64 at noon for the EntryDate, other
code used the time64 at the start of day. */
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
/* Times are not equal, even though the GDates were equal? Then
we set the GDates again. This will force the times to be equal
as well. */
xaccTransSetDatePostedGDate(current_trans, d1);
xaccTransSetDatePostedGDate(target_trans, d2);

View File

@ -679,6 +679,8 @@ gnc_tree_model_price_get_value (GtkTreeModel *tree_model,
gnc_commodity_namespace *name_space;
gnc_commodity *commodity;
GNCPrice *price;
char datebuff[MAX_DATE_LENGTH + 1];
memset (datebuff, 0, sizeof(datebuff));
g_return_if_fail (GNC_IS_TREE_MODEL_PRICE (model));
g_return_if_fail (iter != NULL);
@ -767,8 +769,10 @@ gnc_tree_model_price_get_value (GtkTreeModel *tree_model,
g_value_set_string (value, gnc_commodity_get_printname (commodity));
break;
case GNC_TREE_MODEL_PRICE_COL_DATE:
qof_print_date_buff (datebuff, sizeof(datebuff),
gnc_price_get_time (price));
g_value_init (value, G_TYPE_STRING);
g_value_set_string (value, gnc_print_date (gnc_price_get_time (price)));
g_value_set_string (value, datebuff);
break;
case GNC_TREE_MODEL_PRICE_COL_SOURCE:
g_value_init (value, G_TYPE_STRING);

View File

@ -830,10 +830,11 @@ gnc_tree_model_split_reg_get_tooltip (GncTreeModelSplitReg *model, gint position
{
GncTreeModelSplitRegPrivate *priv;
Transaction *trans;
const gchar *date_text;
char date_text[MAX_DATE_LENGTH + 1];
const gchar *desc_text;
GList *node;
memset (date_text, 0, sizeof(date_text));
priv = model->priv;
node = g_list_nth (priv->full_tlist, position);
@ -848,8 +849,8 @@ gnc_tree_model_split_reg_get_tooltip (GncTreeModelSplitReg *model, gint position
return g_strconcat ("Blank Transaction", NULL);
else
{
Timespec ts = {xaccTransRetDatePosted (trans), 0};
date_text = gnc_print_date (ts);
time64 t = xaccTransRetDatePosted (trans);
qof_print_date_buff (date_text, sizeof(date_text), t);
desc_text = xaccTransGetDescription (trans);
model->current_trans = trans;
return g_strconcat (date_text, "\n", desc_text, NULL);

View File

@ -219,7 +219,7 @@ static gint
default_sort (GNCPrice *price_a, GNCPrice *price_b)
{
gnc_commodity *curr_a, *curr_b;
Timespec ts_a, ts_b;
time64 time_a, time_b;
gint result;
/* Primary sort (i.e. commodity name) handled by the tree structure. */
@ -237,9 +237,9 @@ default_sort (GNCPrice *price_a, GNCPrice *price_b)
if (result != 0) return result;
/* tertiary sort: time */
ts_a = gnc_price_get_time (price_a);
ts_b = gnc_price_get_time (price_b);
result = timespec_cmp (&ts_a, &ts_b);
time_a = gnc_price_get_time64 (price_a);
time_b = gnc_price_get_time64 (price_b);
result = time_a < time_b ? -1 : time_a > time_b ? 1 : 0;
if (result)
/* Reverse the result to present the most recent quote first. */
return -result;
@ -270,16 +270,16 @@ sort_by_date (GtkTreeModel *f_model,
gpointer user_data)
{
GNCPrice *price_a, *price_b;
Timespec ts_a, ts_b;
time64 time_a, time_b;
gboolean result;
if (!get_prices (f_model, f_iter_a, f_iter_b, &price_a, &price_b))
return sort_ns_or_cm (f_model, f_iter_a, f_iter_b);
/* sort by time first */
ts_a = gnc_price_get_time (price_a);
ts_b = gnc_price_get_time (price_b);
result = timespec_cmp (&ts_a, &ts_b);
time_a = gnc_price_get_time64 (price_a);
time_b = gnc_price_get_time64 (price_b);
result = time_a < time_b ? -1 : time_a > time_b ? 1 : 0;
if (result)
/* Reverse the result to present the most recent quote first. */
return -result;

View File

@ -1394,6 +1394,7 @@ gtv_sr_cdf0 (GtkTreeViewColumn *col, GtkCellRenderer *cell, GtkTreeModel *s_mode
gnc_numeric num = gnc_numeric_zero();
const gchar *s = "";
const gchar *row_color;
char datebuff[MAX_DATE_LENGTH + 1];
RowDepth depth;
gint *indices;
Account *anchor = view->priv->anchor;
@ -1462,6 +1463,7 @@ gtv_sr_cdf0 (GtkTreeViewColumn *col, GtkCellRenderer *cell, GtkTreeModel *s_mode
switch (viewcol) {
case COL_DATE:
/* Column is DATE */
memset (datebuff, 0, sizeof(datebuff));
if (is_split)
g_object_set (cell, "cell-background", "white", (gchar*)NULL);
@ -1474,65 +1476,60 @@ gtv_sr_cdf0 (GtkTreeViewColumn *col, GtkCellRenderer *cell, GtkTreeModel *s_mode
show_extra_dates = TRUE;
if (is_trow1) {
Timespec ts = {xaccTransRetDatePosted (trans),0};
time64 t = xaccTransRetDatePosted (trans);
//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);
s = gnc_print_date (ts);
if (t == 0)
t = gnc_time (NULL);
qof_print_date_buff (datebuff, sizeof(datebuff), t);
editable = TRUE;
}
else if (is_trow2 && show_extra_dates) {
Timespec ts = {xaccTransRetDateEntered (trans),0};
time64 t = xaccTransRetDateEntered (trans);
g_object_set (cell, "cell-background", YELLOWCELL, (gchar*)NULL);
//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);
s = gnc_print_date (ts);
if (t == 0)
t = gnc_time (NULL);
qof_print_date_buff (datebuff, sizeof(datebuff), t);
editable = FALSE;
}
else if (is_split && show_extra_dates) {
Timespec ts = {0,0};
time64 t = 0;
if (xaccSplitGetReconcile (split) == YREC)
{
xaccSplitGetDateReconciledTS (split, &ts);
t = xaccSplitGetDateReconciled (split);
//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)
if (t == 0)
{
ts.tv_sec = gnc_time (NULL);
t = gnc_time (NULL);
//xaccSplitSetDateReconciledTS (split, ts.tv_sec);
}//if
s = gnc_print_date (ts);
qof_print_date_buff (datebuff, sizeof(datebuff), 0);
}
else
s = "";
editable = FALSE;
}
else {
s = "";
editable = FALSE;
}
/* Is this a template */
if (is_template && is_trow1)
{
s = _(" Scheduled ");
strncpy (datebuff, _(" Scheduled "), sizeof(datebuff));
editable = FALSE;
}
else if (is_template && is_trow2 && show_extra_dates)
{
s = "";
editable = FALSE;
}
else if (is_template && is_split && show_extra_dates)
{
s = "";
editable = FALSE;
}
@ -1540,11 +1537,12 @@ gtv_sr_cdf0 (GtkTreeViewColumn *col, GtkCellRenderer *cell, GtkTreeModel *s_mode
/* This will remove the calander buttons if FALSE */
g_object_set (cell, "use_buttons", view->priv->show_calendar_buttons, NULL );
g_object_set (cell, "text", s, "editable", editable, NULL);
g_object_set (cell, "text", datebuff, "editable", editable, NULL);
break;
case COL_DUEDATE:
/* Column is DUE DATE */
memset (datebuff, 0, sizeof(datebuff));
if (is_split)
g_object_set (cell, "cell-background", "white", (gchar*)NULL);
@ -1552,18 +1550,17 @@ gtv_sr_cdf0 (GtkTreeViewColumn *col, GtkCellRenderer *cell, GtkTreeModel *s_mode
/* Only print the due date for invoice transactions */
if (type == TXN_TYPE_INVOICE)
{
Timespec ts = {xaccTransRetDateDue (trans), 0};
s = gnc_print_date (ts);
time64 t = xaccTransRetDateDue (trans);
qof_print_date_buff (datebuff, sizeof(datebuff), t);
editable = FALSE;
}
else {
s = "";
editable = FALSE;
}
}
editable = (read_only == TRUE) ? FALSE : editable;
g_object_set (cell, "text", s, "editable", editable, NULL);
g_object_set (cell, "text", datebuff, "editable", editable, NULL);
break;
case COL_NUMACT:

View File

@ -87,14 +87,14 @@ gnc_dialog_date_close_ok_cb (GtkWidget *widget, gpointer user_data)
}
if (ddc->post_date)
*(ddc->ts2) = gnc_date_edit_get_date_ts (GNC_DATE_EDIT (ddc->post_date));
ddc->ts2->tv_sec = gnc_date_edit_get_date (GNC_DATE_EDIT (ddc->post_date));
if (ddc->date)
{
if (ddc->terms)
ddc->ts->tv_sec = gncBillTermComputeDueDate (ddc->terms, ddc->ts2->tv_sec);
else
*(ddc->ts) = gnc_date_edit_get_date_ts (GNC_DATE_EDIT (ddc->date));
ddc->ts->tv_sec = gnc_date_edit_get_date (GNC_DATE_EDIT (ddc->date));
}
if (ddc->memo_entry && ddc->memo)
@ -146,7 +146,7 @@ gnc_dialog_date_close_parented (GtkWidget *parent, const char *message,
date_box = GTK_WIDGET(gtk_builder_get_object (builder, "date_box"));
ddc->date = gnc_date_edit_new (time(NULL), FALSE, FALSE);
gtk_box_pack_start (GTK_BOX(date_box), ddc->date, TRUE, TRUE, 0);
gnc_date_edit_set_time_ts (GNC_DATE_EDIT (ddc->date), *ts);
gnc_date_edit_set_time (GNC_DATE_EDIT (ddc->date), ts->tv_sec);
if (parent)
gtk_window_set_transient_for (GTK_WINDOW(ddc->dialog), GTK_WINDOW(parent));
@ -184,12 +184,12 @@ static void
post_date_changed_cb (GNCDateEdit *gde, gpointer d)
{
DialogDateClose *ddc = d;
Timespec post_date;
Timespec due_date = {0,0};
time64 post_date;
time64 due_date = 0;
post_date = gnc_date_edit_get_date_ts (gde);
due_date.tv_sec = gncBillTermComputeDueDate (ddc->terms, post_date.tv_sec);
gnc_date_edit_set_time_ts (GNC_DATE_EDIT (ddc->date), due_date);
post_date = gnc_date_edit_get_date (gde);
due_date = gncBillTermComputeDueDate (ddc->terms, post_date);
gnc_date_edit_set_time (GNC_DATE_EDIT (ddc->date), due_date);
}
gboolean
@ -278,7 +278,7 @@ gnc_dialog_dates_acct_question_parented (GtkWidget *parent, const char *message,
/* Set the post date widget */
gnc_date_edit_set_time_ts (GNC_DATE_EDIT (ddc->post_date), *post);
gnc_date_edit_set_time (GNC_DATE_EDIT (ddc->post_date), post->tv_sec);
/* Deal with the terms handling of the due date */
if (terms)
@ -289,7 +289,7 @@ gnc_dialog_dates_acct_question_parented (GtkWidget *parent, const char *message,
post_date_changed_cb (GNC_DATE_EDIT (ddc->post_date), ddc);
}
else
gnc_date_edit_set_time_ts (GNC_DATE_EDIT (ddc->date), *ddue);
gnc_date_edit_set_time (GNC_DATE_EDIT (ddc->date), ddue->tv_sec);
/* Setup the account widget */
fill_in_acct_info (ddc, set_default_acct);
@ -378,7 +378,7 @@ gnc_dialog_date_acct_parented (GtkWidget *parent, const char *message,
gtk_label_set_text (label, acct_label_message);
/* Set the date widget */
gnc_date_edit_set_time_ts (GNC_DATE_EDIT (ddc->date), *date);
gnc_date_edit_set_time (GNC_DATE_EDIT (ddc->date), date->tv_sec);
/* Setup the account widget */
fill_in_acct_info (ddc, FALSE);