gnucash unstable: Multiple changes pushed

John Ralls jralls at code.gnucash.org
Thu Apr 12 18:20:54 EDT 2018


Updated	 via  https://github.com/Gnucash/gnucash/commit/4a97269e (commit)
	 via  https://github.com/Gnucash/gnucash/commit/85cc574d (commit)
	 via  https://github.com/Gnucash/gnucash/commit/16ba1e39 (commit)
	from  https://github.com/Gnucash/gnucash/commit/b5ac8591 (commit)



commit 4a97269e4b0ea9afc213b7f6fb839895eb65f599
Author: John Ralls <jralls at ceridwen.us>
Date:   Thu Apr 12 15:16:29 2018 -0700

    Correct a g_log_level in test_gnc_pricedb_lookup_day.

diff --git a/libgnucash/engine/test/utest-gnc-pricedb.c b/libgnucash/engine/test/utest-gnc-pricedb.c
index 34824a3..345a34d 100644
--- a/libgnucash/engine/test/utest-gnc-pricedb.c
+++ b/libgnucash/engine/test/utest-gnc-pricedb.c
@@ -1070,7 +1070,7 @@ static void
 test_gnc_pricedb_lookup_day (PriceDBFixture *fixture, gconstpointer pData)
 {
     gchar *msg1 = "[gnc_dmy2timespec_internal()] Date computation error from Y-M-D 12-11-18: Year is out of valid range: 1400..10000";
-    gint loglevel = G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL;
+    gint loglevel = G_LOG_LEVEL_WARNING | G_LOG_FLAG_FATAL;
     gchar *logdomain = "qof.engine";
     TestErrorStruct check = {loglevel, logdomain, msg1, 0};
     GLogFunc hdlr = g_log_set_default_handler ((GLogFunc)test_null_handler, &check);

commit 85cc574d5071d945bb6174b4ffa5f30037592842
Author: John Ralls <jralls at ceridwen.us>
Date:   Thu Apr 12 15:15:33 2018 -0700

    Prevent throw in gnc-pricedb.
    
    If a price lookup is given an invalid time64/timespec (i.e. INT64_MAX)
    then just return NULL instead of trying to find the nearest price.

diff --git a/libgnucash/engine/gnc-pricedb.c b/libgnucash/engine/gnc-pricedb.c
index 186f697..62e3111 100644
--- a/libgnucash/engine/gnc-pricedb.c
+++ b/libgnucash/engine/gnc-pricedb.c
@@ -2348,6 +2348,7 @@ lookup_nearest_in_time(GNCPriceDB *db,
     GList *item = NULL;
 
     if (!db || !c || !currency) return NULL;
+    if (t.tv_sec == INT64_MAX) return NULL;
     ENTER ("db=%p commodity=%p currency=%p", db, c, currency);
     price_list = pricedb_get_prices_internal (db, c, currency, TRUE);
     if (!price_list) return NULL;

commit 16ba1e39b13f90beb9f17afd32474e766480ff2d
Author: John Ralls <jralls at ceridwen.us>
Date:   Thu Apr 12 15:12:14 2018 -0700

    Bug 795080 - Some dates reset to 01/01/1970
    
    An odd corner case: BST apparently came off of DST at 23:00 26 Oct 2014,
    so midnight that day was ambiguous about being DST or not; that causes
    the local_date_time constructor to throw in spite of the tm.is_dst element
    being 0 (meaning pick standard time).
    
    Instead of just failing in that case, try constructing a local_date_time
    three hours later then adjust it back three hours. If *that* doesn't work
    then throw a std::invalid argument.

diff --git a/libgnucash/engine/gnc-datetime.cpp b/libgnucash/engine/gnc-datetime.cpp
index 0c43372..d0958de 100644
--- a/libgnucash/engine/gnc-datetime.cpp
+++ b/libgnucash/engine/gnc-datetime.cpp
@@ -158,12 +158,12 @@ LDT_from_unix_local(const time64 time)
 static LDT
 LDT_from_struct_tm(const struct tm tm)
 {
+    auto tdate = boost::gregorian::date_from_tm(tm);
+    auto tdur = boost::posix_time::time_duration(tm.tm_hour, tm.tm_min,
+                                                 tm.tm_sec, 0);
+    auto tz = tzp.get(tdate.year());
     try
     {
-        auto tdate = boost::gregorian::date_from_tm(tm);
-        auto tdur = boost::posix_time::time_duration(tm.tm_hour, tm.tm_min,
-                                                     tm.tm_sec, 0);
-        auto tz = tzp.get(tdate.year());
         LDT ldt(tdate, tdur, tz, LDTBase::EXCEPTION_ON_ERROR);
         return ldt;
     }
@@ -177,7 +177,18 @@ LDT_from_struct_tm(const struct tm tm)
     }
     catch(boost::local_time::ambiguous_result&)
     {
-        throw(std::invalid_argument("Struct tm can resolve to more than one time."));
+        /* We plunked down in the middle of a DST change. Try constructing the
+         * LDT three hours later to get a valid result then back up those three
+         * hours to have the time we want.
+         */
+        using boost::posix_time::hours;
+        auto hour = tm.tm_hour;
+        tdur += hours(3);
+        LDT ldt(tdate, tdur, tz, LDTBase::NOT_DATE_TIME_ON_ERROR);
+        if (ldt.is_special())
+            throw(std::invalid_argument("Couldn't create a valid datetime."));
+        ldt -= hours(3);
+        return ldt;
     }
 }
 



Summary of changes:
 libgnucash/engine/gnc-datetime.cpp         | 21 ++++++++++++++++-----
 libgnucash/engine/gnc-pricedb.c            |  1 +
 libgnucash/engine/test/utest-gnc-pricedb.c |  2 +-
 3 files changed, 18 insertions(+), 6 deletions(-)



More information about the gnucash-changes mailing list