Introduce and use gnc_time64_get_day_neutral

This function complements gnc_time64_get_day_begin/end. There was
time64CanonicalDayTime but this returned noon of the given day, where we
want 10:59am in most cases. I haven't changed time64CanonicalDayTime
directly as that may break assumptions in other parts of the code.
Instead I have created a new function that can be gradually introduced.
This commit is contained in:
Geert Janssens 2018-11-20 21:12:32 +01:00
parent 11af81b51b
commit 13f6c4d6d7
2 changed files with 39 additions and 1 deletions

View File

@ -1243,6 +1243,15 @@ gnc_tm_get_day_start (struct tm *tm, time64 time_val)
gnc_tm_set_day_start(tm);
}
static void
gnc_tm_get_day_neutral (struct tm *tm, time64 time_val)
{
/* Get the equivalent time structure */
if (!gnc_localtime_r(&time_val, tm))
return;
gnc_tm_set_day_neutral(tm);
}
static void
gnc_tm_get_day_end (struct tm *tm, time64 time_val)
{
@ -1263,6 +1272,17 @@ gnc_time64_get_day_start (time64 time_val)
return new_time;
}
time64
gnc_time64_get_day_neutral (time64 time_val)
{
struct tm tm;
time64 new_time;
gnc_tm_get_day_neutral(&tm, time_val);
new_time = gnc_mktime(&tm);
return new_time;
}
time64
gnc_time64_get_day_end (time64 time_val)
{

View File

@ -524,6 +524,20 @@ void gnc_tm_set_day_start (struct tm *tm)
tm->tm_sec = 0;
}
/** The gnc_tm_set_day_neutral() inline routine will set the appropriate
* fields in the struct tm to indicate 10:59am 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_neutral (struct tm *tm)
{
/* First second of the day */
g_return_if_fail (tm != NULL);
tm->tm_hour = 10;
tm->tm_min = 59;
tm->tm_sec = 0;
}
/** The gnc_tm_set_day_middle() 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
@ -553,9 +567,13 @@ void gnc_tm_set_day_end (struct tm *tm)
}
/** The gnc_time64_get_day_start() routine will take the given time in
* seconds and adjust it to the last second of that day. */
* seconds and adjust it to the first second of that day. */
time64 gnc_time64_get_day_start(time64 time_val);
/** The gnc_time64_get_day_netural() routine will take the given time in
* seconds and adjust it to 10:59am of that day. */
time64 gnc_time64_get_day_neutral(time64 time_val);
/** The gnc_time64_get_day_end() routine will take the given time in
* seconds and adjust it to the last second of that day. */
time64 gnc_time64_get_day_end(time64 time_val);