From f3bc8eea8b12b485be698e1501afb168fc20956d Mon Sep 17 00:00:00 2001 From: Christopher Lam Date: Sun, 19 Nov 2017 05:20:35 +0800 Subject: [PATCH 01/10] Bugzilla 790526 Correct weeknum calculator This change will fix 'num-of-weeks-since-1/jan/1970' which formerly used quotient to remove the fractional part of the division. For negative values of num-of-weeks, the number is truncated in the wrong direction (i.e. towards 0). This change uses floor instead to ensure the num-of-weeks found is the nearest integer LESS than the fractional number. --- src/app-utils/date-utilities.scm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app-utils/date-utilities.scm b/src/app-utils/date-utilities.scm index 03faa8fa81..72eb0f35ec 100644 --- a/src/app-utils/date-utilities.scm +++ b/src/app-utils/date-utilities.scm @@ -198,7 +198,7 @@ (/ (- (/ (/ caltime 3600.0) 24) 3) 7)) (define (gnc:date-to-week caltime) - (quotient (- (quotient caltime 86400) 3) 7)) + (floor (/ (- (/ caltime 86400) 3) 7))) ;; convert a date in seconds since 1970 into # of days since Feb 28, 1970 ;; ignoring leap-seconds From b6ec61fa45c386b641c516782b4501d333a8ea0e Mon Sep 17 00:00:00 2001 From: christopherlam Date: Wed, 20 Dec 2017 07:58:03 +0800 Subject: [PATCH 02/10] add unittest for bugzilla 790526 --- src/app-utils/test/test-date-utilities.scm | 42 ++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/app-utils/test/test-date-utilities.scm diff --git a/src/app-utils/test/test-date-utilities.scm b/src/app-utils/test/test-date-utilities.scm new file mode 100644 index 0000000000..393c0f4efa --- /dev/null +++ b/src/app-utils/test/test-date-utilities.scm @@ -0,0 +1,42 @@ +(use-modules (gnucash gnc-module)) +(gnc:module-begin-syntax (gnc:module-load "gnucash/app-utils" 0)) +(use-modules (gnucash engine test test-extras)) + +(define (run-test) + (and (test test-weeknum-calculator))) + +(define (create->time64 l) + (let ((now (gnc-localtime (current-time)))) + (set-tm:sec now (list-ref l 0)) + (set-tm:min now (list-ref l 1)) + (set-tm:hour now (list-ref l 2)) + (set-tm:mday now (list-ref l 3)) + (set-tm:mon now (list-ref l 4)) + (set-tm:year now (list-ref l 5)) + (set-tm:isdst now -1) + (gnc-mktime now))) + +(define (list->time64 l) + (create-time64 (list-ref l 0) (list-ref l 1) (list-ref l 2) + (list-ref l 3) (list-ref l 4) (list-ref l 5))) + +(define (weeknums-equal? pair-of-dates) + (let ((d1 (car pair-of-dates)) + (d2 (cdr pair-of-dates))) + (equal? (gnc:date-to-week (list->time64 d1)) + (gnc:date-to-week (list->time64 d2))))) + +(define (test-weeknum-calculator) + (and (weeknums-equal? (cons '(1970 1 1 0 0 0) + '(1970 1 1 23 59 59))) + (weeknums-equal? (cons '(1969 12 31 0 0 0) + '(1969 12 31 23 59 59))) + (weeknums-equal? (cons '(1969 12 31 0 0 0) + '(1970 1 1 0 0 1))) + (weeknums-equal? (cons '(2001 1 1 0 0 0) + '(2001 1 1 23 59 59))) + (not (weeknums-equal? (cons '(1970 1 1 0 0 0) + '(1970 1 10 0 0 1)))) + (not (weeknums-equal? (cons '(1969 12 28 0 0 1) + '(1970 1 5 0 0 1)))) + )) From 3f408a885bc5d88fbb555a78e019494b7518d69b Mon Sep 17 00:00:00 2001 From: christopherlam Date: Wed, 20 Dec 2017 08:15:26 +0800 Subject: [PATCH 03/10] typo --- src/app-utils/test/test-date-utilities.scm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app-utils/test/test-date-utilities.scm b/src/app-utils/test/test-date-utilities.scm index 393c0f4efa..380253ad90 100644 --- a/src/app-utils/test/test-date-utilities.scm +++ b/src/app-utils/test/test-date-utilities.scm @@ -5,7 +5,7 @@ (define (run-test) (and (test test-weeknum-calculator))) -(define (create->time64 l) +(define (create-time64 l) (let ((now (gnc-localtime (current-time)))) (set-tm:sec now (list-ref l 0)) (set-tm:min now (list-ref l 1)) From 98fcf1b08efbe4de7a896637d6394aeed8d824c2 Mon Sep 17 00:00:00 2001 From: John Ralls Date: Tue, 19 Dec 2017 16:54:01 -0800 Subject: [PATCH 04/10] Fix duplicate test-case name. --- src/import-export/test/test-flat-bayes.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/import-export/test/test-flat-bayes.c b/src/import-export/test/test-flat-bayes.c index 22872ca8c5..b00608b960 100644 --- a/src/import-export/test/test-flat-bayes.c +++ b/src/import-export/test/test-flat-bayes.c @@ -279,7 +279,7 @@ main (int argc, char *argv[]) GNC_TEST_ADD (suitename, "guid_bayes_entry", Fixture, NULL, setup, &write_guid_bayes_entry, teardown); GNC_TEST_ADD (suitename, "normal_bayes_find", Fixture, NULL, setup, &find_normal_bayes_account, teardown); GNC_TEST_ADD (suitename, "guid_bayes_find", Fixture, NULL, setup, &find_guid_bayes_account, teardown); - GNC_TEST_ADD (suitename, "normal_bayes_find", Fixture, NULL, setup, &find_normal_bayes_when_non_exists, teardown); + GNC_TEST_ADD (suitename, "normal_bayes_find_none", Fixture, NULL, setup, &find_normal_bayes_when_non_exists, teardown); GNC_TEST_ADD (suitename, "Mixed case", Fixture, NULL, setup, &group_account_name_and_guid_in_mixed_case, teardown); GNC_TEST_ADD (suitename, "Read flat bayes", Fixture, NULL, setup, &read_flat_bayes, teardown); GNC_TEST_ADD (suitename, "Write flat bayes", Fixture, NULL, setup, &write_flat_bayes, teardown); From 302d1e73e850b92f5b8076b0af5741fc4afbaa2d Mon Sep 17 00:00:00 2001 From: John Ralls Date: Tue, 19 Dec 2017 17:39:39 -0800 Subject: [PATCH 05/10] Add test-date-utilities to CMakeLists.txt and Makefile.am. --- src/app-utils/test/CMakeLists.txt | 4 +++- src/app-utils/test/Makefile.am | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/app-utils/test/CMakeLists.txt b/src/app-utils/test/CMakeLists.txt index b525b809fb..dc474784a4 100644 --- a/src/app-utils/test/CMakeLists.txt +++ b/src/app-utils/test/CMakeLists.txt @@ -29,5 +29,7 @@ GNC_ADD_SCHEME_TEST(scm-test-load-module test-load-module.in) CONFIGURE_FILE(test-load-module.in test-load-module @ONLY) +GNC_ADD_SCHEME_TEST(scm-test-date-utilities test-date-utilities.scm) + SET_DIST_LIST(test_app_utils_DIST CMakeLists.txt Makefile.am test-exp-parser.c test-link-module.c test-load-module.in - test-print-parse-amount.c test-print-queries.c test-scm-query-string.c test-sx.c) \ No newline at end of file + test-print-parse-amount.c test-print-queries.c test-scm-query-string.c test-sx.c test-date-utilities.scm) diff --git a/src/app-utils/test/Makefile.am b/src/app-utils/test/Makefile.am index 6fb6a95573..b78f046a64 100644 --- a/src/app-utils/test/Makefile.am +++ b/src/app-utils/test/Makefile.am @@ -4,6 +4,7 @@ TESTS = \ test-exp-parser \ test-scm-query-string \ test-print-parse-amount \ + test-date-utilities \ test-sx test_exp_parser_SOURCES = \ From 9af6f184efde5941d09d5d289b6d41a886745a52 Mon Sep 17 00:00:00 2001 From: christopherlam Date: Wed, 20 Dec 2017 10:01:32 +0800 Subject: [PATCH 06/10] fix unit test again --- src/app-utils/test/test-date-utilities.scm | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/app-utils/test/test-date-utilities.scm b/src/app-utils/test/test-date-utilities.scm index 380253ad90..e62610f1b2 100644 --- a/src/app-utils/test/test-date-utilities.scm +++ b/src/app-utils/test/test-date-utilities.scm @@ -16,15 +16,11 @@ (set-tm:isdst now -1) (gnc-mktime now))) -(define (list->time64 l) - (create-time64 (list-ref l 0) (list-ref l 1) (list-ref l 2) - (list-ref l 3) (list-ref l 4) (list-ref l 5))) - (define (weeknums-equal? pair-of-dates) (let ((d1 (car pair-of-dates)) (d2 (cdr pair-of-dates))) - (equal? (gnc:date-to-week (list->time64 d1)) - (gnc:date-to-week (list->time64 d2))))) + (equal? (gnc:date-to-week (create-time64 d1)) + (gnc:date-to-week (create-time64 d2))))) (define (test-weeknum-calculator) (and (weeknums-equal? (cons '(1970 1 1 0 0 0) From a847d441f14cf66255a8e52f6447b43d9aac447c Mon Sep 17 00:00:00 2001 From: christopherlam Date: Wed, 20 Dec 2017 11:57:35 +0800 Subject: [PATCH 07/10] fix silly mistake --- src/app-utils/test/test-date-utilities.scm | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/app-utils/test/test-date-utilities.scm b/src/app-utils/test/test-date-utilities.scm index e62610f1b2..6fca517300 100644 --- a/src/app-utils/test/test-date-utilities.scm +++ b/src/app-utils/test/test-date-utilities.scm @@ -7,12 +7,12 @@ (define (create-time64 l) (let ((now (gnc-localtime (current-time)))) - (set-tm:sec now (list-ref l 0)) - (set-tm:min now (list-ref l 1)) - (set-tm:hour now (list-ref l 2)) - (set-tm:mday now (list-ref l 3)) - (set-tm:mon now (list-ref l 4)) - (set-tm:year now (list-ref l 5)) + (set-tm:sec now (list-ref l 5)) + (set-tm:min now (list-ref l 4)) + (set-tm:hour now (list-ref l 3)) + (set-tm:mday now (list-ref l 2)) + (set-tm:mon now (list-ref l 1)) + (set-tm:year now (list-ref l 0)) (set-tm:isdst now -1) (gnc-mktime now))) From 44c51f433b0a07e44d1485cac5c16537031703ba Mon Sep 17 00:00:00 2001 From: John Ralls Date: Sat, 23 Dec 2017 16:42:43 -0800 Subject: [PATCH 08/10] Bug 791848 - GC 2.6.x does not handle ISO dates introduced with GC 2.7 Enable reading ISO-formatted dates, recognize GNC_FEATURE_SQLITE3_ISO_DATES. --- src/backend/sql/gnc-backend-sql.c | 34 +++++++++++++++++-------------- src/core-utils/gnc-features.c | 1 + src/core-utils/gnc-features.h | 1 + 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/src/backend/sql/gnc-backend-sql.c b/src/backend/sql/gnc-backend-sql.c index 7d169d1248..76aa181a79 100644 --- a/src/backend/sql/gnc-backend-sql.c +++ b/src/backend/sql/gnc-backend-sql.c @@ -1855,7 +1855,9 @@ typedef Timespec (*TimespecAccessFunc)( const gpointer ); typedef void (*TimespecSetterFunc)( const gpointer, Timespec ); #define TIMESPEC_STR_FORMAT "%04d%02d%02d%02d%02d%02d" +#define TIMESPEC_ALT_FORMAT "%04d-%02d%-02d %02d:%02d:%02d" #define TIMESPEC_COL_SIZE (4+2+2+2+2+2) +#define TIMESPEC_ALT_COL_SIZE (4+3+3+3+3+3) /* This is required because we're passing be->timespace_format to * g_strdup_printf. @@ -1926,22 +1928,24 @@ load_timespec( const GncSqlBackend* be, GncSqlRow* row, else if (G_VALUE_HOLDS_STRING (val)) { const gchar* s = g_value_get_string( val ); - if ( s != NULL ) + if ( s != NULL && strlen(s) == TIMESPEC_COL_SIZE) { - if (! g_str_has_prefix (s, "0000-00-00")) - { - gchar* buf; - buf = g_strdup_printf( "%c%c%c%c-%c%c-%c%c %c%c:%c%c:%c%c", - s[0], s[1], s[2], s[3], - s[4], s[5], - s[6], s[7], - s[8], s[9], - s[10], s[11], - s[12], s[13] ); - ts = gnc_iso8601_to_timespec_gmt( buf ); - g_free( buf ); - } - isOK = TRUE; + gchar* buf; + buf = g_strdup_printf( "%c%c%c%c-%c%c-%c%c %c%c:%c%c:%c%c", + s[0], s[1], s[2], s[3], + s[4], s[5], + s[6], s[7], + s[8], s[9], + s[10], s[11], + s[12], s[13] ); + ts = gnc_iso8601_to_timespec_gmt( buf ); + g_free( buf ); + isOK = TRUE; + } + else if (! g_str_has_prefix (s, "0000-00-00")) + { + ts = gnc_iso8601_to_timespec_gmt (s); + isOK = TRUE; } } else diff --git a/src/core-utils/gnc-features.c b/src/core-utils/gnc-features.c index 1cc495ab8e..03c9418cc9 100644 --- a/src/core-utils/gnc-features.c +++ b/src/core-utils/gnc-features.c @@ -46,6 +46,7 @@ static gncFeature known_features[] = { GNC_FEATURE_KVP_EXTRA_DATA, "Extra data for addresses, jobs or invoice entries (requires at least GnuCash 2.6.4)" }, { GNC_FEATURE_GUID_BAYESIAN, "Use account GUID as key for Bayesian data (requires at least GnuCash 2.6.12)" }, { GNC_FEATURE_GUID_FLAT_BAYESIAN, "Use account GUID as key for bayesian data and store KVP flat (requires at least GnuCash 2.6.19)" }, + { GNC_FEATURE_SQLITE3_ISO_DATES, "Use ISO formatted date-time strings in SQLite3 databases (requires at least GnuCash 2.6.20)"}, { NULL }, }; diff --git a/src/core-utils/gnc-features.h b/src/core-utils/gnc-features.h index a7ed4215cc..df4b590b41 100644 --- a/src/core-utils/gnc-features.h +++ b/src/core-utils/gnc-features.h @@ -46,6 +46,7 @@ #define GNC_FEATURE_KVP_EXTRA_DATA "Extra data in addresses, jobs or invoice entries" #define GNC_FEATURE_GUID_BAYESIAN "Account GUID based Bayesian data" #define GNC_FEATURE_GUID_FLAT_BAYESIAN "Account GUID based bayesian with flat KVP" +#define GNC_FEATURE_SQLITE3_ISO_DATES "ISO-8601 formatted date strings in SQLite3 databases." /** @} */ From 40654cf50cbc03973d245059f98da0f938fe5ba5 Mon Sep 17 00:00:00 2001 From: John Ralls Date: Sat, 23 Dec 2017 17:17:48 -0800 Subject: [PATCH 09/10] Fix picky gcc-7.2 complaint about a %d conversion not fitting in 3 bytes. --- src/gnome-utils/gnc-dense-cal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gnome-utils/gnc-dense-cal.c b/src/gnome-utils/gnc-dense-cal.c index 596a0ae06e..564ddcd197 100644 --- a/src/gnome-utils/gnc-dense-cal.c +++ b/src/gnome-utils/gnc-dense-cal.c @@ -1104,7 +1104,7 @@ gnc_dense_cal_draw_to_buffer(GncDenseCal *dcal) { doc_coords(dcal, doc, &x1, &y1, &x2, &y2); memset(dayNumBuf, 0, 3); - snprintf(dayNumBuf, 3, "%d", g_date_get_day(&d)); + snprintf(dayNumBuf, 3, "%hhu", g_date_get_day(&d)); pango_layout_set_text(layout, dayNumBuf, -1); pango_layout_get_pixel_size(layout, &numW, &numH); w = (x2 - x1) + 1; From 82f1384c5827114d44ba51eafabd8ae00590b3aa Mon Sep 17 00:00:00 2001 From: John Ralls Date: Sat, 23 Dec 2017 17:31:18 -0800 Subject: [PATCH 10/10] Fix autotools test setup for test-date-utilities. --- src/app-utils/test/Makefile.am | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/src/app-utils/test/Makefile.am b/src/app-utils/test/Makefile.am index b78f046a64..085089dc77 100644 --- a/src/app-utils/test/Makefile.am +++ b/src/app-utils/test/Makefile.am @@ -4,8 +4,12 @@ TESTS = \ test-exp-parser \ test-scm-query-string \ test-print-parse-amount \ - test-date-utilities \ - test-sx + test-sx \ + $(SCM_TESTS) + +SCM_TESTS = test-date-utilities + +SCM_TEST_SRCS = $(SCM_TESTS:%=%.scm) test_exp_parser_SOURCES = \ test-exp-parser.c @@ -18,6 +22,7 @@ GNC_TEST_DEPS = --gnc-module-dir ${top_builddir}/src/engine \ --guile-load-dir ${top_builddir}/src/core-utils \ --guile-load-dir ${top_builddir}/src/gnc-module \ --guile-load-dir ${top_builddir}/src/engine \ + --guile-load-dir ${top_builddir}/src/engine/test \ --guile-load-dir ${top_builddir}/src/scm \ --guile-load-dir ${top_builddir}/src/app-utils \ --library-dir ${top_builddir}/src/libqof/qof \ @@ -28,6 +33,12 @@ GNC_TEST_DEPS = --gnc-module-dir ${top_builddir}/src/engine \ --library-dir ${top_builddir}/src/backend/sql \ --library-dir ${top_builddir}/src/app-utils +$(SCM_TESTS): %: $(srcdir)/%.scm Makefile .scm-links + echo 'export GNC_BUILDDIR="${abs_top_builddir}";' > $@ + echo 'export GNC_UNINSTALLED=yes;' >> $@ + echo '${GUILE} --debug -l $(srcdir)/$*.scm -c "(exit (run-test))"' >> $@ + chmod a+x $@ + TESTS_ENVIRONMENT = \ GUILE_WARN_DEPRECATED=no \ GUILE="${GUILE}" \ @@ -68,3 +79,20 @@ AM_CPPFLAGS = \ -I${top_srcdir}/src/libqof/qof \ ${GUILE_CFLAGS} \ ${GLIB_CFLAGS} + +.scm-links: + $(RM) -rf gnucash + mkdir -p gnucash/app-utils/test + ( cd gnucash/app-utils/test; for A in $(SCM_TEST_HELPERS) ; do $(LN_S) -f $(abs_srcdir)/$$A . ; done ) +if ! OS_WIN32 +# Windows knows no "ln -s" but uses "cp": must copy every time (see bug #566567). + touch .scm-links +endif + +clean-local: + $(RM) -rf gnucash + $(RM) *.log + +noinst_DATA = .scm-links +CLEANFILES = .scm-links +DISTCLEANFILES = $(SCM_TESTS)