mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Converted timespec_to_dom_tree to time64
This commit is contained in:
parent
f77369bb96
commit
5dd12119b7
@ -124,10 +124,10 @@ entry_dom_tree_create (GncEntry* entry)
|
||||
qof_instance_get_guid (QOF_INSTANCE (entry))));
|
||||
|
||||
ts = gncEntryGetDate (entry);
|
||||
xmlAddChild (ret, timespec_to_dom_tree (entry_date_string, &ts));
|
||||
xmlAddChild (ret, time64_to_dom_tree (entry_date_string, ts.tv_sec));
|
||||
|
||||
ts = gncEntryGetDateEntered (entry);
|
||||
xmlAddChild (ret, timespec_to_dom_tree (entry_dateentered_string, &ts));
|
||||
xmlAddChild (ret, time64_to_dom_tree (entry_dateentered_string, ts.tv_sec));
|
||||
|
||||
maybe_add_string (ret, entry_description_string,
|
||||
gncEntryGetDescription (entry));
|
||||
|
@ -83,8 +83,8 @@ maybe_add_string (xmlNodePtr ptr, const char* tag, const char* str)
|
||||
static void
|
||||
maybe_add_timespec (xmlNodePtr ptr, const char* tag, Timespec ts)
|
||||
{
|
||||
if (ts.tv_sec || ts.tv_nsec)
|
||||
xmlAddChild (ptr, timespec_to_dom_tree (tag, &ts));
|
||||
if (ts.tv_sec)
|
||||
xmlAddChild (ptr, time64_to_dom_tree (tag, ts.tv_sec));
|
||||
}
|
||||
|
||||
static xmlNodePtr
|
||||
@ -112,7 +112,7 @@ invoice_dom_tree_create (GncInvoice* invoice)
|
||||
gncInvoiceGetOwner (invoice)));
|
||||
|
||||
ts = gncInvoiceGetDateOpened (invoice);
|
||||
xmlAddChild (ret, timespec_to_dom_tree (invoice_opened_string, &ts));
|
||||
xmlAddChild (ret, time64_to_dom_tree (invoice_opened_string, ts.tv_sec));
|
||||
|
||||
maybe_add_timespec (ret, invoice_posted_string,
|
||||
gncInvoiceGetDatePosted (invoice));
|
||||
|
@ -90,11 +90,11 @@ order_dom_tree_create (GncOrder* order)
|
||||
gncOrderGetOwner (order)));
|
||||
|
||||
ts = gncOrderGetDateOpened (order);
|
||||
xmlAddChild (ret, timespec_to_dom_tree (order_opened_string, &ts));
|
||||
xmlAddChild (ret, time64_to_dom_tree (order_opened_string, ts.tv_sec));
|
||||
|
||||
ts = gncOrderGetDateClosed (order);
|
||||
if (ts.tv_sec || ts.tv_nsec)
|
||||
xmlAddChild (ret, timespec_to_dom_tree (order_closed_string, &ts));
|
||||
if (ts.tv_sec)
|
||||
xmlAddChild (ret, time64_to_dom_tree (order_closed_string, ts.tv_sec));
|
||||
|
||||
maybe_add_string (ret, order_notes_string, gncOrderGetNotes (order));
|
||||
maybe_add_string (ret, order_reference_string, gncOrderGetReference (order));
|
||||
|
@ -439,7 +439,7 @@ gnc_price_to_dom_tree (const xmlChar* tag, GNCPrice* price)
|
||||
if (!add_child_or_kill_parent (price_xml, tmpnode)) return NULL;
|
||||
|
||||
timesp = gnc_price_get_time (price);
|
||||
tmpnode = timespec_to_dom_tree ("price:time", ×p);
|
||||
tmpnode = time64_to_dom_tree ("price:time", timesp.tv_sec);
|
||||
if (!add_child_or_kill_parent (price_xml, tmpnode)) return NULL;
|
||||
|
||||
sourcestr = gnc_price_get_source_string (price);
|
||||
|
@ -59,9 +59,9 @@ add_gnc_num (xmlNodePtr node, const gchar* tag, gnc_numeric num)
|
||||
static void
|
||||
add_timespec (xmlNodePtr node, const gchar* tag, Timespec tms, gboolean always)
|
||||
{
|
||||
if (always || ! ((tms.tv_sec == 0) && (tms.tv_nsec == 0)))
|
||||
if (always || tms.tv_sec)
|
||||
{
|
||||
xmlAddChild (node, timespec_to_dom_tree (tag, &tms));
|
||||
xmlAddChild (node, time64_to_dom_tree (tag, tms.tv_sec));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2350,7 +2350,7 @@ txn_rest_date_posted_end_handler (gpointer data_for_children,
|
||||
gpointer* result, const gchar* tag)
|
||||
{
|
||||
Transaction* t = (Transaction*) parent_data;
|
||||
TimespecParseInfo* info = (TimespecParseInfo*) data_for_children;
|
||||
Time64ParseInfo* info = (Time64ParseInfo*) data_for_children;
|
||||
|
||||
g_return_val_if_fail (info, FALSE);
|
||||
if (!t || !timespec_parse_ok (info))
|
||||
@ -2359,7 +2359,7 @@ txn_rest_date_posted_end_handler (gpointer data_for_children,
|
||||
return (FALSE);
|
||||
}
|
||||
|
||||
xaccTransSetDatePostedTS (t, & (info->ts));
|
||||
xaccTransSetDatePostedSecs (t, info->time);
|
||||
g_free (info);
|
||||
return (TRUE);
|
||||
}
|
||||
@ -2382,7 +2382,7 @@ txn_rest_date_entered_end_handler (gpointer data_for_children,
|
||||
gpointer* result, const gchar* tag)
|
||||
{
|
||||
Transaction* t = (Transaction*) parent_data;
|
||||
TimespecParseInfo* info = (TimespecParseInfo*) data_for_children;
|
||||
Time64ParseInfo* info = (Time64ParseInfo*) data_for_children;
|
||||
|
||||
g_return_val_if_fail (info, FALSE);
|
||||
if (!t || !timespec_parse_ok (info))
|
||||
@ -2391,7 +2391,7 @@ txn_rest_date_entered_end_handler (gpointer data_for_children,
|
||||
return (FALSE);
|
||||
}
|
||||
|
||||
xaccTransSetDateEnteredTS (t, & (info->ts));
|
||||
xaccTransSetDateEnteredSecs (t, info->time);
|
||||
g_free (info);
|
||||
return (TRUE);
|
||||
}
|
||||
@ -2713,7 +2713,7 @@ txn_restore_split_reconcile_date_end_handler (gpointer data_for_children,
|
||||
gpointer* result, const gchar* tag)
|
||||
{
|
||||
Split* s = (Split*) parent_data;
|
||||
TimespecParseInfo* info = (TimespecParseInfo*) data_for_children;
|
||||
Time64ParseInfo* info = (Time64ParseInfo*) data_for_children;
|
||||
|
||||
g_return_val_if_fail (info, FALSE);
|
||||
if (!s || !timespec_parse_ok (info))
|
||||
@ -2722,7 +2722,7 @@ txn_restore_split_reconcile_date_end_handler (gpointer data_for_children,
|
||||
return (FALSE);
|
||||
}
|
||||
|
||||
xaccSplitSetDateReconciledTS (s, & (info->ts));
|
||||
xaccSplitSetDateReconciledSecs (s, info->time);
|
||||
g_free (info);
|
||||
return (TRUE);
|
||||
}
|
||||
|
@ -137,24 +137,12 @@ time64_to_string (time64 time)
|
||||
return gnc_print_time64 (time, TIMESPEC_TIME_FORMAT " %q");
|
||||
}
|
||||
|
||||
char*
|
||||
timespec_sec_to_string (const Timespec* ts)
|
||||
{
|
||||
return gnc_print_time64 (ts->tv_sec, "%Y-%m-%d %H:%M:%S %q");
|
||||
}
|
||||
|
||||
gchar*
|
||||
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");
|
||||
auto date_str = time64_to_string (time);
|
||||
if (!date_str)
|
||||
return NULL;
|
||||
ret = xmlNewNode (NULL, BAD_CAST tag);
|
||||
@ -164,46 +152,6 @@ time64_to_dom_tree (const char* tag, const time64 time)
|
||||
return ret;
|
||||
}
|
||||
|
||||
xmlNodePtr
|
||||
timespec_to_dom_tree (const char* tag, const Timespec* spec)
|
||||
{
|
||||
xmlNodePtr ret;
|
||||
gchar* date_str = NULL;
|
||||
gchar* ns_str = NULL;
|
||||
|
||||
g_return_val_if_fail (spec, NULL);
|
||||
|
||||
date_str = timespec_sec_to_string (spec);
|
||||
|
||||
if (!date_str)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ret = xmlNewNode (NULL, BAD_CAST tag);
|
||||
|
||||
xmlNewTextChild (ret, NULL, BAD_CAST "ts:date",
|
||||
checked_char_cast (date_str));
|
||||
|
||||
if (spec->tv_nsec > 0)
|
||||
{
|
||||
ns_str = timespec_nsec_to_string (spec);
|
||||
if (ns_str)
|
||||
{
|
||||
xmlNewTextChild (ret, NULL, BAD_CAST "ts:ns",
|
||||
checked_char_cast (ns_str));
|
||||
}
|
||||
}
|
||||
|
||||
g_free (date_str);
|
||||
if (ns_str)
|
||||
{
|
||||
g_free (ns_str);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
xmlNodePtr
|
||||
gdate_to_dom_tree (const char* tag, const GDate* date)
|
||||
{
|
||||
@ -332,7 +280,7 @@ add_kvp_value_node (xmlNodePtr node, const gchar* tag, KvpValue* val)
|
||||
case KvpValue::Type::TIMESPEC:
|
||||
{
|
||||
auto ts = val->get<Timespec> ();
|
||||
val_node = timespec_to_dom_tree (tag, &ts);
|
||||
val_node = time64_to_dom_tree (tag, ts.tv_sec);
|
||||
xmlSetProp (val_node, BAD_CAST "type", BAD_CAST "timespec");
|
||||
xmlAddChild (node, val_node);
|
||||
break;
|
||||
|
@ -40,10 +40,7 @@ xmlNodePtr int_to_dom_tree (const char* tag, gint64 val);
|
||||
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);
|
||||
|
@ -871,15 +871,3 @@ dom_tree_valid_time64 (time64 val, const xmlChar * name)
|
||||
"with a date of 1969-12-31 or 1970-01-01.", name);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
dom_tree_valid_timespec (Timespec* ts, const xmlChar* name)
|
||||
{
|
||||
|
||||
if (ts->tv_sec || ts->tv_nsec)
|
||||
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;
|
||||
}
|
||||
|
@ -43,7 +43,6 @@ GList* dom_tree_freqSpec_to_recurrences (xmlNodePtr node, QofBook* book);
|
||||
Recurrence* dom_tree_to_recurrence (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);
|
||||
|
@ -356,10 +356,10 @@ simple_chars_only_parser_new (sixtp_end_handler end_handler)
|
||||
<ns>658864000</ns>
|
||||
</date-posted>
|
||||
|
||||
and produce a Timespec*. The start handler for the top allocates
|
||||
the Timespec * and passes it to the children. The <s> block sets
|
||||
the seconds and the <ns> block (if any) sets the nanoseconds. If
|
||||
all goes well, returns the Timespec* as the result.
|
||||
and produce a time64. The start handler for the top allocates
|
||||
the time64 and passes it to the children. The <s> block sets
|
||||
the seconds and the <ns> block is ignored. If
|
||||
all goes well, returns the time64 as the result.
|
||||
*/
|
||||
|
||||
gboolean
|
||||
@ -372,11 +372,11 @@ string_to_time64 (const gchar* str, time64* time)
|
||||
/* Top level timespec node:
|
||||
|
||||
input: user end handler *
|
||||
returns: Timespec*
|
||||
returns: time64
|
||||
|
||||
start: Allocates TimespecParseInfo* for data_for_children.
|
||||
start: Allocates Time64ParseInfo* for data_for_children.
|
||||
characters: none (whitespace only).
|
||||
end: g_free TimespecParseInfo + any other actions
|
||||
end: g_free Time64ParseInfo + any other actions
|
||||
|
||||
cleanup-result: NA
|
||||
cleanup-chars: NA
|
||||
@ -392,7 +392,7 @@ generic_timespec_start_handler (GSList* sibling_data, gpointer parent_data,
|
||||
gpointer* data_for_children, gpointer* result,
|
||||
const gchar* tag, gchar** attrs)
|
||||
{
|
||||
TimespecParseInfo* tsp = g_new0 (TimespecParseInfo, 1);
|
||||
Time64ParseInfo* tsp = g_new0 (Time64ParseInfo, 1);
|
||||
g_return_val_if_fail (tsp, FALSE);
|
||||
*data_for_children = tsp;
|
||||
return (TRUE);
|
||||
@ -403,18 +403,9 @@ generic_timespec_start_handler (GSList* sibling_data, gpointer parent_data,
|
||||
new timespec. Otherwise, you can presume that everything's been
|
||||
cleaned up properly and return FALSE. */
|
||||
gboolean
|
||||
timespec_parse_ok (TimespecParseInfo* info)
|
||||
timespec_parse_ok (Time64ParseInfo* info)
|
||||
{
|
||||
|
||||
if ((info->s_block_count > 1) || (info->ns_block_count > 1) ||
|
||||
((info->s_block_count == 0) && (info->ns_block_count == 0)))
|
||||
{
|
||||
return (FALSE);
|
||||
}
|
||||
else
|
||||
{
|
||||
return (TRUE);
|
||||
}
|
||||
return info->s_block_count != 1;
|
||||
}
|
||||
|
||||
/* generic_timespec_end_handler - must be customized and provided by
|
||||
@ -422,12 +413,12 @@ timespec_parse_ok (TimespecParseInfo* info)
|
||||
|
||||
/* <s> (parent timespec-node)
|
||||
|
||||
input: TimespecParseInfo *
|
||||
input: Time64ParseInfo *
|
||||
returns: NA
|
||||
|
||||
start: NA
|
||||
characters: accumulate.
|
||||
end: convert characters to secs part of input Timespec and inc s_block_count.
|
||||
end: convert characters to secs part of input time64 and inc s_block_count.
|
||||
|
||||
cleanup-result: NA
|
||||
cleanup-chars: g_free data.
|
||||
@ -444,7 +435,7 @@ generic_timespec_secs_end_handler (gpointer data_for_children,
|
||||
gpointer* result, const gchar* tag)
|
||||
{
|
||||
gchar* txt = NULL;
|
||||
TimespecParseInfo* info = (TimespecParseInfo*) parent_data;
|
||||
Time64ParseInfo* info = (Time64ParseInfo*) parent_data;
|
||||
gboolean ok;
|
||||
|
||||
g_return_val_if_fail (parent_data, FALSE);
|
||||
@ -452,7 +443,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_time64 (txt, & (info->ts.tv_sec));
|
||||
ok = string_to_time64 (txt, & info->time);
|
||||
g_free (txt);
|
||||
|
||||
g_return_val_if_fail (ok, FALSE);
|
||||
@ -463,15 +454,15 @@ generic_timespec_secs_end_handler (gpointer data_for_children,
|
||||
|
||||
/* <s> (parent timespec-node)
|
||||
|
||||
input: TimespecParseInfo *
|
||||
input: Time64ParseInfo *
|
||||
returns: NA
|
||||
|
||||
start: NA
|
||||
characters: accumulate.
|
||||
end: convert characters to secs part of input Timespec and inc s_block_count.
|
||||
end: NA
|
||||
|
||||
cleanup-result: NA
|
||||
cleanup-chars: g_free data.
|
||||
cleanup-chars: NA.
|
||||
fail: NA
|
||||
result-fail: NA
|
||||
chars-fail: g_free data.
|
||||
|
@ -31,10 +31,9 @@ extern "C"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
Timespec ts;
|
||||
time64 time;
|
||||
guint s_block_count;
|
||||
guint ns_block_count;
|
||||
} TimespecParseInfo;
|
||||
} Time64ParseInfo;
|
||||
|
||||
#define TIMESPEC_TIME_FORMAT "%Y-%m-%d %H:%M:%S"
|
||||
#define TIMESPEC_PARSE_TIME_FORMAT "%Y-%m-%d %H:%M:%S"
|
||||
@ -94,7 +93,7 @@ gboolean generic_timespec_start_handler (GSList* sibling_data,
|
||||
gpointer* result,
|
||||
const gchar* tag, gchar** attrs);
|
||||
|
||||
gboolean timespec_parse_ok (TimespecParseInfo* info);
|
||||
gboolean timespec_parse_ok (Time64ParseInfo* info);
|
||||
|
||||
gboolean generic_timespec_secs_end_handler (
|
||||
gpointer data_for_children,
|
||||
|
Loading…
Reference in New Issue
Block a user