Removing timspec from some xml parsing

And several other sprawling references that are connected in one
way or another.
This commit is contained in:
lmat
2017-12-29 13:52:45 -05:00
committed by Christopher Lam
parent 7390396af9
commit f77369bb96
22 changed files with 131 additions and 195 deletions

View File

@@ -2766,7 +2766,7 @@ xaccTransGetVoidTime(const Transaction *tr)
if (G_VALUE_HOLDS_STRING (&v))
s = g_value_get_string (&v);
if (s)
return gnc_iso8601_to_timespec_gmt (s).tv_sec;
return gnc_iso8601_to_time64_gmt (s);
return void_time;
}

View File

@@ -1198,25 +1198,25 @@ gnc_date_timestamp (void)
*/
#define ISO_DATE_FORMAT "%d-%d-%d %d:%d:%lf%s"
Timespec
gnc_iso8601_to_timespec_gmt(const char *cstr)
time64
gnc_iso8601_to_time64_gmt(const char *cstr)
{
time64 time;
if (!cstr) return {0, 0};
if (!cstr) return 0;
try
{
GncDateTime gncdt(cstr);
return {static_cast<time64>(gncdt), 0};
return static_cast<time64>(gncdt);
}
catch(std::logic_error& err)
{
PWARN("Error processing %s: %s", cstr, err.what());
return {0, 0};
return 0;
}
catch(std::runtime_error& err)
{
PWARN("Error processing time64 %s: %s", cstr, err.what());
return {0, 0};
return 0;
}
}

View File

@@ -392,7 +392,7 @@ Timespec gnc_dmy2timespec_neutral (gint day, gint month, gint year);
* XXX Caution: this routine does not handle strings that specify
* times before January 1 1970.
*/
Timespec gnc_iso8601_to_timespec_gmt(const gchar *);
time64 gnc_iso8601_to_time64_gmt(const gchar *);
/** The gnc_timespec_to_iso8601_buff() routine takes the input
* UTC Timespec value and prints it as an ISO-8601 style string.

View File

@@ -227,6 +227,15 @@ get_random_glist_depth (gint depth)
/* ========================================================== */
/* Time/Date, GncGUID data stuff */
time64
get_random_time (void)
{
time64 ret {0};
while (ret <= 0)
ret = rand();
return ret;
}
Timespec*
get_random_timespec(void)
{

View File

@@ -46,6 +46,7 @@ typedef struct KvpFrameImpl KvpFrame;
#define __KVP_FRAME
#endif
Timespec* get_random_timespec(void);
time64 get_random_time(void);
void random_timespec_zero_nsec (gboolean zero_nsec);
void random_timespec_usec_resolution (gboolean usec_resolution);

View File

@@ -52,7 +52,7 @@ check_time (Timespec ts, gboolean always_print)
* the time, in seconds, is identical to the local time in
* Greenwich (GMT).
*/
ts_2 = gnc_iso8601_to_timespec_gmt (str);
ts_2 = {gnc_iso8601_to_time64_gmt (str), 0};
ok = timespec_equal (&ts, &ts_2);
@@ -85,7 +85,7 @@ check_conversion (const char * str, Timespec expected_ts)
int day, month, year;
GDate d1, d2;
ts = gnc_iso8601_to_timespec_gmt (str);
ts = {gnc_iso8601_to_time64_gmt (str), 0};
// We test the conversion to GDate against the timespec2dmy
// conversion, and also the conversion back to timespec and again
@@ -309,31 +309,31 @@ run_test (void)
/* Various leap-year days and near-leap times. */
ts = gnc_iso8601_to_timespec_gmt ("1980-02-29 00:00:00.000000 -0000");
ts = {gnc_iso8601_to_time64_gmt ("1980-02-29 00:00:00.000000 -0000"), 0};
check_time (ts, do_print);
ts = gnc_iso8601_to_timespec_gmt ("1979-02-28 00:00:00.000000 -0000");
ts = {gnc_iso8601_to_time64_gmt ("1979-02-28 00:00:00.000000 -0000"), 0};
check_time (ts, do_print);
ts = gnc_iso8601_to_timespec_gmt ("1990-02-28 00:00:00.000000 -0000");
ts = {gnc_iso8601_to_time64_gmt ("1990-02-28 00:00:00.000000 -0000"), 0};
check_time (ts, do_print);
ts = gnc_iso8601_to_timespec_gmt ("2000-02-29 00:00:00.000000 -0000");
ts = {gnc_iso8601_to_time64_gmt ("2000-02-29 00:00:00.000000 -0000"), 0};
check_time (ts, do_print);
ts = gnc_iso8601_to_timespec_gmt ("2004-02-29 00:00:00.000000 -0000");
ts = {gnc_iso8601_to_time64_gmt ("2004-02-29 00:00:00.000000 -0000"), 0};
check_time (ts, do_print);
ts = gnc_iso8601_to_timespec_gmt ("2008-02-29 00:00:00.000000 -0000");
ts = {gnc_iso8601_to_time64_gmt ("2008-02-29 00:00:00.000000 -0000"), 0};
check_time (ts, do_print);
ts = gnc_iso8601_to_timespec_gmt ("2008-02-29 00:01:00.000000 -0000");
ts = {gnc_iso8601_to_time64_gmt ("2008-02-29 00:01:00.000000 -0000"), 0};
check_time (ts, do_print);
ts = gnc_iso8601_to_timespec_gmt ("2008-02-29 02:02:00.000000 -0000");
ts = {gnc_iso8601_to_time64_gmt ("2008-02-29 02:02:00.000000 -0000"), 0};
check_time (ts, do_print);
ts = gnc_iso8601_to_timespec_gmt ("2008-02-28 23:23:23.000000 -0000");
ts = {gnc_iso8601_to_time64_gmt ("2008-02-28 23:23:23.000000 -0000"), 0};
check_time (ts, do_print);
/* Here's a date ten days after the 2038 rollover that should work

View File

@@ -1635,17 +1635,15 @@ get_nanoseconds (GDateTime *gdt)
static void
test_gnc_iso8601_to_timespec_gmt (FixtureA *f, gconstpointer pData)
{
Timespec t;
t = gnc_iso8601_to_timespec_gmt (NULL);
Timespec t = {gnc_iso8601_to_time64_gmt (NULL), 0};
g_assert_cmpint (t.tv_sec, ==, 0);
g_assert_cmpint (t.tv_nsec, ==, 0);
t = gnc_iso8601_to_timespec_gmt ("");
t.tv_sec = gnc_iso8601_to_time64_gmt ("");
g_assert_cmpint (t.tv_sec, ==, 0);
g_assert_cmpint (t.tv_nsec, ==, 0);
t = gnc_iso8601_to_timespec_gmt ("1989-03-27 13:43:27");
t.tv_sec = gnc_iso8601_to_time64_gmt ("1989-03-27 13:43:27");
g_assert_cmpint (t.tv_sec, ==, f->ts1.tv_sec);
/* MinGW has some precision issues in the last microsecond digit */
#ifdef G_OS_WIN32
@@ -1654,19 +1652,19 @@ test_gnc_iso8601_to_timespec_gmt (FixtureA *f, gconstpointer pData)
#else
g_assert_cmpint (t.tv_nsec, ==, f->ts1.tv_nsec);
#endif
t = gnc_iso8601_to_timespec_gmt ("2020-11-07 06:21:19 -05");
t.tv_sec = gnc_iso8601_to_time64_gmt ("2020-11-07 06:21:19 -05");
g_assert_cmpint (t.tv_sec, ==, f->ts2.tv_sec);
g_assert_cmpint (t.tv_nsec, ==, f->ts2.tv_nsec);
t = gnc_iso8601_to_timespec_gmt ("2012-07-04 19:27:44.0+08:40");
t.tv_sec = gnc_iso8601_to_time64_gmt ("2012-07-04 19:27:44.0+08:40");
g_assert_cmpint (t.tv_sec, ==, f->ts3.tv_sec);
g_assert_cmpint (t.tv_nsec, ==, f->ts3.tv_nsec);
t = gnc_iso8601_to_timespec_gmt ("1961-09-22 17:53:19 -05");
t.tv_sec = gnc_iso8601_to_time64_gmt ("1961-09-22 17:53:19 -05");
g_assert_cmpint (t.tv_sec, ==, f->ts4.tv_sec);
g_assert_cmpint (t.tv_nsec, ==, f->ts4.tv_nsec);
t = gnc_iso8601_to_timespec_gmt ("2061-01-25 23:21:19.0 -05:00");
t.tv_sec = gnc_iso8601_to_time64_gmt ("2061-01-25 23:21:19.0 -05:00");
g_assert_cmpint (t.tv_sec, ==, f->ts5.tv_sec);
g_assert_cmpint (t.tv_nsec, ==, f->ts5.tv_nsec);
}