Convert all time_t to time64: app-utils

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@22620 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
John Ralls 2012-12-01 22:44:41 +00:00
parent 3b1ad26e5f
commit 6716e3ac5b
12 changed files with 55 additions and 99 deletions

View File

@ -59,7 +59,14 @@
#define KEY_END_DATE "end_date"
#define KEY_END_PERIOD "end_period"
static time_t
static time64 gnc_accounting_period_start_time64 (GncAccountingPeriod which,
const GDate *fy_end,
const GDate *contains);
static time64 gnc_accounting_period_end_time64 (GncAccountingPeriod which,
const GDate *fy_end,
const GDate *contains);
static time64
lookup_start_date_option(const gchar *section,
const gchar *key_choice,
const gchar *key_absolute,
@ -67,7 +74,7 @@ lookup_start_date_option(const gchar *section,
GDate *fy_end)
{
gchar *choice;
time_t time;
time64 time;
int which;
choice = gnc_gconf_get_string(section, key_choice, NULL);
@ -78,7 +85,7 @@ lookup_start_date_option(const gchar *section,
else
{
which = gnc_gconf_get_int(section, key_relative, NULL);
time = gnc_accounting_period_start_timet(which, fy_end, NULL);
time = gnc_accounting_period_start_time64(which, fy_end, NULL);
}
g_free(choice);
/* we will need the balance of the last transaction before the start
@ -88,8 +95,7 @@ lookup_start_date_option(const gchar *section,
return time;
}
static time_t
static time64
lookup_end_date_option(const gchar *section,
const gchar *key_choice,
const gchar *key_absolute,
@ -97,19 +103,19 @@ lookup_end_date_option(const gchar *section,
GDate *fy_end)
{
gchar *choice;
time_t time;
time64 time;
int which;
choice = gnc_gconf_get_string(section, key_choice, NULL);
if (choice && strcmp(choice, "absolute") == 0)
{
time = gnc_gconf_get_int(section, key_absolute, NULL);
time = gnc_timet_get_day_end(time);
time = gnc_time64_get_day_end(time);
}
else
{
which = gnc_gconf_get_int(section, key_relative, NULL);
time = gnc_accounting_period_end_timet(which, fy_end, NULL);
time = gnc_accounting_period_end_time64(which, fy_end, NULL);
}
g_free(choice);
if (time == 0)
@ -133,10 +139,10 @@ get_fy_end(void)
return NULL;
}
time_t
time64
gnc_accounting_period_fiscal_start(void)
{
time_t t;
time64 t;
GDate *fy_end = get_fy_end();
t = lookup_start_date_option(GCONF_SECTION, KEY_START_CHOICE,
KEY_START_DATE, KEY_START_PERIOD, fy_end);
@ -145,10 +151,10 @@ gnc_accounting_period_fiscal_start(void)
return t;
}
time_t
time64
gnc_accounting_period_fiscal_end(void)
{
time_t t;
time64 t;
GDate *fy_end = get_fy_end();
t = lookup_end_date_option(GCONF_SECTION, KEY_END_CHOICE,
@ -173,8 +179,8 @@ gnc_accounting_period_start_gdate (GncAccountingPeriod which,
}
else
{
date = g_date_new();
g_date_set_time_t(date, time(NULL));
date = g_date_new ();
gnc_gdate_set_today (date);
}
switch (which)
@ -235,19 +241,19 @@ gnc_accounting_period_start_gdate (GncAccountingPeriod which,
return date;
}
time_t
gnc_accounting_period_start_timet (GncAccountingPeriod which,
static time64
gnc_accounting_period_start_time64 (GncAccountingPeriod which,
const GDate *fy_end,
const GDate *contains)
{
GDate *date;
time_t secs;
time64 secs;
date = gnc_accounting_period_start_gdate(which, fy_end, contains);
if (!date)
return 0;
secs = gnc_timet_get_day_start_gdate(date);
secs = gnc_time64_get_day_start_gdate(date);
g_date_free(date);
return secs;
}
@ -267,8 +273,8 @@ gnc_accounting_period_end_gdate (GncAccountingPeriod which,
}
else
{
date = g_date_new();
g_date_set_time_t(date, time(NULL));
date = g_date_new ();
gnc_gdate_set_today (date);
}
switch (which)
@ -330,22 +336,21 @@ gnc_accounting_period_end_gdate (GncAccountingPeriod which,
return date;
}
time_t
gnc_accounting_period_end_timet (GncAccountingPeriod which,
static time64
gnc_accounting_period_end_time64 (GncAccountingPeriod which,
const GDate *fy_end,
const GDate *contains)
{
GDate *date;
time_t secs;
time64 secs;
date = gnc_accounting_period_end_gdate(which, fy_end, contains);
if (!date)
return 0;
secs = gnc_timet_get_day_end_gdate(date);
secs = gnc_time64_get_day_end_gdate(date);
g_date_free(date);
return secs ;
}
/** @} */

View File

@ -45,7 +45,7 @@
#define GNC_ACCOUNTING_PERIOD_H
#include <glib.h>
#include <time.h>
#include <gnc-date.h>
/**
* This specifies a time interval.
@ -93,32 +93,6 @@ typedef enum
GDate *gnc_accounting_period_start_gdate (GncAccountingPeriod which,
const GDate *fy_end,
const GDate *contains);
/** This function returns the starting time for an accounting period.
* The time will be computed based upon the type of accounting
* interval requested, an optional fiscal year end value, and an
* optional time value.
*
* @param which An enum specifying the type of accounting period.
*
* @param fy_end This argument specifies the month and day of the
* fiscal year end. If the accounting period specified in the
* 'which' parameter is not a fiscal accounting period, this variable
* is ignored and may be NULL. Note: the year field of this argument
* is always ignored.
*
* @param contains This argument specifies the origin time value used
* by the calculations in this function. If this value is NULL, the
* origin will be the current time.
*
* @return The starting second of the specified time interval, based
* on a zero value of January 1st, 1970. */
time_t gnc_accounting_period_start_timet (GncAccountingPeriod which,
const GDate *fy_end,
const GDate *contains);
/** This function returns the ending date for an accounting period.
* The date will be computed based upon the type of accounting
* interval requested, an optional fiscal year end value, and an
@ -142,35 +116,10 @@ GDate *gnc_accounting_period_end_gdate (GncAccountingPeriod which,
const GDate *fy_end,
const GDate *contains);
/** This function returns the ending time for an accounting period.
* The time will be computed based upon the type of accounting
* interval requested, an optional fiscal year end value, and an
* optional time value.
*
* @param which An enum specifying the type of accounting period.
*
* @param fy_end This argument specifies the month and day of the
* fiscal year end. If the accounting period specified in the
* 'which' parameter is not a fiscal accounting period, this variable
* is ignored and may be NULL. Note: the year field of this argument
* is always ignored.
*
* @param contains This argument specifies the origin time value used
* by the calculations in this function. If this value is NULL, the
* origin will be the current time.
*
* @return The ending second of the specified time interval, based
* on a zero value of January 1st, 1970. */
time_t gnc_accounting_period_end_timet (GncAccountingPeriod which,
const GDate *fy_end,
const GDate *contains);
/* Get the fiscal accounting period from the preferences and return
the start and end times. */
time_t gnc_accounting_period_fiscal_start(void);
time_t gnc_accounting_period_fiscal_end(void);
time64 gnc_accounting_period_fiscal_start(void);
time64 gnc_accounting_period_fiscal_end(void);
/** @} */

View File

@ -48,6 +48,7 @@
#include "gnc-sx-instance-model.h"
#include "gnc-ui-util.h"
#include "qof.h"
#include <gnc-gdate-utils.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "gnc.app-utils.sx"
@ -426,7 +427,7 @@ gnc_sx_get_current_instances(void)
{
GDate now;
g_date_clear(&now, 1);
g_date_set_time_t(&now, time(NULL));
gnc_gdate_set_time64 (&now, gnc_time (NULL));
return gnc_sx_get_instances(&now, FALSE);
}

View File

@ -182,7 +182,7 @@ gnc_ui_account_get_print_report_balance (xaccGetBalanceInCurrencyFn fn,
gnc_numeric
gnc_ui_account_get_balance_as_of_date (Account *account,
time_t date,
time64 date,
gboolean include_children)
{
gnc_numeric balance;

View File

@ -108,8 +108,8 @@ gnc_ui_account_get_print_report_balance (xaccGetBalanceInCurrencyFn fn,
gboolean *negative);
gnc_numeric gnc_ui_account_get_balance_as_of_date (Account *account,
time_t date,
gboolean include_children);
time64 date,
gboolean include_children);
/********************************************************************
* Balance calculations related to owners

View File

@ -712,7 +712,7 @@ gnc_find_or_create_equity_account (Account *root,
gboolean
gnc_account_create_opening_balance (Account *account,
gnc_numeric balance,
time_t date,
time64 date,
QofBook *book)
{
Account *equity_account;

View File

@ -126,7 +126,7 @@ Account * gnc_find_or_create_equity_account (Account *root,
gnc_commodity *currency);
gboolean gnc_account_create_opening_balance (Account *account,
gnc_numeric balance,
time_t date,
time64 date,
QofBook *book);
/* Locale functions *************************************************/

View File

@ -1304,8 +1304,8 @@ gnc_detach_process (Process *proc, const gboolean kill_it)
}
time_t
gnc_parse_time_to_timet(const gchar *s, const gchar *format)
time64
gnc_parse_time_to_time64 (const gchar *s, const gchar *format)
{
struct tm tm;
@ -1314,7 +1314,7 @@ gnc_parse_time_to_timet(const gchar *s, const gchar *format)
if (!strptime(s, format, &tm))
return -1;
return mktime(&tm);
return gnc_mktime(&tm);
}
gchar *gnc_scm_to_locale_string(SCM scm_string)

View File

@ -153,4 +153,4 @@ void gnc_detach_process(Process *proc, const gboolean kill_it);
* @param format Format specification.
*
* @return The time in seconds since unix epoch, or -1 on error */
time_t gnc_parse_time_to_timet(const gchar *s, const gchar *format);
time64 gnc_parse_time_to_time64 (const gchar *s, const gchar *format);

View File

@ -2085,7 +2085,7 @@ gnc_option_db_lookup_multichoice_option(GNCOptionDB *odb,
* set_ab_value argument. If the default_value argument is NULL, *
* copies the current date to set_ab_value. Whatever value is *
* stored in set_ab_value is returned as an approximate (no *
* nanoseconds) time_t value. set_ab_value may be NULL, in which *
* nanoseconds) time64 value. set_ab_value may be NULL, in which *
* case only the return value can be used. If is_relative is *
* non-NULL, it is set to whether the date option is currently *
* storing a relative date. If it is, and set_rel_value *
@ -2099,9 +2099,9 @@ gnc_option_db_lookup_multichoice_option(GNCOptionDB *odb,
* set_ab_value - location to store absolute option value *
* set_rel_value - location to store relative option value *
* default - default value if not found *
* Return: time_t approximation of set_value *
* Return: time64 approximation of set_value *
\********************************************************************/
time_t
time64
gnc_option_db_lookup_date_option(GNCOptionDB *odb,
const char *section,
const char *name,
@ -2171,7 +2171,7 @@ gnc_option_db_lookup_date_option(GNCOptionDB *odb,
{
if (default_value == NULL)
{
set_ab_value->tv_sec = time (NULL);
set_ab_value->tv_sec = gnc_time (NULL);
set_ab_value->tv_nsec = 0;
}
else

View File

@ -182,7 +182,7 @@ char * gnc_option_db_lookup_multichoice_option(GNCOptionDB *odb,
const char *name,
const char *default_value);
time_t gnc_option_db_lookup_date_option(GNCOptionDB *odb,
time64 gnc_option_db_lookup_date_option(GNCOptionDB *odb,
const char *section,
const char *name,
gboolean *is_relative,

View File

@ -4,6 +4,7 @@
#include "SX-book.h"
#include "gnc-sx-instance-model.h"
#include "gnc-ui-util.h"
#include <gnc-gdate-utils.h>
#include "test-stuff.h"
#include "test-engine-stuff.h"
@ -16,7 +17,7 @@ test_basic()
SchedXaction *one_sx;
g_date_clear(&today, 1);
g_date_set_time_t(&today, time(NULL));
gnc_gdate_set_today (&today);
yesterday = today;
g_date_subtract_days(&yesterday, 1);
@ -86,14 +87,14 @@ test_once()
when = g_date_new();
g_date_clear(when, 1);
g_date_set_time_t(when, time(NULL));
gnc_gdate_set_today (when);
while (random_offset_within_one_year == 0)
random_offset_within_one_year = get_random_int_in_range(-365, 365);
g_date_add_days(when, random_offset_within_one_year);
end = g_date_new();
g_date_clear(end, 1);
g_date_set_time_t(end, time(NULL));
gnc_gdate_set_today (end);
g_date_add_years(end, 1);
lonely = add_once_sx("once", when);
@ -128,10 +129,10 @@ test_state_changes()
GncSxInstance *inst;
start = g_date_new();
g_date_set_time_t(start, time(NULL));
gnc_gdate_set_today (start);
end = g_date_new();
g_date_set_time_t(end, time(NULL));
gnc_gdate_set_today (end);
g_date_add_days(end, 3);
foo = add_daily_sx("foo", start, NULL, NULL);