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

@@ -244,9 +244,10 @@ static inline gboolean
set_timespec (xmlNodePtr node, GncEntry* entry, set_timespec (xmlNodePtr node, GncEntry* entry,
void (*func) (GncEntry* entry, Timespec ts)) void (*func) (GncEntry* entry, Timespec ts))
{ {
Timespec ts = dom_tree_to_timespec (node); time64 time = dom_tree_to_time64 (node);
if (!dom_tree_valid_timespec (&ts, node->name)) return FALSE; if (!dom_tree_valid_time64 (time, node->name)) return FALSE;
Timespec ts = {time, 0};
func (entry, ts); func (entry, ts);
return TRUE; return TRUE;
} }

View File

@@ -188,9 +188,10 @@ static inline gboolean
set_timespec (xmlNodePtr node, GncInvoice* invoice, set_timespec (xmlNodePtr node, GncInvoice* invoice,
void (*func) (GncInvoice* invoice, Timespec ts)) void (*func) (GncInvoice* invoice, Timespec ts))
{ {
Timespec ts = dom_tree_to_timespec (node); time64 time = dom_tree_to_time64 (node);
if (!dom_tree_valid_timespec (&ts, node->name)) return FALSE; if (!dom_tree_valid_time64 (time, node->name)) return FALSE;
Timespec ts = {time, 0};
func (invoice, ts); func (invoice, ts);
return TRUE; return TRUE;
} }

View File

@@ -134,9 +134,9 @@ static inline gboolean
set_timespec (xmlNodePtr node, GncOrder* order, set_timespec (xmlNodePtr node, GncOrder* order,
void (*func) (GncOrder* order, Timespec ts)) void (*func) (GncOrder* order, Timespec ts))
{ {
Timespec ts = dom_tree_to_timespec (node); time64 time = dom_tree_to_time64 (node);
if (!dom_tree_valid_timespec (&ts, node->name)) return FALSE; if (!dom_tree_valid_time64 (time, node->name)) return FALSE;
Timespec ts {time, 0};
func (order, ts); func (order, ts);
return TRUE; return TRUE;
} }

View File

@@ -113,9 +113,10 @@ price_parse_xml_sub_node (GNCPrice* p, xmlNodePtr sub_node, QofBook* book)
} }
else if (g_strcmp0 ("price:time", (char*)sub_node->name) == 0) else if (g_strcmp0 ("price:time", (char*)sub_node->name) == 0)
{ {
Timespec t = dom_tree_to_timespec (sub_node); time64 time = dom_tree_to_time64 (sub_node);
if (!dom_tree_valid_timespec (&t, sub_node->name)) return FALSE; if (!dom_tree_valid_time64 (time, sub_node->name)) return FALSE;
gnc_price_set_time (p, t); Timespec ts {time, 0};
gnc_price_set_time (p, ts);
} }
else if (g_strcmp0 ("price:source", (char*)sub_node->name) == 0) else if (g_strcmp0 ("price:source", (char*)sub_node->name) == 0)
{ {

View File

@@ -275,13 +275,9 @@ static gboolean
spl_reconcile_date_handler (xmlNodePtr node, gpointer data) spl_reconcile_date_handler (xmlNodePtr node, gpointer data)
{ {
struct split_pdata* pdata = static_cast<decltype (pdata)> (data); struct split_pdata* pdata = static_cast<decltype (pdata)> (data);
Timespec ts; time64 time = dom_tree_to_time64 (node);
if (!dom_tree_valid_time64 (time, node->name)) return FALSE;
ts = dom_tree_to_timespec (node); xaccSplitSetDateReconciledSecs (pdata->split, time);
if (!dom_tree_valid_timespec (&ts, node->name)) return FALSE;
xaccSplitSetDateReconciledTS (pdata->split, &ts);
return TRUE; return TRUE;
} }
@@ -434,14 +430,10 @@ static inline gboolean
set_tran_date (xmlNodePtr node, Transaction* trn, set_tran_date (xmlNodePtr node, Transaction* trn,
void (*func) (Transaction* trn, const Timespec* tm)) void (*func) (Transaction* trn, const Timespec* tm))
{ {
Timespec tm; time64 time = dom_tree_to_time64 (node);
if (!dom_tree_valid_time64 (time, node->name)) return FALSE;
tm = dom_tree_to_timespec (node); Timespec ts {time, 0};
func (trn, &ts);
if (!dom_tree_valid_timespec (&tm, node->name)) return FALSE;
func (trn, &tm);
return TRUE; return TRUE;
} }

View File

@@ -2959,9 +2959,10 @@ price_parse_xml_sub_node (GNCPrice* p, xmlNodePtr sub_node, QofBook* book)
} }
else if (g_strcmp0 ("price:time", (char*)sub_node->name) == 0) else if (g_strcmp0 ("price:time", (char*)sub_node->name) == 0)
{ {
Timespec t = dom_tree_to_timespec (sub_node); time64 time = dom_tree_to_time64 (sub_node);
if (!dom_tree_valid_timespec (&t, sub_node->name)) return FALSE; if (!dom_tree_valid_time64 (time, sub_node->name)) return FALSE;
gnc_price_set_time (p, t); Timespec ts = {time, 0};
gnc_price_set_time (p, ts);
} }
else if (g_strcmp0 ("price:source", (char*)sub_node->name) == 0) else if (g_strcmp0 ("price:source", (char*)sub_node->name) == 0)
{ {

View File

@@ -131,6 +131,12 @@ commodity_ref_to_dom_tree (const char* tag, const gnc_commodity* c)
return ret; return ret;
} }
char*
time64_to_string (time64 time)
{
return gnc_print_time64 (time, TIMESPEC_TIME_FORMAT " %q");
}
char* char*
timespec_sec_to_string (const Timespec* ts) timespec_sec_to_string (const Timespec* ts)
{ {
@@ -143,6 +149,21 @@ timespec_nsec_to_string (const Timespec* ts)
return g_strdup_printf ("%ld", ts->tv_nsec); return g_strdup_printf ("%ld", ts->tv_nsec);
} }
xmlNodePtr
time64_to_dom_tree (const char* tag, const time64 time)
{
xmlNodePtr ret;
g_return_val_if_fail (time, NULL);
auto date_str = gnc_print_time64 (time, TIMESPEC_TIME_FORMAT " %q");
if (!date_str)
return NULL;
ret = xmlNewNode (NULL, BAD_CAST tag);
xmlNewTextChild (ret, NULL, BAD_CAST "ts:date",
checked_char_cast (date_str));
g_free (date_str);
return ret;
}
xmlNodePtr xmlNodePtr
timespec_to_dom_tree (const char* tag, const Timespec* spec) timespec_to_dom_tree (const char* tag, const Timespec* spec)
{ {

View File

@@ -41,8 +41,10 @@ xmlNodePtr boolean_to_dom_tree (const char* tag, gboolean val);
xmlNodePtr guid_to_dom_tree (const char* tag, const GncGUID* gid); xmlNodePtr guid_to_dom_tree (const char* tag, const GncGUID* gid);
xmlNodePtr commodity_ref_to_dom_tree (const char* tag, const gnc_commodity* c); xmlNodePtr commodity_ref_to_dom_tree (const char* tag, const gnc_commodity* c);
xmlNodePtr timespec_to_dom_tree (const char* tag, const Timespec* spec); xmlNodePtr timespec_to_dom_tree (const char* tag, const Timespec* spec);
xmlNodePtr time64_to_dom_tree (const char* tag, time64);
gchar* timespec_nsec_to_string (const Timespec* ts); gchar* timespec_nsec_to_string (const Timespec* ts);
gchar* timespec_sec_to_string (const Timespec* ts); gchar* timespec_sec_to_string (const Timespec* ts);
gchar* time64_to_string (time64);
xmlNodePtr gdate_to_dom_tree (const char* tag, const GDate* spec); xmlNodePtr gdate_to_dom_tree (const char* tag, const GDate* spec);
xmlNodePtr gnc_numeric_to_dom_tree (const char* tag, const gnc_numeric* num); xmlNodePtr gnc_numeric_to_dom_tree (const char* tag, const gnc_numeric* num);
xmlNodePtr qof_instance_slots_to_dom_tree (const char* tag, xmlNodePtr qof_instance_slots_to_dom_tree (const char* tag,

View File

@@ -233,14 +233,9 @@ dom_tree_to_guid_kvp_value (xmlNodePtr node)
} }
static KvpValue* static KvpValue*
dom_tree_to_timespec_kvp_value (xmlNodePtr node) dom_tree_to_time64_kvp_value (xmlNodePtr node)
{ {
Timespec ts; return new KvpValue {Timespec {dom_tree_to_time64 (node), 0}};
KvpValue* ret = nullptr;
ts = dom_tree_to_timespec (node);
ret = new KvpValue {ts};
return ret;
} }
static KvpValue* static KvpValue*
@@ -360,7 +355,7 @@ struct kvp_val_converter val_converters[] =
{ "numeric", dom_tree_to_numeric_kvp_value }, { "numeric", dom_tree_to_numeric_kvp_value },
{ "string", dom_tree_to_string_kvp_value }, { "string", dom_tree_to_string_kvp_value },
{ "guid", dom_tree_to_guid_kvp_value }, { "guid", dom_tree_to_guid_kvp_value },
{ "timespec", dom_tree_to_timespec_kvp_value }, { "timespec", dom_tree_to_time64_kvp_value },
{ "gdate", dom_tree_to_gdate_kvp_value }, { "gdate", dom_tree_to_gdate_kvp_value },
{ "list", dom_tree_to_list_kvp_value }, { "list", dom_tree_to_list_kvp_value },
{ "frame", dom_tree_to_frame_kvp_value }, { "frame", dom_tree_to_frame_kvp_value },
@@ -528,17 +523,15 @@ dom_tree_to_gnc_numeric (xmlNodePtr node)
return ret; return ret;
} }
static inline Timespec static time64
timespec_failure (Timespec ts) time_parse_failure ()
{ {
ts.tv_sec = 0; return 0;
ts.tv_nsec = 0;
return ts;
} }
Timespec time64
dom_tree_to_timespec (xmlNodePtr node) dom_tree_to_time64 (xmlNodePtr node)
{ {
/* Turn something like this /* Turn something like this
@@ -547,18 +540,15 @@ dom_tree_to_timespec (xmlNodePtr node)
<ns>658864000</ns> <ns>658864000</ns>
</date-posted> </date-posted>
into a Timespec. If this returns FALSE, the effects on *ts are into a time64. If this returns FALSE, the effects on *ts are
undefined. The XML is valid if it has at least one of <s> or <ns> undefined. The XML is valid if it has at least one of <s> or <ns>
and no more than one of each. Order is irrelevant. */ and no more than one of each. Order is irrelevant. */
Timespec ret; time64 ret {0};
gboolean seen_s = FALSE; gboolean seen_s = FALSE;
gboolean seen_ns = FALSE; gboolean seen_ns = FALSE;
xmlNodePtr n; xmlNodePtr n;
ret.tv_sec = 0;
ret.tv_nsec = 0;
for (n = node->xmlChildrenNode; n; n = n->next) for (n = node->xmlChildrenNode; n; n = n->next)
{ {
switch (n->type) switch (n->type)
@@ -571,52 +561,29 @@ dom_tree_to_timespec (xmlNodePtr node)
{ {
if (seen_s) if (seen_s)
{ {
return timespec_failure (ret); return time_parse_failure ();
} }
else else
{ {
gchar* content = dom_tree_to_text (n); gchar* content = dom_tree_to_text (n);
if (!content) if (!content)
{ {
return timespec_failure (ret); return time_parse_failure ();
} }
if (!string_to_timespec_secs (content, &ret)) if (!string_to_time64 (content, &ret))
{ {
g_free (content); g_free (content);
return timespec_failure (ret); return time_parse_failure ();
} }
g_free (content); g_free (content);
seen_s = TRUE; seen_s = TRUE;
} }
} }
else if (g_strcmp0 ("ts:ns", (char*)n->name) == 0)
{
if (seen_ns)
{
return timespec_failure (ret);
}
else
{
gchar* content = dom_tree_to_text (n);
if (!content)
{
return timespec_failure (ret);
}
if (!string_to_timespec_nsecs (content, &ret))
{
g_free (content);
return timespec_failure (ret);
}
g_free (content);
seen_ns = TRUE;
}
}
break; break;
default: default:
PERR ("unexpected sub-node."); PERR ("unexpected sub-node.");
return timespec_failure (ret); return time_parse_failure ();
break; break;
} }
} }
@@ -624,7 +591,7 @@ dom_tree_to_timespec (xmlNodePtr node)
if (!seen_s) if (!seen_s)
{ {
PERR ("no ts:date node found."); PERR ("no ts:date node found.");
return timespec_failure (ret); return time_parse_failure ();
} }
return ret; return ret;
@@ -895,6 +862,16 @@ dom_tree_generic_parse (xmlNodePtr node, struct dom_tree_handler* handlers,
return successful; return successful;
} }
gboolean
dom_tree_valid_time64 (time64 val, const xmlChar * name)
{
if (val)
return TRUE;
g_warning ("Invalid timestamp in data file. Look for a '%s' entry "
"with a date of 1969-12-31 or 1970-01-01.", name);
return FALSE;
}
gboolean gboolean
dom_tree_valid_timespec (Timespec* ts, const xmlChar* name) dom_tree_valid_timespec (Timespec* ts, const xmlChar* name)
{ {

View File

@@ -42,8 +42,9 @@ gnc_commodity* dom_tree_to_commodity_ref_no_engine (xmlNodePtr node, QofBook*);
GList* dom_tree_freqSpec_to_recurrences (xmlNodePtr node, QofBook* book); GList* dom_tree_freqSpec_to_recurrences (xmlNodePtr node, QofBook* book);
Recurrence* dom_tree_to_recurrence (xmlNodePtr node); Recurrence* dom_tree_to_recurrence (xmlNodePtr node);
Timespec dom_tree_to_timespec (xmlNodePtr node); time64 dom_tree_to_time64 (xmlNodePtr node);
gboolean dom_tree_valid_timespec (Timespec* ts, const xmlChar* name); gboolean dom_tree_valid_timespec (Timespec* ts, const xmlChar* name);
gboolean dom_tree_valid_time64 (time64 ts, const xmlChar* name);
GDate* dom_tree_to_gdate (xmlNodePtr node); GDate* dom_tree_to_gdate (xmlNodePtr node);
gnc_numeric* dom_tree_to_gnc_numeric (xmlNodePtr node); gnc_numeric* dom_tree_to_gnc_numeric (xmlNodePtr node);
gchar* dom_tree_to_text (xmlNodePtr tree); gchar* dom_tree_to_text (xmlNodePtr tree);

View File

@@ -363,16 +363,9 @@ simple_chars_only_parser_new (sixtp_end_handler end_handler)
*/ */
gboolean gboolean
string_to_timespec_secs (const gchar* str, Timespec* ts) string_to_time64 (const gchar* str, time64* time)
{ {
*ts = gnc_iso8601_to_timespec_gmt (str); *time = gnc_iso8601_to_time64_gmt (str);
return (TRUE);
}
gboolean
string_to_timespec_nsecs (const gchar* str, Timespec* ts)
{
/* We don't do nanoseconds anymore. */
return (TRUE); return (TRUE);
} }
@@ -459,7 +452,7 @@ generic_timespec_secs_end_handler (gpointer data_for_children,
txt = concatenate_child_result_chars (data_from_children); txt = concatenate_child_result_chars (data_from_children);
g_return_val_if_fail (txt, FALSE); g_return_val_if_fail (txt, FALSE);
ok = string_to_timespec_secs (txt, & (info->ts)); ok = string_to_time64 (txt, & (info->ts.tv_sec));
g_free (txt); g_free (txt);
g_return_val_if_fail (ok, FALSE); g_return_val_if_fail (ok, FALSE);
@@ -491,22 +484,7 @@ generic_timespec_nsecs_end_handler (gpointer data_for_children,
gpointer parent_data, gpointer global_data, gpointer parent_data, gpointer global_data,
gpointer* result, const gchar* tag) gpointer* result, const gchar* tag)
{ {
gchar* txt = NULL; return TRUE;
TimespecParseInfo* info = (TimespecParseInfo*) parent_data;
gboolean ok;
g_return_val_if_fail (parent_data, FALSE);
txt = concatenate_child_result_chars (data_from_children);
g_return_val_if_fail (txt, FALSE);
ok = string_to_timespec_nsecs (txt, & (info->ts));
g_free (txt);
g_return_val_if_fail (ok, FALSE);
info->ns_block_count++;
return (TRUE);
} }
static sixtp* static sixtp*

View File

@@ -85,8 +85,7 @@ gboolean generic_return_chars_end_handler (gpointer data_for_children,
sixtp* simple_chars_only_parser_new (sixtp_end_handler end_handler); sixtp* simple_chars_only_parser_new (sixtp_end_handler end_handler);
gboolean string_to_timespec_secs (const gchar* str, Timespec* ts); gboolean string_to_time64 (const gchar* str, time64* ts);
gboolean string_to_timespec_nsecs (const gchar* str, Timespec* ts);
gboolean generic_timespec_start_handler (GSList* sibling_data, gboolean generic_timespec_start_handler (GSList* sibling_data,
gpointer parent_data, gpointer parent_data,

View File

@@ -41,51 +41,26 @@ main (int argc, char** argv)
for (i = 0; i < 20; i++) for (i = 0; i < 20; i++)
{ {
Timespec* spec1; time64 spec2;
Timespec spec2; auto spec1 = get_random_time ();
gchar* sec_str; auto sec_str = time64_to_string (spec1);
gchar* nsec_str; if (!string_to_time64 (sec_str, &spec2))
spec1 = get_random_timespec ();
sec_str = timespec_sec_to_string (spec1);
nsec_str = timespec_nsec_to_string (spec1);
if (!string_to_timespec_secs (sec_str, &spec2))
{ {
failure_args ("string_to_timespec_secs", __FILE__, __LINE__, failure_args ("string_to_timespec_secs", __FILE__, __LINE__,
"string is %s", sec_str); "string is %s", sec_str);
} }
else if (spec1 != spec2)
else if (!string_to_timespec_nsecs (nsec_str, &spec2))
{
failure_args ("string_to_timespec_nsecs", __FILE__, __LINE__,
"string is %s", nsec_str);
}
else if (spec1->tv_sec != spec2.tv_sec)
{ {
failure_args ("timespec_secs", __FILE__, __LINE__, failure_args ("timespec_secs", __FILE__, __LINE__,
"not equal ints are %" G_GINT64_FORMAT "not equal ints are %" G_GINT64_FORMAT
" and %" G_GINT64_FORMAT "\n", " and %" G_GINT64_FORMAT "\n",
spec1->tv_sec, spec2.tv_sec); spec1, spec2);
} }
else if (spec1->tv_nsec != spec2.tv_nsec)
{
failure_args ("timespec_nsecs", __FILE__, __LINE__,
"not equal ints are %ld and %ld\n",
spec1->tv_nsec, spec2.tv_nsec);
}
else else
{ {
success ("timespec"); success ("timespec");
} }
g_free (spec1);
g_free (sec_str); g_free (sec_str);
g_free (nsec_str);
} }
print_test_results (); print_test_results ();
exit (get_rv ()); exit (get_rv ());

View File

@@ -132,17 +132,11 @@ test_dom_tree_to_timespec (void)
int i; int i;
for (i = 0; i < 20; i++) for (i = 0; i < 20; i++)
{ {
Timespec* test_spec1;
Timespec test_spec2;
xmlNodePtr test_node; xmlNodePtr test_node;
time64 test_spec1 = get_random_time ();
test_spec1 = get_random_timespec (); test_node = time64_to_dom_tree ("test-spec", test_spec1);
time64 test_spec2 = dom_tree_to_time64 (test_node);
test_node = timespec_to_dom_tree ("test-spec", test_spec1); if (!dom_tree_valid_time64 (test_spec2, (const xmlChar*)"test-spec"))
test_spec2 = dom_tree_to_timespec (test_node);
if (!dom_tree_valid_timespec (&test_spec2, (const xmlChar*)"test-spec"))
{ {
failure_args ("dom_tree_to_timespec", failure_args ("dom_tree_to_timespec",
__FILE__, __LINE__, "NULL return"); __FILE__, __LINE__, "NULL return");
@@ -150,8 +144,7 @@ test_dom_tree_to_timespec (void)
xmlElemDump (stdout, NULL, test_node); xmlElemDump (stdout, NULL, test_node);
printf ("\n"); printf ("\n");
} }
else if (test_spec1 == test_spec2)
else if (timespec_cmp (test_spec1, &test_spec2) == 0)
{ {
success ("dom_tree_to_timespec"); success ("dom_tree_to_timespec");
} }
@@ -161,15 +154,9 @@ test_dom_tree_to_timespec (void)
printf ("Node looks like:\n"); printf ("Node looks like:\n");
xmlElemDump (stdout, NULL, test_node); xmlElemDump (stdout, NULL, test_node);
printf ("\n"); printf ("\n");
printf ("Secs are %" G_GUINT64_FORMAT " vs %" G_GUINT64_FORMAT " :: ", printf ("passed: %" G_GUINT64_FORMAT " got: %" G_GUINT64_FORMAT ".\n",
test_spec1->tv_sec, test_spec1, test_spec2);
test_spec2.tv_sec);
printf ("NSecs are %ld vs %ld\n",
test_spec1->tv_nsec,
test_spec2.tv_nsec);
} }
g_free (test_spec1);
xmlFreeNode (test_node); xmlFreeNode (test_node);
} }
} }

View File

@@ -279,16 +279,8 @@ equals_node_val_vs_kvp_frame (xmlNodePtr node, const KvpFrame* frm)
gboolean gboolean
equals_node_val_vs_date (xmlNodePtr node, const Timespec tm) equals_node_val_vs_date (xmlNodePtr node, const Timespec tm)
{ {
Timespec tm_test = dom_tree_to_timespec (node); time64 time = dom_tree_to_time64 (node);
return time == tm.tv_sec;
if (tm_test.tv_sec == tm.tv_sec && tm_test.tv_nsec == tm.tv_nsec)
{
return TRUE;
}
else
{
return FALSE;
}
} }
/***********************************************************************/ /***********************************************************************/

View File

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

View File

@@ -1198,25 +1198,25 @@ gnc_date_timestamp (void)
*/ */
#define ISO_DATE_FORMAT "%d-%d-%d %d:%d:%lf%s" #define ISO_DATE_FORMAT "%d-%d-%d %d:%d:%lf%s"
Timespec time64
gnc_iso8601_to_timespec_gmt(const char *cstr) gnc_iso8601_to_time64_gmt(const char *cstr)
{ {
time64 time; time64 time;
if (!cstr) return {0, 0}; if (!cstr) return 0;
try try
{ {
GncDateTime gncdt(cstr); GncDateTime gncdt(cstr);
return {static_cast<time64>(gncdt), 0}; return static_cast<time64>(gncdt);
} }
catch(std::logic_error& err) catch(std::logic_error& err)
{ {
PWARN("Error processing %s: %s", cstr, err.what()); PWARN("Error processing %s: %s", cstr, err.what());
return {0, 0}; return 0;
} }
catch(std::runtime_error& err) catch(std::runtime_error& err)
{ {
PWARN("Error processing time64 %s: %s", cstr, err.what()); 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 * XXX Caution: this routine does not handle strings that specify
* times before January 1 1970. * 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 /** The gnc_timespec_to_iso8601_buff() routine takes the input
* UTC Timespec value and prints it as an ISO-8601 style string. * 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 */ /* Time/Date, GncGUID data stuff */
time64
get_random_time (void)
{
time64 ret {0};
while (ret <= 0)
ret = rand();
return ret;
}
Timespec* Timespec*
get_random_timespec(void) get_random_timespec(void)
{ {

View File

@@ -46,6 +46,7 @@ typedef struct KvpFrameImpl KvpFrame;
#define __KVP_FRAME #define __KVP_FRAME
#endif #endif
Timespec* get_random_timespec(void); Timespec* get_random_timespec(void);
time64 get_random_time(void);
void random_timespec_zero_nsec (gboolean zero_nsec); void random_timespec_zero_nsec (gboolean zero_nsec);
void random_timespec_usec_resolution (gboolean usec_resolution); 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 * the time, in seconds, is identical to the local time in
* Greenwich (GMT). * 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); ok = timespec_equal (&ts, &ts_2);
@@ -85,7 +85,7 @@ check_conversion (const char * str, Timespec expected_ts)
int day, month, year; int day, month, year;
GDate d1, d2; 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 // We test the conversion to GDate against the timespec2dmy
// conversion, and also the conversion back to timespec and again // 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. */ /* 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); 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); 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); 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); 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); 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); 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); 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); 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); check_time (ts, do_print);
/* Here's a date ten days after the 2038 rollover that should work /* 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 static void
test_gnc_iso8601_to_timespec_gmt (FixtureA *f, gconstpointer pData) test_gnc_iso8601_to_timespec_gmt (FixtureA *f, gconstpointer pData)
{ {
Timespec t; Timespec t = {gnc_iso8601_to_time64_gmt (NULL), 0};
t = gnc_iso8601_to_timespec_gmt (NULL);
g_assert_cmpint (t.tv_sec, ==, 0); g_assert_cmpint (t.tv_sec, ==, 0);
g_assert_cmpint (t.tv_nsec, ==, 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_sec, ==, 0);
g_assert_cmpint (t.tv_nsec, ==, 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); g_assert_cmpint (t.tv_sec, ==, f->ts1.tv_sec);
/* MinGW has some precision issues in the last microsecond digit */ /* MinGW has some precision issues in the last microsecond digit */
#ifdef G_OS_WIN32 #ifdef G_OS_WIN32
@@ -1654,19 +1652,19 @@ test_gnc_iso8601_to_timespec_gmt (FixtureA *f, gconstpointer pData)
#else #else
g_assert_cmpint (t.tv_nsec, ==, f->ts1.tv_nsec); g_assert_cmpint (t.tv_nsec, ==, f->ts1.tv_nsec);
#endif #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_sec, ==, f->ts2.tv_sec);
g_assert_cmpint (t.tv_nsec, ==, f->ts2.tv_nsec); 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_sec, ==, f->ts3.tv_sec);
g_assert_cmpint (t.tv_nsec, ==, f->ts3.tv_nsec); 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_sec, ==, f->ts4.tv_sec);
g_assert_cmpint (t.tv_nsec, ==, f->ts4.tv_nsec); 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_sec, ==, f->ts5.tv_sec);
g_assert_cmpint (t.tv_nsec, ==, f->ts5.tv_nsec); g_assert_cmpint (t.tv_nsec, ==, f->ts5.tv_nsec);
} }