r22376 - gnucash/trunk/src/import-export/ofx - Minor improvement of OFX import with missing date field. Unfortunately libofx doesn't do this right in any case.
Christian Stimming
cstim at code.gnucash.org
Sun Sep 9 16:26:58 EDT 2012
Author: cstim
Date: 2012-09-09 16:26:58 -0400 (Sun, 09 Sep 2012)
New Revision: 22376
Trac: http://svn.gnucash.org/trac/changeset/22376
Modified:
gnucash/trunk/src/import-export/ofx/gnc-ofx-import.c
Log:
Minor improvement of OFX import with missing date field. Unfortunately libofx doesn't do this right in any case.
Modified: gnucash/trunk/src/import-export/ofx/gnc-ofx-import.c
===================================================================
--- gnucash/trunk/src/import-export/ofx/gnc-ofx-import.c 2012-09-09 19:01:02 UTC (rev 22375)
+++ gnucash/trunk/src/import-export/ofx/gnc-ofx-import.c 2012-09-09 20:26:58 UTC (rev 22376)
@@ -357,20 +357,27 @@
transaction = xaccMallocTransaction(book);
xaccTransBeginEdit(transaction);
- if (data.date_initiated_valid)
+ /* Note: Unfortunately libofx <= 0.9.5 will not report a missing
+ * date field as an invalid one. Instead, it will report it as
+ * valid and return a completely bogus date. Starting with
+ * libofx-0.9.6 (not yet released as of 2012-09-09), it will still
+ * be reported as valid but at least the date integer itself is
+ * just plain zero. */
+ if (data.date_posted_valid && (data.date_posted != 0))
{
+ /* The hopeful case: We have a posted_date */
+ xaccTransSetDatePostedSecs(transaction, data.date_posted);
+ } else if (data.date_initiated_valid && (data.date_initiated != 0))
+ {
+ /* No posted date? Maybe we have an initiated_date */
xaccTransSetDatePostedSecs(transaction, data.date_initiated);
}
- else if (data.date_posted_valid)
+ else
{
- xaccTransSetDatePostedSecs(transaction, data.date_posted);
+ /* Uh no, no valid date. As a workaround use today's date */
+ xaccTransSetDatePostedSecs(transaction, mktime(localtime(¤t_time)));
}
- if (data.date_posted_valid)
- {
- xaccTransSetDatePostedSecs(transaction, data.date_posted);
- }
-
current_time = time(NULL);
xaccTransSetDateEnteredSecs(transaction, mktime(localtime(¤t_time)));
More information about the gnucash-changes
mailing list