Remove timespec2dmy.

It had only two uses and one was in a test. Replace those calls with
gnc_localtime_r.
This commit is contained in:
John Ralls 2018-07-31 16:19:39 -07:00
parent 6f89bd62b3
commit b60aef9d2a
4 changed files with 13 additions and 63 deletions

View File

@ -415,15 +415,6 @@ time64 gnc_iso8601_to_time64_gmt(const gchar *);
*/
gchar * gnc_timespec_to_iso8601_buff (Timespec ts, gchar * buff);
gchar * gnc_time64_to_iso8601_buff (time64, char * buff);
/** Set the proleptic Gregorian day, month, and year from a Timespec
* \param ts: input timespec
* \param day: output day, 1 - 31
* \param month: output month, 1 - 12
* \param year: output year, 0001 - 9999 CE
*/
void gnc_timespec2dmy (Timespec ts, gint *day, gint *month, gint *year);
// @}
/* ======================================================== */

View File

@ -753,15 +753,18 @@ gboolean gncBillTermIsDirty (const GncBillTerm *term)
*
*/
static void
compute_monthyear (const GncBillTerm *term, Timespec post_date,
compute_monthyear (const GncBillTerm *term, time64 post_date,
int *month, int *year)
{
int iday, imonth, iyear;
struct tm tm;
int cutoff = term->cutoff;
g_return_if_fail (term->type == GNC_TERM_TYPE_PROXIMO);
gnc_timespec2dmy (post_date, &iday, &imonth, &iyear);
gnc_localtime_r (&post_date, &tm);
iday = tm.tm_mday;
imonth = tm.tm_mon + 1;
iyear = tm.tm_year + 1;
if (cutoff <= 0)
cutoff += gnc_date_get_last_mday (imonth - 1, iyear);
@ -810,7 +813,7 @@ compute_time (const GncBillTerm *term, Timespec post_date, int days)
res.tv_sec += (SECS_PER_DAY * days);
break;
case GNC_TERM_TYPE_PROXIMO:
compute_monthyear (term, post_date, &month, &year);
compute_monthyear (term, post_date.tv_sec, &month, &year);
day = gnc_date_get_last_mday (month - 1, year);
if (days < day)
day = days;

View File

@ -82,15 +82,19 @@ static gboolean
check_conversion (const char * str, Timespec expected_ts)
{
Timespec ts;
struct tm tm;
int day, month, year;
GDate d1, d2;
ts = {gnc_iso8601_to_time64_gmt (str), 0};
// We test the conversion to GDate against the timespec2dmy
// We test the conversion to GDate against the gnc_localtime_r
// conversion, and also the conversion back to timespec and again
// to GDate so that it is still the original GDate
gnc_timespec2dmy(ts, &day, &month, &year);
gnc_localtime_r (&ts.tv_sec, &tm);
day = tm.tm_mday;
month = tm.tm_mon + 1;
year = tm.tm_year + 1900;
d1 = timespec_to_gdate(ts);
d2 = timespec_to_gdate(gdate_to_timespec(d1));
if ((g_date_compare(&d1, &d2) != 0)

View File

@ -1738,54 +1738,7 @@ test_gnc_timespec_to_iso8601_buff (FixtureA *f, gconstpointer pData)
g_assert_cmpstr (buff, ==, time_str);
g_free (time_str);
}
/* gnc_timespec2dmy
void
gnc_timespec2dmy (Timespec t, int *day, int *month, int *year)// C: 1 Local: 0:0:0
*/
static void
test_gnc_timespec2dmy (FixtureA *f, gconstpointer pData)
{
struct tm tm;
int day, r_day, mo, r_mo, yr, r_yr;
gnc_timespec2dmy (f->ts0, &r_day, &r_mo, &r_yr);
gnc_localtime_r (&f->ts0.tv_sec, &tm);
g_assert_cmpint (r_day, ==, tm.tm_mday);
g_assert_cmpint (r_mo, ==, tm.tm_mon + 1);
g_assert_cmpint (r_yr, ==, tm.tm_year + 1900);
gnc_timespec2dmy (f->ts1, &r_day, &r_mo, &r_yr);
gnc_localtime_r (&f->ts1.tv_sec, &tm);
g_assert_cmpint (r_day, ==, tm.tm_mday);
g_assert_cmpint (r_mo, ==, tm.tm_mon + 1);
g_assert_cmpint (r_yr, ==, tm.tm_year + 1900);
gnc_timespec2dmy (f->ts2, &r_day, &r_mo, &r_yr);
gnc_localtime_r (&f->ts2.tv_sec, &tm);
g_assert_cmpint (r_day, ==, tm.tm_mday);
g_assert_cmpint (r_mo, ==, tm.tm_mon + 1);
g_assert_cmpint (r_yr, ==, tm.tm_year + 1900);
gnc_timespec2dmy (f->ts3, &r_day, &r_mo, &r_yr);
gnc_localtime_r (&f->ts3.tv_sec, &tm);
g_assert_cmpint (r_day, ==, tm.tm_mday);
g_assert_cmpint (r_mo, ==, tm.tm_mon + 1);
g_assert_cmpint (r_yr, ==, tm.tm_year + 1900);
gnc_timespec2dmy (f->ts4, &r_day, &r_mo, &r_yr);
gnc_localtime_r (&f->ts4.tv_sec, &tm);
g_assert_cmpint (r_day, ==, tm.tm_mday);
g_assert_cmpint (r_mo, ==, tm.tm_mon + 1);
g_assert_cmpint (r_yr, ==, tm.tm_year + 1900);
gnc_timespec2dmy (f->ts5, &r_day, &r_mo, &r_yr);
gnc_localtime_r (&f->ts5.tv_sec, &tm);
g_assert_cmpint (r_day, ==, tm.tm_mday);
g_assert_cmpint (r_mo, ==, tm.tm_mon + 1);
g_assert_cmpint (r_yr, ==, tm.tm_year + 1900);
}
/* gnc_dmy2timespec_internal
static Timespec
gnc_dmy2timespec_internal (int day, int month, int year, gboolean start_of_day)// Local: 2:0:0
@ -2259,7 +2212,6 @@ test_suite_gnc_date (void)
GNC_TEST_ADD_FUNC (suitename, "gnc_date_timestamp", test_gnc_date_timestamp);
GNC_TEST_ADD (suitename, "gnc iso8601 to time64 gmt", FixtureA, NULL, setup, test_gnc_iso8601_to_time64_gmt, NULL);
GNC_TEST_ADD (suitename, "gnc timespec to iso8601 buff", FixtureA, NULL, setup, test_gnc_timespec_to_iso8601_buff, NULL);
GNC_TEST_ADD (suitename, "gnc timespec2dmy", FixtureA, NULL, setup, test_gnc_timespec2dmy, NULL);
// GNC_TEST_ADD_FUNC (suitename, "gnc dmy2timespec internal", test_gnc_dmy2timespec_internal);
GNC_TEST_ADD (suitename, "gnc dmy2timespec", FixtureB, NULL, setup_begin, test_gnc_dmy2timespec, NULL);