mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Consolidate all the functions that convert time values to be the
beginning, middle, or end of a day. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@8088 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
1b90a6d09c
commit
d417ccb041
15
ChangeLog
15
ChangeLog
@ -1,3 +1,18 @@
|
||||
2003-03-16 David Hampton <hampton@employees.org>
|
||||
|
||||
* src/business/business-ledger/gncEntryLedgerLoad.c:
|
||||
* src/engine/date.c:
|
||||
* src/engine/date.h:
|
||||
* src/gnome/gnc-split-reg.c:
|
||||
* src/gnome/window-register.c:
|
||||
* src/gnome-utils/gnc-date-edit.c:
|
||||
* src/register/ledger-core/gnc-ledger-display.c:
|
||||
* src/register/ledger-core/split-register-load.c:
|
||||
* src/register/ledger-core/split-register-util.c:
|
||||
* src/register/register-gnome/datecell-gnome.c:
|
||||
Consolidate all the functions that convert time values to be the
|
||||
beginning, middle, or end of a day.
|
||||
|
||||
2003-03-15 David Hampton <hampton@employees.org>
|
||||
|
||||
* src/gnome-utils/gnc-date-edit.c: Fix the keypress handlers so
|
||||
|
@ -409,20 +409,7 @@ void gnc_entry_ledger_load (GncEntryLedger *ledger, GList *entry_list)
|
||||
vcell_loc.virt_row++;
|
||||
|
||||
/* get the current time and reset the dividing row */
|
||||
{
|
||||
struct tm *tm;
|
||||
|
||||
present = time (NULL);
|
||||
|
||||
tm = localtime (&present);
|
||||
tm->tm_sec = 59;
|
||||
tm->tm_min = 59;
|
||||
tm->tm_hour = 23;
|
||||
tm->tm_isdst = -1;
|
||||
|
||||
present = mktime (tm);
|
||||
}
|
||||
|
||||
present = gnc_timet_get_today_end ();
|
||||
table->model->dividing_row = -1;
|
||||
cursor = gnc_table_layout_get_cursor (table->layout, "cursor");
|
||||
|
||||
|
@ -161,10 +161,7 @@ timespecCanonicalDayTime(Timespec t)
|
||||
time_t t_secs = t.tv_sec + (t.tv_nsec / NANOS_PER_SECOND);
|
||||
result = localtime(&t_secs);
|
||||
tm = *result;
|
||||
tm.tm_sec = 0;
|
||||
tm.tm_min = 0;
|
||||
tm.tm_hour = 12;
|
||||
tm.tm_isdst = -1;
|
||||
gnc_tm_set_day_middle(&tm);
|
||||
retval.tv_sec = mktime(&tm);
|
||||
retval.tv_nsec = 0;
|
||||
return retval;
|
||||
@ -375,11 +372,8 @@ printDate (char * buff, int day, int month, int year)
|
||||
tm_str.tm_mon = month - 1; /* tm_mon = 0 through 11 */
|
||||
tm_str.tm_year = year - 1900; /* this is what the standard
|
||||
* says, it's not a Y2K thing */
|
||||
tm_str.tm_hour = 0;
|
||||
tm_str.tm_min = 0;
|
||||
tm_str.tm_sec = 0;
|
||||
tm_str.tm_isdst = -1;
|
||||
|
||||
gnc_tm_set_day_start (&tm_str);
|
||||
strftime (buff, MAX_DATE_LENGTH, GNC_D_FMT, &tm_str);
|
||||
}
|
||||
break;
|
||||
@ -849,10 +843,7 @@ xaccDMYToSec (int day, int month, int year)
|
||||
stm.tm_year = year - 1900;
|
||||
stm.tm_mon = month - 1;
|
||||
stm.tm_mday = day;
|
||||
stm.tm_hour = 0;
|
||||
stm.tm_min = 0;
|
||||
stm.tm_sec = 0;
|
||||
stm.tm_isdst = -1;
|
||||
gnc_tm_set_day_start(&stm);
|
||||
|
||||
/* compute number of seconds */
|
||||
secs = mktime (&stm);
|
||||
@ -897,19 +888,9 @@ gnc_dmy2timespec_internal (int day, int month, int year, gboolean start_of_day)
|
||||
date.tm_mday = day;
|
||||
|
||||
if (start_of_day)
|
||||
{
|
||||
date.tm_hour = 0;
|
||||
date.tm_min = 0;
|
||||
date.tm_sec = 0;
|
||||
}
|
||||
gnc_tm_set_day_start(&date);
|
||||
else
|
||||
{
|
||||
date.tm_hour = 23;
|
||||
date.tm_min = 59;
|
||||
date.tm_sec = 59;
|
||||
}
|
||||
|
||||
date.tm_isdst = -1;
|
||||
gnc_tm_set_day_end(&date);
|
||||
|
||||
/* compute number of seconds */
|
||||
secs = mktime (&date);
|
||||
@ -968,5 +949,69 @@ timespecToTime_t (Timespec ts)
|
||||
return ts.tv_sec;
|
||||
}
|
||||
|
||||
void
|
||||
gnc_tm_get_day_start (struct tm *tm, time_t time_val)
|
||||
{
|
||||
/* Get the equivalent time structure */
|
||||
tm = localtime_r(&time_val, tm);
|
||||
gnc_tm_set_day_start(tm);
|
||||
}
|
||||
|
||||
void
|
||||
gnc_tm_get_day_end (struct tm *tm, time_t time_val)
|
||||
{
|
||||
/* Get the equivalent time structure */
|
||||
tm = localtime_r(&time_val, tm);
|
||||
gnc_tm_set_day_end(tm);
|
||||
}
|
||||
|
||||
time_t
|
||||
gnc_timet_get_day_start (time_t time_val)
|
||||
{
|
||||
struct tm tm;
|
||||
|
||||
gnc_tm_get_day_start(&tm, time_val);
|
||||
return mktime(&tm);
|
||||
}
|
||||
|
||||
time_t
|
||||
gnc_timet_get_day_end (time_t time_val)
|
||||
{
|
||||
struct tm tm;
|
||||
|
||||
gnc_tm_get_day_end(&tm, time_val);
|
||||
return mktime(&tm);
|
||||
}
|
||||
|
||||
void
|
||||
gnc_tm_get_today_start (struct tm *tm)
|
||||
{
|
||||
gnc_tm_get_day_start(tm, time(NULL));
|
||||
}
|
||||
|
||||
void
|
||||
gnc_tm_get_today_end (struct tm *tm)
|
||||
{
|
||||
gnc_tm_get_day_end(tm, time(NULL));
|
||||
}
|
||||
|
||||
time_t
|
||||
gnc_timet_get_today_start (void)
|
||||
{
|
||||
struct tm tm;
|
||||
|
||||
gnc_tm_get_day_start(&tm, time(NULL));
|
||||
return mktime(&tm);
|
||||
}
|
||||
|
||||
time_t
|
||||
gnc_timet_get_today_end (void)
|
||||
{
|
||||
struct tm tm;
|
||||
|
||||
gnc_tm_get_day_end(&tm, time(NULL));
|
||||
return mktime(&tm);
|
||||
}
|
||||
|
||||
/********************** END OF FILE *********************************\
|
||||
\********************************************************************/
|
||||
|
@ -28,6 +28,14 @@
|
||||
* If a file-io thing needs date handling, it should do it itself,
|
||||
* instead of depending on the routines here. */
|
||||
|
||||
/** @addtogroup Date
|
||||
@{ */
|
||||
/** @file date.h
|
||||
@brief Date handling routines
|
||||
@author Copyright (C) 1997 Robin D. Clark
|
||||
@author Copyright (C) 1999,1999,2000 Linas Vepstas <linas@linas.org>
|
||||
*/
|
||||
|
||||
#ifndef XACC_DATE_H
|
||||
#define XACC_DATE_H
|
||||
|
||||
@ -237,4 +245,87 @@ char * gnc_timespec_to_iso8601_buff (Timespec ts, char * buff);
|
||||
*/
|
||||
long int gnc_timezone (struct tm *tm);
|
||||
|
||||
|
||||
/** @name Date Start/End Adjustment routines
|
||||
* Given a time value, adjust it to be the beginning or end of that day.
|
||||
*/
|
||||
/** @{ */
|
||||
/** The gnc_tm_set_day_start() inline routine will set the appropriate
|
||||
* fields in the struct tm to indicate the first second of that day.
|
||||
* This routine assumes that the contents of the data structure is
|
||||
* already in normalized form. */
|
||||
static inline
|
||||
void gnc_tm_set_day_start (struct tm *tm)
|
||||
{
|
||||
/* First second of the day */
|
||||
tm->tm_hour = 0;
|
||||
tm->tm_min = 0;
|
||||
tm->tm_sec = 0;
|
||||
tm->tm_isdst = -1;
|
||||
}
|
||||
|
||||
/** The gnc_tm_set_day_start() inline routine will set the appropriate
|
||||
* fields in the struct tm to indicate noon of that day. This
|
||||
* routine assumes that the contents of the data structure is already
|
||||
* in normalized form.*/
|
||||
static inline
|
||||
void gnc_tm_set_day_middle (struct tm *tm)
|
||||
{
|
||||
/* First second of the day */
|
||||
tm->tm_hour = 12;
|
||||
tm->tm_min = 0;
|
||||
tm->tm_sec = 0;
|
||||
tm->tm_isdst = -1;
|
||||
}
|
||||
|
||||
/** The gnc_tm_set_day_start() inline routine will set the appropriate
|
||||
* fields in the struct tm to indicate the last second of that day.
|
||||
* This routine assumes that the contents of the data structure is
|
||||
* already in normalized form.*/
|
||||
static inline
|
||||
void gnc_tm_set_day_end (struct tm *tm)
|
||||
{
|
||||
/* Last second of the day */
|
||||
tm->tm_hour = 23;
|
||||
tm->tm_min = 59;
|
||||
tm->tm_sec = 59;
|
||||
tm->tm_isdst = -1;
|
||||
}
|
||||
|
||||
/** The gnc_tm_get_day_start() routine will convert the given time in
|
||||
* seconds to the struct tm format, and then adjust it to the
|
||||
* first second of that day. */
|
||||
void gnc_tm_get_day_start(struct tm *tm, time_t time_val);
|
||||
|
||||
/** The gnc_tm_get_day_end() routine will convert the given time in
|
||||
* seconds to the struct tm format, and then adjust it to the
|
||||
* last second of that day. */
|
||||
void gnc_tm_get_day_end(struct tm *tm, time_t time_val);
|
||||
|
||||
/** The gnc_timet_get_day_start() routine will take the given time in
|
||||
* seconds and first it to the last second of that day. */
|
||||
time_t gnc_timet_get_day_start(time_t time_val);
|
||||
|
||||
/** The gnc_timet_get_day_end() routine will take the given time in
|
||||
* seconds and adjust it to the last second of that day. */
|
||||
time_t gnc_timet_get_day_end(time_t time_val);
|
||||
|
||||
/** The gnc_tm_get_today_start() routine takes a pointer to a struct
|
||||
* tm and fills it in with the first second of the today. */
|
||||
void gnc_tm_get_today_start(struct tm *tm);
|
||||
|
||||
/** The gnc_tm_get_today_end() routine takes a pointer to a struct
|
||||
* tm and fills it in with the last second of the today. */
|
||||
void gnc_tm_get_today_end(struct tm *tm);
|
||||
|
||||
/** The gnc_timet_get_today_start() routine returns a time_t value
|
||||
* corresponding to the first second of today. */
|
||||
time_t gnc_timet_get_today_start(void);
|
||||
|
||||
/** The gnc_timet_get_today_end() routine returns a time_t value
|
||||
* corresponding to the last second of today. */
|
||||
time_t gnc_timet_get_today_end(void);
|
||||
/** @} */
|
||||
|
||||
#endif /* XACC_DATE_H */
|
||||
/** @} */
|
||||
|
@ -252,21 +252,10 @@ select_clicked (GtkWidget *widget, GNCDateEdit *gde)
|
||||
if (mtm.tm_year >= 1900)
|
||||
mtm.tm_year -= 1900;
|
||||
|
||||
mtm.tm_sec = 0;
|
||||
mtm.tm_min = 0;
|
||||
mtm.tm_hour = 0;
|
||||
mtm.tm_isdst = -1;
|
||||
|
||||
gnc_tm_set_day_start(&mtm);
|
||||
if (mktime (&mtm) == -1)
|
||||
{
|
||||
time_t secs = time (NULL);
|
||||
|
||||
mtm = *localtime (&secs);
|
||||
mtm.tm_sec = 0;
|
||||
mtm.tm_min = 0;
|
||||
mtm.tm_hour = 0;
|
||||
mtm.tm_isdst = -1;
|
||||
|
||||
gnc_tm_get_today_start (&mtm);
|
||||
gnc_date_edit_set_time (gde, mktime (&mtm));
|
||||
}
|
||||
|
||||
@ -549,16 +538,7 @@ date_accel_key_press(GtkWidget *widget, GdkEventKey *event, gpointer data)
|
||||
return FALSE;
|
||||
|
||||
if (mktime (&tm) == -1)
|
||||
{
|
||||
time_t secs = time (NULL);
|
||||
|
||||
tm = *localtime (&secs);
|
||||
tm.tm_sec = 0;
|
||||
tm.tm_min = 0;
|
||||
tm.tm_hour = 0;
|
||||
tm.tm_isdst = -1;
|
||||
}
|
||||
|
||||
gnc_tm_get_today_start (&tm);
|
||||
gnc_date_edit_set_time (gde, mktime (&tm));
|
||||
|
||||
gtk_calendar_select_day (GTK_CALENDAR (gde->calendar), 1);
|
||||
@ -796,9 +776,7 @@ gnc_date_edit_get_date_internal (GNCDateEdit *gde)
|
||||
}
|
||||
else
|
||||
{
|
||||
tm.tm_hour = 0;
|
||||
tm.tm_min = 0;
|
||||
tm.tm_sec = 0;
|
||||
gnc_tm_set_day_start(&tm);
|
||||
}
|
||||
|
||||
tm.tm_isdst = -1;
|
||||
@ -823,16 +801,7 @@ gnc_date_edit_get_date (GNCDateEdit *gde)
|
||||
tm = gnc_date_edit_get_date_internal (gde);
|
||||
|
||||
if (mktime (&tm) == -1)
|
||||
{
|
||||
time_t secs = time (NULL);
|
||||
|
||||
tm = *localtime (&secs);
|
||||
tm.tm_sec = 0;
|
||||
tm.tm_min = 0;
|
||||
tm.tm_hour = 0;
|
||||
tm.tm_isdst = -1;
|
||||
}
|
||||
|
||||
return gnc_timet_get_today_start();
|
||||
return mktime (&tm);
|
||||
}
|
||||
|
||||
@ -862,22 +831,10 @@ gnc_date_edit_get_date_end (GNCDateEdit *gde)
|
||||
g_return_val_if_fail (GNC_IS_DATE_EDIT (gde), 0);
|
||||
|
||||
tm = gnc_date_edit_get_date_internal (gde);
|
||||
|
||||
tm.tm_hour = 23;
|
||||
tm.tm_min = 59;
|
||||
tm.tm_sec = 59;
|
||||
gnc_tm_set_day_end(&tm);
|
||||
|
||||
if (mktime (&tm) == -1)
|
||||
{
|
||||
time_t secs = time (NULL);
|
||||
|
||||
tm = *localtime (&secs);
|
||||
tm.tm_sec = 23;
|
||||
tm.tm_min = 59;
|
||||
tm.tm_hour = 59;
|
||||
tm.tm_isdst = -1;
|
||||
}
|
||||
|
||||
return gnc_timet_get_today_end();
|
||||
return mktime (&tm);
|
||||
}
|
||||
|
||||
|
@ -2077,19 +2077,11 @@ gsr_account_present_balance (Account *account)
|
||||
GList *list;
|
||||
GList *node;
|
||||
time_t today;
|
||||
struct tm *tm;
|
||||
|
||||
if (!account)
|
||||
return gnc_numeric_zero ();
|
||||
|
||||
today = time (NULL);
|
||||
tm = localtime (&today);
|
||||
tm->tm_hour = 23;
|
||||
tm->tm_min = 59;
|
||||
tm->tm_sec = 59;
|
||||
tm->tm_isdst = -1;
|
||||
today = mktime (tm);
|
||||
|
||||
today = gnc_timet_get_today_end();
|
||||
list = xaccAccountGetSplitList (account);
|
||||
for (node = g_list_last (list); node; node = node->prev)
|
||||
{
|
||||
@ -2113,21 +2105,13 @@ gsr_account_projectedminimum_balance (Account *account)
|
||||
GList *list;
|
||||
GList *node;
|
||||
time_t today;
|
||||
struct tm *tm;
|
||||
gnc_numeric lowest = gnc_numeric_zero ();
|
||||
int seen_a_transaction = 0;
|
||||
|
||||
if (!account)
|
||||
return gnc_numeric_zero ();
|
||||
|
||||
today = time (NULL);
|
||||
tm = localtime (&today);
|
||||
tm->tm_hour = 23;
|
||||
tm->tm_min = 59;
|
||||
tm->tm_sec = 59;
|
||||
tm->tm_isdst = -1;
|
||||
today = mktime (tm);
|
||||
|
||||
today = gnc_timet_get_today_end();
|
||||
list = xaccAccountGetSplitList (account);
|
||||
for (node = g_list_last (list); node; node = node->prev)
|
||||
{
|
||||
|
@ -266,38 +266,6 @@ gnc_register_raise (RegWindow *regData)
|
||||
gtk_window_present( GTK_WINDOW(regData->window) );
|
||||
}
|
||||
|
||||
static time_t
|
||||
gnc_register_min_day_time(time_t time_val)
|
||||
{
|
||||
struct tm *time_struct;
|
||||
|
||||
/* Get the equivalent time structure */
|
||||
time_struct = localtime(&time_val);
|
||||
|
||||
/* First second of the day */
|
||||
time_struct->tm_sec = 0;
|
||||
time_struct->tm_min = 0;
|
||||
time_struct->tm_hour = 0;
|
||||
|
||||
return mktime(time_struct);
|
||||
}
|
||||
|
||||
static time_t
|
||||
gnc_register_max_day_time(time_t time_val)
|
||||
{
|
||||
struct tm *time_struct;
|
||||
|
||||
/* Get the equivalent time structure */
|
||||
time_struct = localtime(&time_val);
|
||||
|
||||
/* Last second of the day */
|
||||
time_struct->tm_sec = 59;
|
||||
time_struct->tm_min = 59;
|
||||
time_struct->tm_hour = 23;
|
||||
|
||||
return mktime(time_struct);
|
||||
}
|
||||
|
||||
static void
|
||||
gnc_date_range_set_sensitivities(RegWindow *regData)
|
||||
{
|
||||
@ -445,7 +413,7 @@ gnc_register_set_date_range(RegWindow *regData)
|
||||
time_t start;
|
||||
|
||||
start = gnc_date_edit_get_date(GNC_DATE_EDIT(regDateData->start_date));
|
||||
start = gnc_register_min_day_time(start);
|
||||
start = gnc_timet_get_day_start(start);
|
||||
|
||||
xaccQueryAddDateMatchTT(query,
|
||||
TRUE, start,
|
||||
@ -459,7 +427,7 @@ gnc_register_set_date_range(RegWindow *regData)
|
||||
time_t end;
|
||||
|
||||
end = gnc_date_edit_get_date(GNC_DATE_EDIT(regDateData->end_date));
|
||||
end = gnc_register_max_day_time(end);
|
||||
end = gnc_timet_get_day_end(end);
|
||||
|
||||
xaccQueryAddDateMatchTT(query,
|
||||
FALSE, 0,
|
||||
|
@ -418,7 +418,7 @@ gnc_ledger_display_gl (void)
|
||||
{
|
||||
Query *query;
|
||||
time_t start;
|
||||
struct tm *tm;
|
||||
struct tm tm;
|
||||
|
||||
query = xaccMallocQuery ();
|
||||
|
||||
@ -442,14 +442,9 @@ gnc_ledger_display_gl (void)
|
||||
tAG = NULL;
|
||||
}
|
||||
|
||||
start = time (NULL);
|
||||
tm = localtime (&start);
|
||||
tm->tm_mon--;
|
||||
tm->tm_hour = 0;
|
||||
tm->tm_min = 0;
|
||||
tm->tm_sec = 0;
|
||||
tm->tm_isdst = -1;
|
||||
start = mktime (tm);
|
||||
gnc_tm_get_today_start(&tm);
|
||||
tm.tm_mon--; /* Default the register to the last month's worth of transactions. */
|
||||
start = mktime (&tm);
|
||||
xaccQueryAddDateMatchTT (query,
|
||||
TRUE, start,
|
||||
FALSE, 0,
|
||||
|
@ -275,20 +275,7 @@ gnc_split_register_load (SplitRegister *reg, GList * slist,
|
||||
vcell_loc.virt_row++;
|
||||
|
||||
/* get the current time and reset the dividing row */
|
||||
{
|
||||
struct tm *tm;
|
||||
|
||||
present = time (NULL);
|
||||
|
||||
tm = localtime (&present);
|
||||
tm->tm_sec = 59;
|
||||
tm->tm_min = 59;
|
||||
tm->tm_hour = 23;
|
||||
tm->tm_isdst = -1;
|
||||
|
||||
present = mktime (tm);
|
||||
}
|
||||
|
||||
present = gnc_timet_get_today_end ();
|
||||
if (info->first_pass)
|
||||
{
|
||||
if (default_account)
|
||||
|
@ -34,24 +34,6 @@
|
||||
static short module = MOD_LEDGER;
|
||||
|
||||
|
||||
static time_t
|
||||
gnc_get_today_midnight (void)
|
||||
{
|
||||
time_t present;
|
||||
struct tm tm;
|
||||
|
||||
present = time (NULL);
|
||||
|
||||
tm = *localtime (&present);
|
||||
|
||||
tm.tm_sec = 0;
|
||||
tm.tm_min = 0;
|
||||
tm.tm_hour = 0;
|
||||
tm.tm_isdst = -1;
|
||||
|
||||
return mktime (&tm);
|
||||
}
|
||||
|
||||
/* The routines below create, access, and destroy the SRInfo structure
|
||||
* used by SplitLedger routines to store data for a particular register.
|
||||
* This is the only code that should access the user_data member of a
|
||||
@ -72,7 +54,7 @@ gnc_split_register_init_info (SplitRegister *reg)
|
||||
info->default_account = *xaccGUIDNULL ();
|
||||
info->template_account = *xaccGUIDNULL ();
|
||||
|
||||
info->last_date_entered = gnc_get_today_midnight ();
|
||||
info->last_date_entered = gnc_timet_get_today_start ();
|
||||
|
||||
info->first_pass = TRUE;
|
||||
info->full_refresh = TRUE;
|
||||
|
@ -104,23 +104,10 @@ gnc_parse_date (struct tm *parsed, const char * datestr)
|
||||
parsed->tm_mday = day;
|
||||
parsed->tm_mon = month - 1;
|
||||
parsed->tm_year = year - 1900;
|
||||
parsed->tm_sec = 0;
|
||||
parsed->tm_min = 0;
|
||||
parsed->tm_hour = 0;
|
||||
parsed->tm_isdst = -1;
|
||||
|
||||
gnc_tm_set_day_start(parsed);
|
||||
if (mktime (parsed) == -1)
|
||||
{
|
||||
time_t secs = time (NULL);
|
||||
|
||||
*parsed = *localtime (&secs);
|
||||
|
||||
parsed->tm_sec = 0;
|
||||
parsed->tm_min = 0;
|
||||
parsed->tm_hour = 0;
|
||||
parsed->tm_isdst = -1;
|
||||
}
|
||||
|
||||
gnc_tm_get_today_start (parsed);
|
||||
mktime (parsed);
|
||||
}
|
||||
|
||||
@ -351,11 +338,8 @@ gnc_date_cell_set_value (DateCell *cell, int day, int mon, int year)
|
||||
dada.tm_mday = day;
|
||||
dada.tm_mon = mon - 1;
|
||||
dada.tm_year = year - 1900;
|
||||
dada.tm_sec = 0;
|
||||
dada.tm_min = 0;
|
||||
dada.tm_hour = 0;
|
||||
dada.tm_isdst = -1;
|
||||
|
||||
gnc_tm_set_day_start(&dada);
|
||||
mktime (&dada);
|
||||
|
||||
box->date.tm_mday = dada.tm_mday;
|
||||
|
Loading…
Reference in New Issue
Block a user