Convert all time_t to time64: import-export

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@22624 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
John Ralls
2012-12-01 22:45:23 +00:00
parent 2a62fb551a
commit d6f8fe4f5c
8 changed files with 66 additions and 73 deletions
@@ -51,7 +51,7 @@ gettrans_dates(GtkWidget *parent, Account *gnc_acc,
GWEN_TIME **from_date, GWEN_TIME **to_date)
{
Timespec last_timespec, until_timespec;
time_t now = time(NULL);
time64 now = gnc_time (NULL);
gboolean use_last_date = TRUE;
gboolean use_earliest_date = TRUE;
gboolean use_until_now = TRUE;
@@ -63,9 +63,9 @@ gettrans_dates(GtkWidget *parent, Account *gnc_acc,
if (last_timespec.tv_sec == 0)
{
use_last_date = FALSE;
timespecFromTime_t(&last_timespec, now);
timespecFromTime64 (&last_timespec, now);
}
timespecFromTime_t(&until_timespec, now);
timespecFromTime64 (&until_timespec, now);
/* Let the user choose the date range of retrieval */
if (!gnc_ab_enter_daterange(parent, NULL,
@@ -83,13 +83,13 @@ gettrans_dates(GtkWidget *parent, Account *gnc_acc,
{
if (use_last_date)
last_timespec = gnc_ab_get_account_trans_retrieval(gnc_acc);
*from_date = GWEN_Time_fromSeconds(timespecToTime_t(last_timespec));
*from_date = GWEN_Time_fromSeconds(timespecToTime64(last_timespec));
}
/* Now calculate to date */
if (use_until_now)
timespecFromTime_t(&until_timespec, now);
*to_date = GWEN_Time_fromSeconds(timespecToTime_t(until_timespec));
timespecFromTime64(&until_timespec, now);
*to_date = GWEN_Time_fromSeconds(timespecToTime64(until_timespec));
return TRUE;
}
@@ -145,7 +145,7 @@ gnc_ab_gettrans(GtkWidget *parent, Account *gnc_acc)
goto cleanup;
}
/* Use this as a local storage for the until_time below. */
timespecFromTime_t(&until_timespec, GWEN_Time_toTime_t(to_date));
timespecFromTime64(&until_timespec, GWEN_Time_toTime_t(to_date));
/* Get a GetTransactions job and enqueue it */
job = AB_JobGetTransactions_new(ab_acc);
+4 -5
View File
@@ -470,7 +470,7 @@ gnc_ab_trans_to_gnc(const AB_TRANSACTION *ab_trans, Account *gnc_acc)
Transaction *gnc_trans;
const gchar *fitid;
const GWEN_TIME *valuta_date;
time_t current_time;
time64 current_time;
const char *custref;
gchar *description;
Split *split;
@@ -496,8 +496,7 @@ gnc_ab_trans_to_gnc(const AB_TRANSACTION *ab_trans, Account *gnc_acc)
else
g_warning("transaction_cb: Oops, date 'valuta_date' was NULL");
current_time = time(NULL);
xaccTransSetDateEnteredSecs(gnc_trans, mktime(localtime(&current_time)));
xaccTransSetDateEnteredSecs(gnc_trans, gnc_time_utc (NULL));
/* Currency. We take simply the default currency of the gnucash account */
xaccTransSetCurrency(gnc_trans, xaccAccountGetCommodity(gnc_acc));
@@ -804,7 +803,7 @@ bal_accountinfo_cb(AB_IMEXPORTER_ACCOUNTINFO *element, gpointer user_data)
const AB_VALUE *booked_val = NULL, *noted_val = NULL;
gdouble booked_value, noted_value;
gnc_numeric value;
time_t booked_tt = 0;
time64 booked_tt = 0;
GtkWidget *dialog;
gboolean show_recn_window = FALSE;
@@ -873,7 +872,7 @@ bal_accountinfo_cb(AB_IMEXPORTER_ACCOUNTINFO *element, gpointer user_data)
{
/* No time found? Use today because the HBCI query asked for today's
* balance. */
booked_tt = gnc_timet_get_day_start(time(NULL));
booked_tt = gnc_time64_get_day_start(gnc_time(NULL));
}
booked_val = AB_Balance_GetValue(booked_bal);
if (booked_val)
@@ -480,19 +480,19 @@ csv_export_info_acct_type_cb (GtkWidget *w, gpointer user_data)
static void
get_filter_times (CsvExportInfo *info)
{
time_t time_val;
time64 time_val;
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(info->csvd.start_date_choose)))
{
time_val = gnc_date_edit_get_date(GNC_DATE_EDIT(info->csvd.start_date));
time_val = gnc_timet_get_day_start(time_val);
time_val = gnc_time64_get_day_start(time_val);
info->csvd.start_time = time_val;
}
else
{
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(info->csvd.start_date_today)))
{
info->csvd.start_time = gnc_timet_get_today_start();
info->csvd.start_time = gnc_time64_get_today_start();
}
else
{
@@ -503,18 +503,18 @@ get_filter_times (CsvExportInfo *info)
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(info->csvd.end_date_choose)))
{
time_val = gnc_date_edit_get_date(GNC_DATE_EDIT(info->csvd.end_date));
time_val = gnc_timet_get_day_end(time_val);
time_val = gnc_time64_get_day_end(time_val);
info->csvd.end_time = time_val;
}
else
{
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(info->csvd.start_date_today)))
{
info->csvd.end_time = gnc_timet_get_today_end();
info->csvd.end_time = gnc_time64_get_today_end();
}
else
{
info->csvd.end_time = time(NULL);
info->csvd.end_time = gnc_time (NULL);
}
}
}
@@ -613,13 +613,13 @@ csv_export_end_date_cb (GtkWidget *radio, gpointer user_data)
* a query and sorting by date. Since the truncated sort returns
* only the *last* search results, sort in decreasing order.
*******************************************************************/
static time_t
static time64
get_earliest_in_book (QofBook *book)
{
QofQuery *q;
GSList *p1, *p2;
GList *res;
time_t earliest;
time64 earliest;
q = qof_query_create_for(GNC_ID_SPLIT);
qof_query_set_max_results(q, 1);
@@ -644,7 +644,7 @@ get_earliest_in_book (QofBook *book)
else
{
/* If no results, we don't want to bomb totally */
earliest = time (0);
earliest = gnc_time (0);
}
qof_query_destroy (q);
@@ -856,7 +856,7 @@ csv_export_assistant_create (CsvExportInfo *info)
GtkWidget *box, *h_box;
GtkWidget *button;
GtkWidget *table, *hbox;
time_t start_time, end_time;
time64 start_time, end_time;
builder = gtk_builder_new();
gnc_builder_add_from_file (builder , "assistant-csv-export.glade", "CSV Export Assistant");
@@ -939,7 +939,7 @@ csv_export_assistant_create (CsvExportInfo *info)
/* Earliest and Latest in Book */
start_time = get_earliest_in_book (gnc_get_current_book());
end_time = time(NULL);
end_time = gnc_time (NULL);
info->csvd.start_time = start_time;
info->csvd.end_time = end_time;
@@ -955,20 +955,20 @@ csv_export_assistant_create (CsvExportInfo *info)
info->csvd.end_date_today = GTK_WIDGET(gtk_builder_get_object (builder, "end_date_today"));
/* Start date info */
info->csvd.start_date = gnc_date_edit_new (time (NULL), FALSE, FALSE);
info->csvd.start_date = gnc_date_edit_new (gnc_time (NULL), FALSE, FALSE);
hbox = GTK_WIDGET(gtk_builder_get_object (builder, "start_date_hbox"));
gtk_box_pack_start (GTK_BOX (hbox), info->csvd.start_date, TRUE, TRUE, 0);
gtk_widget_show (info->csvd.start_date);
gnc_date_edit_set_time(GNC_DATE_EDIT(info->csvd.start_date), start_time);
gnc_date_edit_set_time (GNC_DATE_EDIT(info->csvd.start_date), start_time);
g_signal_connect (G_OBJECT (info->csvd.start_date), "date-changed",
G_CALLBACK (csv_export_date_changed_cb), info);
/* End date info */
info->csvd.end_date = gnc_date_edit_new (time (NULL), FALSE, FALSE);
info->csvd.end_date = gnc_date_edit_new (gnc_time (NULL), FALSE, FALSE);
hbox = GTK_WIDGET(gtk_builder_get_object (builder, "end_date_hbox"));
gtk_box_pack_start (GTK_BOX (hbox), info->csvd.end_date, TRUE, TRUE, 0);
gtk_widget_show (info->csvd.end_date);
gnc_date_edit_set_time(GNC_DATE_EDIT(info->csvd.end_date), end_time);
gnc_date_edit_set_time (GNC_DATE_EDIT(info->csvd.end_date), end_time);
g_signal_connect (G_OBJECT (info->csvd.end_date), "date-changed",
G_CALLBACK (csv_export_date_changed_cb), info);
@@ -46,8 +46,8 @@ typedef struct
GtkWidget *end_date_today;
GtkWidget *end_date;
time_t start_time;
time_t end_time;
time64 start_time;
time64 end_time;
} CsvExportDate;
typedef struct
+25 -30
View File
@@ -14,7 +14,6 @@
#include "gnc-ui-util.h"
#include <string.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/stat.h>
@@ -23,10 +22,6 @@
#include <fcntl.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#ifndef HAVE_LOCALTIME_R
#include "localtime_r.h"
#endif
G_GNUC_UNUSED static QofLogModule log_module = GNC_MOD_IMPORT;
@@ -74,9 +69,9 @@ static StfParseOptions_t* default_parse_options(void)
* @param format An index specifying a format in date_format_user
* @return The parsed value of date_str on success or -1 on failure
*/
static time_t parse_date_with_year(const char* date_str, int format)
static time64 parse_date_with_year(const char* date_str, int format)
{
time_t rawtime; /* The integer time */
time64 rawtime; /* The integer time */
struct tm retvalue, test_retvalue; /* The time in a broken-down structure */
int i, j, mem_length, orig_year = -1, orig_month = -1, orig_day = -1;
@@ -135,8 +130,8 @@ static time_t parse_date_with_year(const char* date_str, int format)
/* Put some sane values in retvalue by using the current time for
* the non-year-month-day parts of the date. */
time(&rawtime);
localtime_r(&rawtime, &retvalue);
gnc_time (&rawtime);
gnc_localtime_r (&rawtime, &retvalue);
/* j traverses pmatch (index 0 contains the entire string, so we
* start at index 1 for the first meaningful match). */
@@ -156,7 +151,7 @@ static time_t parse_date_with_year(const char* date_str, int format)
date_segment[mem_length] = '\0';
/* Set the appropriate member of retvalue. Save the original
* values so that we can check if the change when we use mktime
* values so that we can check if the change when we use gnc_mktime
* below. */
switch (segment_type)
{
@@ -186,16 +181,16 @@ static time_t parse_date_with_year(const char* date_str, int format)
j++;
}
}
/* Convert back to an integer. If mktime leaves retvalue unchanged,
/* Convert back to an integer. If gnc_mktime leaves retvalue unchanged,
* everything is okay; otherwise, an error has occurred. */
/* We have to use a "test" date value to account for changes in
* daylight savings time, which can cause a date change with mktime
* daylight savings time, which can cause a date change with gnc_mktime
* near midnight, causing the code to incorrectly think a date is
* incorrect. */
test_retvalue = retvalue;
mktime(&test_retvalue);
gnc_mktime (&test_retvalue);
retvalue.tm_isdst = test_retvalue.tm_isdst;
rawtime = mktime(&retvalue);
rawtime = gnc_mktime (&retvalue);
if (retvalue.tm_mday == orig_day &&
retvalue.tm_mon == orig_month &&
retvalue.tm_year == orig_year)
@@ -215,9 +210,9 @@ static time_t parse_date_with_year(const char* date_str, int format)
* @param format An index specifying a format in date_format_user
* @return The parsed value of date_str on success or -1 on failure
*/
static time_t parse_date_without_year(const char* date_str, int format)
static time64 parse_date_without_year(const char* date_str, int format)
{
time_t rawtime; /* The integer time */
time64 rawtime; /* The integer time */
struct tm retvalue, test_retvalue; /* The time in a broken-down structure */
int i, j, mem_length, orig_year = -1, orig_month = -1, orig_day = -1;
@@ -245,8 +240,8 @@ static time_t parse_date_without_year(const char* date_str, int format)
/* Put some sane values in retvalue by using the current time for
* the non-year-month-day parts of the date. */
time(&rawtime);
localtime_r(&rawtime, &retvalue);
gnc_time (&rawtime);
gnc_localtime_r (&rawtime, &retvalue);
orig_year = retvalue.tm_year;
/* j traverses pmatch (index 0 contains the entire string, so we
@@ -268,7 +263,7 @@ static time_t parse_date_without_year(const char* date_str, int format)
date_segment[mem_length] = '\0';
/* Set the appropriate member of retvalue. Save the original
* values so that we can check if the change when we use mktime
* values so that we can check if the change when we use gnc_mktime
* below. */
switch (segment_type)
{
@@ -284,16 +279,16 @@ static time_t parse_date_without_year(const char* date_str, int format)
j++;
}
}
/* Convert back to an integer. If mktime leaves retvalue unchanged,
/* Convert back to an integer. If gnc_mktime leaves retvalue unchanged,
* everything is okay; otherwise, an error has occurred. */
/* We have to use a "test" date value to account for changes in
* daylight savings time, which can cause a date change with mktime
* daylight savings time, which can cause a date change with gnc_mktime
* near midnight, causing the code to incorrectly think a date is
* incorrect. */
test_retvalue = retvalue;
mktime(&test_retvalue);
gnc_mktime (&test_retvalue);
retvalue.tm_isdst = test_retvalue.tm_isdst;
rawtime = mktime(&retvalue);
rawtime = gnc_mktime (&retvalue);
if (retvalue.tm_mday == orig_day &&
retvalue.tm_mon == orig_month &&
retvalue.tm_year == orig_year)
@@ -314,7 +309,7 @@ static time_t parse_date_without_year(const char* date_str, int format)
* @param format An index specifying a format in date_format_user
* @return The parsed value of date_str on success or -1 on failure
*/
time_t parse_date(const char* date_str, int format)
time64 parse_date(const char* date_str, int format)
{
if (strchr(date_format_user[format], 'y'))
return parse_date_with_year(date_str, format);
@@ -625,7 +620,7 @@ static void trans_property_free(TransProperty* prop)
{
switch (prop->type)
{
/* The types for "Date" and "Balance" (time_t and gnc_numeric,
/* The types for "Date" and "Balance" (time64 and gnc_numeric,
* respectively) are typically not pointed to, we have to free
* them, unlike types like char* ("Description"). */
case GNC_CSV_DATE:
@@ -653,9 +648,9 @@ static gboolean trans_property_set(TransProperty* prop, char* str)
switch (prop->type)
{
case GNC_CSV_DATE:
prop->value = g_new(time_t, 1);
*((time_t*)(prop->value)) = parse_date(str, prop->list->date_format);
return *((time_t*)(prop->value)) != -1;
prop->value = g_new(time64, 1);
*((time64*)(prop->value)) = parse_date(str, prop->list->date_format);
return *((time64*)(prop->value)) != -1;
case GNC_CSV_DESCRIPTION:
case GNC_CSV_NOTES:
@@ -924,7 +919,7 @@ static GncCsvTransLine* trans_property_list_to_trans(TransPropertyList* list, gc
switch (prop->type)
{
case GNC_CSV_DATE:
xaccTransSetDatePostedSecs(trans_line->trans, *((time_t*)(prop->value)));
xaccTransSetDatePostedSecs(trans_line->trans, *((time64*)(prop->value)));
break;
case GNC_CSV_DESCRIPTION:
@@ -1202,7 +1197,7 @@ int gnc_csv_parse_to_trans(GncCsvParseData* parse_data, Account* account,
GncCsvTransLine* trans_line = (GncCsvTransLine*)transactions->data;
if (trans_line->balance_set)
{
time_t date = xaccTransGetDate(trans_line->trans);
time64 date = xaccTransGetDate(trans_line->trans);
/* Find what the balance should be by adding the offset to the actual balance. */
gnc_numeric existing_balance = gnc_numeric_add(balance_offset,
xaccAccountGetBalanceAsOfDate(account, date),
+1 -1
View File
@@ -130,6 +130,6 @@ int gnc_csv_parse(GncCsvParseData* parse_data, gboolean guessColTypes, GError**
int gnc_csv_parse_to_trans(GncCsvParseData* parse_data, Account* account, gboolean redo_errors);
time_t parse_date(const char* date_str, int format);
time64 parse_date(const char* date_str, int format);
#endif
+8 -8
View File
@@ -409,7 +409,7 @@ TransactionGetTokens(GNCImportTransInfo *info)
Transaction* transaction;
GList* tokens;
const char* text;
time_t transtime;
time64 transtime;
struct tm *tm_struct;
char local_day_of_week[16];
Split* split;
@@ -432,12 +432,12 @@ TransactionGetTokens(GNCImportTransInfo *info)
* it to day of week as a token
*/
transtime = xaccTransGetDate(transaction);
tm_struct = gmtime(&transtime);
tm_struct = gnc_gmtime(&transtime);
if (!qof_strftime(local_day_of_week, sizeof(local_day_of_week), "%A", tm_struct))
{
PERR("TransactionGetTokens: error, strftime failed\n");
}
gnc_tm_free (tm_struct);
/* we cannot add a locally allocated string to this array, dup it so
* it frees the same way the rest do
*/
@@ -599,7 +599,7 @@ static void split_find_match (GNCImportTransInfo * trans_info,
gint prob = 0;
gboolean update_proposed;
double downloaded_split_amount, match_split_amount;
time_t match_time, download_time;
time64 match_time, download_time;
int datediff_day;
Transaction *new_trans = gnc_import_TransInfo_get_trans (trans_info);
Split *new_trans_fsplit = gnc_import_TransInfo_get_fsplit (trans_info);
@@ -816,7 +816,7 @@ void gnc_import_find_split_matches(GNCImportTransInfo *trans_info,
*/
Account *importaccount =
xaccSplitGetAccount (gnc_import_TransInfo_get_fsplit (trans_info));
time_t download_time = xaccTransGetDate (gnc_import_TransInfo_get_trans (trans_info));
time64 download_time = xaccTransGetDate (gnc_import_TransInfo_get_trans (trans_info));
qof_query_set_book (query, gnc_get_current_book());
xaccQueryAddSingleAccountMatch (query, importaccount,
@@ -917,7 +917,7 @@ gnc_import_process_trans_item (GncImportMatchMap *matchmap,
xaccSplitSetReconcile(gnc_import_TransInfo_get_fsplit (trans_info), CREC);
/*Set reconcile date to today*/
xaccSplitSetDateReconciledSecs(gnc_import_TransInfo_get_fsplit (trans_info),
time(NULL));
gnc_time (NULL));
/* Done editing. */
xaccTransCommitEdit(gnc_import_TransInfo_get_trans (trans_info));
return TRUE;
@@ -981,7 +981,7 @@ gnc_import_process_trans_item (GncImportMatchMap *matchmap,
}
/* Set reconcile date to today */
xaccSplitSetDateReconciledSecs(selected_match->split, time(NULL));
xaccSplitSetDateReconciledSecs(selected_match->split, gnc_time (NULL));
/* Copy the online id to the reconciled transaction, so
the match will be remembered */
@@ -1037,7 +1037,7 @@ gnc_import_process_trans_item (GncImportMatchMap *matchmap,
(selected_match->split, CREC);
/* Set reconcile date to today */
xaccSplitSetDateReconciledSecs
(selected_match->split, time(NULL));
(selected_match->split, gnc_time (NULL));
/* Copy the online id to the reconciled transaction, so
the match will be remembered */
+4 -5
View File
@@ -313,7 +313,7 @@ static Account *gnc_ofx_new_account(const char* name,
int ofx_proc_transaction_cb(struct OfxTransactionData data, void * transaction_user_data)
{
char dest_string[255];
time_t current_time;
time64 current_time = gnc_time (NULL);
Account *account;
Account *investment_account = NULL;
Account *income_account = NULL;
@@ -375,11 +375,10 @@ int ofx_proc_transaction_cb(struct OfxTransactionData data, void * transaction_u
else
{
/* Uh no, no valid date. As a workaround use today's date */
xaccTransSetDatePostedSecs(transaction, mktime(localtime(&current_time)));
xaccTransSetDatePostedSecs(transaction, current_time);
}
current_time = time(NULL);
xaccTransSetDateEnteredSecs(transaction, mktime(localtime(&current_time)));
xaccTransSetDateEnteredSecs(transaction, current_time);
if (data.check_number_valid)
{
@@ -426,7 +425,7 @@ int ofx_proc_transaction_cb(struct OfxTransactionData data, void * transaction_u
if (data.date_funds_available_valid)
{
Timespec ts;
timespecFromTime_t(&ts, data.date_funds_available);
timespecFromTime64(&ts, data.date_funds_available);
gnc_timespec_to_iso8601_buff (ts, dest_string);
tmp = notes;
notes = g_strdup_printf("%s%s%s", tmp, "|Date funds available:", dest_string);