mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Removing timspec from some xml parsing
And several other sprawling references that are connected in one way or another.
This commit is contained in:
@@ -244,9 +244,10 @@ static inline gboolean
|
||||
set_timespec (xmlNodePtr node, GncEntry* entry,
|
||||
void (*func) (GncEntry* entry, Timespec ts))
|
||||
{
|
||||
Timespec ts = dom_tree_to_timespec (node);
|
||||
if (!dom_tree_valid_timespec (&ts, node->name)) return FALSE;
|
||||
time64 time = dom_tree_to_time64 (node);
|
||||
if (!dom_tree_valid_time64 (time, node->name)) return FALSE;
|
||||
|
||||
Timespec ts = {time, 0};
|
||||
func (entry, ts);
|
||||
return TRUE;
|
||||
}
|
||||
|
@@ -188,9 +188,10 @@ static inline gboolean
|
||||
set_timespec (xmlNodePtr node, GncInvoice* invoice,
|
||||
void (*func) (GncInvoice* invoice, Timespec ts))
|
||||
{
|
||||
Timespec ts = dom_tree_to_timespec (node);
|
||||
if (!dom_tree_valid_timespec (&ts, node->name)) return FALSE;
|
||||
time64 time = dom_tree_to_time64 (node);
|
||||
if (!dom_tree_valid_time64 (time, node->name)) return FALSE;
|
||||
|
||||
Timespec ts = {time, 0};
|
||||
func (invoice, ts);
|
||||
return TRUE;
|
||||
}
|
||||
|
@@ -134,9 +134,9 @@ static inline gboolean
|
||||
set_timespec (xmlNodePtr node, GncOrder* order,
|
||||
void (*func) (GncOrder* order, Timespec ts))
|
||||
{
|
||||
Timespec ts = dom_tree_to_timespec (node);
|
||||
if (!dom_tree_valid_timespec (&ts, node->name)) return FALSE;
|
||||
|
||||
time64 time = dom_tree_to_time64 (node);
|
||||
if (!dom_tree_valid_time64 (time, node->name)) return FALSE;
|
||||
Timespec ts {time, 0};
|
||||
func (order, ts);
|
||||
return TRUE;
|
||||
}
|
||||
|
@@ -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)
|
||||
{
|
||||
Timespec t = dom_tree_to_timespec (sub_node);
|
||||
if (!dom_tree_valid_timespec (&t, sub_node->name)) return FALSE;
|
||||
gnc_price_set_time (p, t);
|
||||
time64 time = dom_tree_to_time64 (sub_node);
|
||||
if (!dom_tree_valid_time64 (time, sub_node->name)) return FALSE;
|
||||
Timespec ts {time, 0};
|
||||
gnc_price_set_time (p, ts);
|
||||
}
|
||||
else if (g_strcmp0 ("price:source", (char*)sub_node->name) == 0)
|
||||
{
|
||||
|
@@ -275,13 +275,9 @@ static gboolean
|
||||
spl_reconcile_date_handler (xmlNodePtr node, gpointer data)
|
||||
{
|
||||
struct split_pdata* pdata = static_cast<decltype (pdata)> (data);
|
||||
Timespec ts;
|
||||
|
||||
ts = dom_tree_to_timespec (node);
|
||||
if (!dom_tree_valid_timespec (&ts, node->name)) return FALSE;
|
||||
|
||||
xaccSplitSetDateReconciledTS (pdata->split, &ts);
|
||||
|
||||
time64 time = dom_tree_to_time64 (node);
|
||||
if (!dom_tree_valid_time64 (time, node->name)) return FALSE;
|
||||
xaccSplitSetDateReconciledSecs (pdata->split, time);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@@ -434,14 +430,10 @@ static inline gboolean
|
||||
set_tran_date (xmlNodePtr node, Transaction* trn,
|
||||
void (*func) (Transaction* trn, const Timespec* tm))
|
||||
{
|
||||
Timespec tm;
|
||||
|
||||
tm = dom_tree_to_timespec (node);
|
||||
|
||||
if (!dom_tree_valid_timespec (&tm, node->name)) return FALSE;
|
||||
|
||||
func (trn, &tm);
|
||||
|
||||
time64 time = dom_tree_to_time64 (node);
|
||||
if (!dom_tree_valid_time64 (time, node->name)) return FALSE;
|
||||
Timespec ts {time, 0};
|
||||
func (trn, &ts);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
@@ -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)
|
||||
{
|
||||
Timespec t = dom_tree_to_timespec (sub_node);
|
||||
if (!dom_tree_valid_timespec (&t, sub_node->name)) return FALSE;
|
||||
gnc_price_set_time (p, t);
|
||||
time64 time = dom_tree_to_time64 (sub_node);
|
||||
if (!dom_tree_valid_time64 (time, sub_node->name)) return FALSE;
|
||||
Timespec ts = {time, 0};
|
||||
gnc_price_set_time (p, ts);
|
||||
}
|
||||
else if (g_strcmp0 ("price:source", (char*)sub_node->name) == 0)
|
||||
{
|
||||
|
@@ -131,6 +131,12 @@ commodity_ref_to_dom_tree (const char* tag, const gnc_commodity* c)
|
||||
return ret;
|
||||
}
|
||||
|
||||
char*
|
||||
time64_to_string (time64 time)
|
||||
{
|
||||
return gnc_print_time64 (time, TIMESPEC_TIME_FORMAT " %q");
|
||||
}
|
||||
|
||||
char*
|
||||
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);
|
||||
}
|
||||
|
||||
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
|
||||
timespec_to_dom_tree (const char* tag, const Timespec* spec)
|
||||
{
|
||||
|
@@ -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 commodity_ref_to_dom_tree (const char* tag, const gnc_commodity* c);
|
||||
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_sec_to_string (const Timespec* ts);
|
||||
gchar* time64_to_string (time64);
|
||||
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 qof_instance_slots_to_dom_tree (const char* tag,
|
||||
|
@@ -233,14 +233,9 @@ dom_tree_to_guid_kvp_value (xmlNodePtr node)
|
||||
}
|
||||
|
||||
static KvpValue*
|
||||
dom_tree_to_timespec_kvp_value (xmlNodePtr node)
|
||||
dom_tree_to_time64_kvp_value (xmlNodePtr node)
|
||||
{
|
||||
Timespec ts;
|
||||
KvpValue* ret = nullptr;
|
||||
|
||||
ts = dom_tree_to_timespec (node);
|
||||
ret = new KvpValue {ts};
|
||||
return ret;
|
||||
return new KvpValue {Timespec {dom_tree_to_time64 (node), 0}};
|
||||
}
|
||||
|
||||
static KvpValue*
|
||||
@@ -360,7 +355,7 @@ struct kvp_val_converter val_converters[] =
|
||||
{ "numeric", dom_tree_to_numeric_kvp_value },
|
||||
{ "string", dom_tree_to_string_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 },
|
||||
{ "list", dom_tree_to_list_kvp_value },
|
||||
{ "frame", dom_tree_to_frame_kvp_value },
|
||||
@@ -528,17 +523,15 @@ dom_tree_to_gnc_numeric (xmlNodePtr node)
|
||||
return ret;
|
||||
}
|
||||
|
||||
static inline Timespec
|
||||
timespec_failure (Timespec ts)
|
||||
static time64
|
||||
time_parse_failure ()
|
||||
{
|
||||
ts.tv_sec = 0;
|
||||
ts.tv_nsec = 0;
|
||||
return ts;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Timespec
|
||||
dom_tree_to_timespec (xmlNodePtr node)
|
||||
time64
|
||||
dom_tree_to_time64 (xmlNodePtr node)
|
||||
{
|
||||
/* Turn something like this
|
||||
|
||||
@@ -547,18 +540,15 @@ dom_tree_to_timespec (xmlNodePtr node)
|
||||
<ns>658864000</ns>
|
||||
</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>
|
||||
and no more than one of each. Order is irrelevant. */
|
||||
|
||||
Timespec ret;
|
||||
time64 ret {0};
|
||||
gboolean seen_s = FALSE;
|
||||
gboolean seen_ns = FALSE;
|
||||
xmlNodePtr n;
|
||||
|
||||
|
||||
ret.tv_sec = 0;
|
||||
ret.tv_nsec = 0;
|
||||
for (n = node->xmlChildrenNode; n; n = n->next)
|
||||
{
|
||||
switch (n->type)
|
||||
@@ -571,52 +561,29 @@ dom_tree_to_timespec (xmlNodePtr node)
|
||||
{
|
||||
if (seen_s)
|
||||
{
|
||||
return timespec_failure (ret);
|
||||
return time_parse_failure ();
|
||||
}
|
||||
else
|
||||
{
|
||||
gchar* content = dom_tree_to_text (n);
|
||||
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);
|
||||
return timespec_failure (ret);
|
||||
return time_parse_failure ();
|
||||
}
|
||||
g_free (content);
|
||||
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;
|
||||
default:
|
||||
PERR ("unexpected sub-node.");
|
||||
return timespec_failure (ret);
|
||||
return time_parse_failure ();
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -624,7 +591,7 @@ dom_tree_to_timespec (xmlNodePtr node)
|
||||
if (!seen_s)
|
||||
{
|
||||
PERR ("no ts:date node found.");
|
||||
return timespec_failure (ret);
|
||||
return time_parse_failure ();
|
||||
}
|
||||
|
||||
return ret;
|
||||
@@ -895,6 +862,16 @@ dom_tree_generic_parse (xmlNodePtr node, struct dom_tree_handler* handlers,
|
||||
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
|
||||
dom_tree_valid_timespec (Timespec* ts, const xmlChar* name)
|
||||
{
|
||||
|
@@ -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);
|
||||
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_time64 (time64 ts, const xmlChar* name);
|
||||
GDate* dom_tree_to_gdate (xmlNodePtr node);
|
||||
gnc_numeric* dom_tree_to_gnc_numeric (xmlNodePtr node);
|
||||
gchar* dom_tree_to_text (xmlNodePtr tree);
|
||||
|
@@ -363,16 +363,9 @@ simple_chars_only_parser_new (sixtp_end_handler end_handler)
|
||||
*/
|
||||
|
||||
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);
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
gboolean
|
||||
string_to_timespec_nsecs (const gchar* str, Timespec* ts)
|
||||
{
|
||||
/* We don't do nanoseconds anymore. */
|
||||
*time = gnc_iso8601_to_time64_gmt (str);
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
@@ -459,7 +452,7 @@ generic_timespec_secs_end_handler (gpointer data_for_children,
|
||||
txt = concatenate_child_result_chars (data_from_children);
|
||||
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_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* result, const gchar* tag)
|
||||
{
|
||||
gchar* txt = NULL;
|
||||
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);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static sixtp*
|
||||
|
@@ -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);
|
||||
|
||||
gboolean string_to_timespec_secs (const gchar* str, Timespec* ts);
|
||||
gboolean string_to_timespec_nsecs (const gchar* str, Timespec* ts);
|
||||
gboolean string_to_time64 (const gchar* str, time64* ts);
|
||||
|
||||
gboolean generic_timespec_start_handler (GSList* sibling_data,
|
||||
gpointer parent_data,
|
||||
|
@@ -41,51 +41,26 @@ main (int argc, char** argv)
|
||||
|
||||
for (i = 0; i < 20; i++)
|
||||
{
|
||||
Timespec* spec1;
|
||||
Timespec spec2;
|
||||
gchar* sec_str;
|
||||
gchar* nsec_str;
|
||||
|
||||
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))
|
||||
time64 spec2;
|
||||
auto spec1 = get_random_time ();
|
||||
auto sec_str = time64_to_string (spec1);
|
||||
if (!string_to_time64 (sec_str, &spec2))
|
||||
{
|
||||
failure_args ("string_to_timespec_secs", __FILE__, __LINE__,
|
||||
"string is %s", sec_str);
|
||||
}
|
||||
|
||||
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)
|
||||
else if (spec1 != spec2)
|
||||
{
|
||||
failure_args ("timespec_secs", __FILE__, __LINE__,
|
||||
"not equal ints are %" G_GINT64_FORMAT
|
||||
" 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
|
||||
{
|
||||
success ("timespec");
|
||||
}
|
||||
|
||||
g_free (spec1);
|
||||
g_free (sec_str);
|
||||
g_free (nsec_str);
|
||||
}
|
||||
print_test_results ();
|
||||
exit (get_rv ());
|
||||
|
@@ -132,17 +132,11 @@ test_dom_tree_to_timespec (void)
|
||||
int i;
|
||||
for (i = 0; i < 20; i++)
|
||||
{
|
||||
Timespec* test_spec1;
|
||||
Timespec test_spec2;
|
||||
xmlNodePtr test_node;
|
||||
|
||||
test_spec1 = get_random_timespec ();
|
||||
|
||||
test_node = timespec_to_dom_tree ("test-spec", test_spec1);
|
||||
|
||||
test_spec2 = dom_tree_to_timespec (test_node);
|
||||
|
||||
if (!dom_tree_valid_timespec (&test_spec2, (const xmlChar*)"test-spec"))
|
||||
time64 test_spec1 = get_random_time ();
|
||||
test_node = time64_to_dom_tree ("test-spec", test_spec1);
|
||||
time64 test_spec2 = dom_tree_to_time64 (test_node);
|
||||
if (!dom_tree_valid_time64 (test_spec2, (const xmlChar*)"test-spec"))
|
||||
{
|
||||
failure_args ("dom_tree_to_timespec",
|
||||
__FILE__, __LINE__, "NULL return");
|
||||
@@ -150,8 +144,7 @@ test_dom_tree_to_timespec (void)
|
||||
xmlElemDump (stdout, NULL, test_node);
|
||||
printf ("\n");
|
||||
}
|
||||
|
||||
else if (timespec_cmp (test_spec1, &test_spec2) == 0)
|
||||
else if (test_spec1 == test_spec2)
|
||||
{
|
||||
success ("dom_tree_to_timespec");
|
||||
}
|
||||
@@ -161,15 +154,9 @@ test_dom_tree_to_timespec (void)
|
||||
printf ("Node looks like:\n");
|
||||
xmlElemDump (stdout, NULL, test_node);
|
||||
printf ("\n");
|
||||
printf ("Secs are %" G_GUINT64_FORMAT " vs %" G_GUINT64_FORMAT " :: ",
|
||||
test_spec1->tv_sec,
|
||||
test_spec2.tv_sec);
|
||||
printf ("NSecs are %ld vs %ld\n",
|
||||
test_spec1->tv_nsec,
|
||||
test_spec2.tv_nsec);
|
||||
printf ("passed: %" G_GUINT64_FORMAT " got: %" G_GUINT64_FORMAT ".\n",
|
||||
test_spec1, test_spec2);
|
||||
}
|
||||
|
||||
g_free (test_spec1);
|
||||
xmlFreeNode (test_node);
|
||||
}
|
||||
}
|
||||
|
@@ -279,16 +279,8 @@ equals_node_val_vs_kvp_frame (xmlNodePtr node, const KvpFrame* frm)
|
||||
gboolean
|
||||
equals_node_val_vs_date (xmlNodePtr node, const Timespec tm)
|
||||
{
|
||||
Timespec tm_test = dom_tree_to_timespec (node);
|
||||
|
||||
if (tm_test.tv_sec == tm.tv_sec && tm_test.tv_nsec == tm.tv_nsec)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
time64 time = dom_tree_to_time64 (node);
|
||||
return time == tm.tv_sec;
|
||||
}
|
||||
|
||||
/***********************************************************************/
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -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.
|
||||
|
@@ -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)
|
||||
{
|
||||
|
@@ -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);
|
||||
|
||||
|
@@ -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
|
||||
|
@@ -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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user