gnucash maint: Bug 796940 - Invalid transaction date-posted KVP causes...

John Ralls jralls at code.gnucash.org
Sun Nov 11 03:17:21 EST 2018


Updated	 via  https://github.com/Gnucash/gnucash/commit/710b122b (commit)
	from  https://github.com/Gnucash/gnucash/commit/4c1c485d (commit)



commit 710b122b24de23e61dc2b099a9fdc89cb7c0d3a2
Author: John Ralls <jralls at ceridwen.us>
Date:   Sun Nov 11 17:07:34 2018 +0900

    Bug 796940 - Invalid transaction date-posted KVP causes...
    
    date-posted to not be saved.
    
    Check the stored GDate for being in the GncDateTime range as well
    as the GDate range before returning it and check trans->date-posted
    against INT64_MAX instead of 0 before changing it.

diff --git a/libgnucash/engine/Scrub.c b/libgnucash/engine/Scrub.c
index 86f0791..939db6a 100644
--- a/libgnucash/engine/Scrub.c
+++ b/libgnucash/engine/Scrub.c
@@ -1400,9 +1400,10 @@ xaccTransScrubPostedDate (Transaction *trans)
     time64 orig = xaccTransGetDate(trans);
     GDate date = xaccTransGetDatePostedGDate(trans);
     time64 time = gdate_to_time64(date);
-    if (orig && orig != time)
+    /* xaccTransGetDatePostedGDate will return a valid time */
+    if (orig == INT64_MAX && orig != time)
     {
-        /* xaccTransSetDatePostedTS handles committing the change. */
+        /* xaccTransSetDatePostedSecs handles committing the change. */
         xaccTransSetDatePostedSecs(trans, time);
     }
 }
diff --git a/libgnucash/engine/Transaction.c b/libgnucash/engine/Transaction.c
index cc83775..b33e90f 100644
--- a/libgnucash/engine/Transaction.c
+++ b/libgnucash/engine/Transaction.c
@@ -2394,13 +2394,11 @@ xaccTransGetDatePostedGDate (const Transaction *trans)
         qof_instance_get_kvp (QOF_INSTANCE (trans), &v, 1, TRANS_DATE_POSTED);
         if (G_VALUE_HOLDS_BOXED (&v))
              result = *(GDate*)g_value_get_boxed (&v);
-        if (! g_date_valid (&result))
+        if (! g_date_valid (&result) || gdate_to_time64 (result) == INT64_MAX)
         {
-             /* Well, this txn doesn't have a GDate saved in a
-              * slot. Avoid getting the date in the local TZ by
-              * converting to UTC before generating the
-              * date. (time64_to_gdate doesn't do this so don't use
-              * it.
+             /* Well, this txn doesn't have a valid GDate saved in a slot.
+              * time64_to_gdate() uses local time and we want UTC so we have
+              * to write it out.
               */
              time64 time = xaccTransGetDate(trans);
              struct tm *stm = gnc_gmtime(&time);



Summary of changes:
 libgnucash/engine/Scrub.c       |  5 +++--
 libgnucash/engine/Transaction.c | 10 ++++------
 2 files changed, 7 insertions(+), 8 deletions(-)



More information about the gnucash-changes mailing list