GNOME Bugzilla – Bug 790526
Mathematical bug
Last modified: 2018-06-30 00:00:45 UTC
Created attachment 363959 [details] Sample file dec69-jan70 Hi All There's a bug in the week number calculation, which only affects dates near 01/01/1970. Premise: the 'weeknumber' calculator is performed in date-utilities.scm - its formula is currently (quotient (- (quotient (gnc-mktime datevec) 86400) 3) 7). This works rather well for modern dates. The following sample datafile has 1 transaction per day, everyday from 01/12/1979 to 31/01/1970. Herewith the weekly transaction report. Notice the blocks are not 7-day blocks anymore. This stems from the quotient function truncating the whole numbers from the division, and the number 'changes direction' near zero. Also notice the week headers are wrong for pre-1970 dates. I'm not sure which mathematical formula will reliably calculate the weekday. Can anyone help? Transaction Report From 01/12/1969 To 31/01/1970 Date Description Account Amount Checking Account 08/12/1969 to 14/12/1969 01/12/1969 Item Checking Account $0.00 02/12/1969 Item Checking Account $0.00 03/12/1969 Item Checking Account $0.00 04/12/1969 Item Checking Account $0.00 05/12/1969 Item Checking Account $0.00 06/12/1969 Item Checking Account $0.00 07/12/1969 Item Checking Account $0.00 Total For 08/12/1969 to 14/12/1969 $0.00 15/12/1969 to 21/12/1969 08/12/1969 Item Checking Account $0.00 09/12/1969 Item Checking Account $0.00 10/12/1969 Item Checking Account $0.00 11/12/1969 Item Checking Account $0.00 12/12/1969 Item Checking Account $0.00 13/12/1969 Item Checking Account $0.00 14/12/1969 Item Checking Account $0.00 Total For 15/12/1969 to 21/12/1969 $0.00 22/12/1969 to 28/12/1969 15/12/1969 Item Checking Account $0.00 16/12/1969 Item Checking Account $0.00 17/12/1969 Item Checking Account $0.00 18/12/1969 Item Checking Account $0.00 19/12/1969 Item Checking Account $0.00 20/12/1969 Item Checking Account $0.00 21/12/1969 Item Checking Account $0.00 Total For 22/12/1969 to 28/12/1969 $0.00 29/12/1969 to 04/01/1970 22/12/1969 Item Checking Account $0.00 23/12/1969 Item Checking Account $0.00 23/12/1969 Item Checking Account $0.00 24/12/1969 Item Checking Account $0.00 25/12/1969 Item Checking Account $0.00 26/12/1969 Item Checking Account $0.00 27/12/1969 Item Checking Account $0.00 28/12/1969 Item Checking Account $0.00 Total For 29/12/1969 to 04/01/1970 $0.00 05/01/1970 to 11/01/1970 29/12/1969 Item Checking Account $0.00 30/12/1969 Item Checking Account $0.00 31/12/1969 Item Checking Account $0.00 Total For 05/01/1970 to 11/01/1970 $0.00 05/01/1970 to 11/01/1970 01/01/1970 Item Checking Account $0.00 02/01/1970 Item Checking Account $0.00 03/01/1970 Item Checking Account $0.00 04/01/1970 Item Checking Account $0.00 05/01/1970 Item Checking Account $0.00 06/01/1970 Item Checking Account $0.00 07/01/1970 Item Checking Account $0.00 08/01/1970 Item Checking Account $0.00 09/01/1970 Item Checking Account $0.00 10/01/1970 Item Checking Account $0.00 11/01/1970 Item Checking Account $0.00 Total For 05/01/1970 to 11/01/1970 $0.00 12/01/1970 to 18/01/1970 12/01/1970 Item Checking Account $0.00 13/01/1970 Item Checking Account $0.00 14/01/1970 Item Checking Account $0.00 15/01/1970 Item Checking Account $0.00 16/01/1970 Item Checking Account $0.00 17/01/1970 Item Checking Account $0.00 18/01/1970 Item Checking Account $0.00 Total For 12/01/1970 to 18/01/1970 $0.00 19/01/1970 to 25/01/1970 19/01/1970 Item Checking Account $0.00 20/01/1970 Item Checking Account $0.00 21/01/1970 Item Checking Account $0.00 22/01/1970 Item Checking Account $0.00 23/01/1970 Item Checking Account $0.00 24/01/1970 Item Checking Account $0.00 25/01/1970 Item Checking Account $0.00 Total For 19/01/1970 to 25/01/1970 $0.00 26/01/1970 to 01/02/1970 26/01/1970 Item Checking Account $0.00 27/01/1970 Item Checking Account $0.00 28/01/1970 Item Checking Account $0.00 29/01/1970 Item Checking Account $0.00 30/01/1970 Item Checking Account $0.00 31/01/1970 Item Checking Account $0.00 Total For 26/01/1970 to 01/02/1970 $0.00 Total For Checking Account $0.00 Grand Total $0.00
I've changed weeknumber calculator to (floor (/ (- (/ time64 86400) 3) 7)) which does a better job. But for some reason gnucash decides to divide the week on 01/01/1970. Transaction Report From 01/12/1969 To 31/01/1970 Date Description Account Amount Checking Account 01/12/1969 to 07/12/1969 01/12/1969 Item Checking Account $0.00 02/12/1969 Item Checking Account $0.00 03/12/1969 Item Checking Account $0.00 04/12/1969 Item Checking Account $0.00 05/12/1969 Item Checking Account $0.00 06/12/1969 Item Checking Account $0.00 07/12/1969 Item Checking Account $0.00 Total For 01/12/1969 to 07/12/1969 $0.00 08/12/1969 to 14/12/1969 08/12/1969 Item Checking Account $0.00 09/12/1969 Item Checking Account $0.00 10/12/1969 Item Checking Account $0.00 11/12/1969 Item Checking Account $0.00 12/12/1969 Item Checking Account $0.00 13/12/1969 Item Checking Account $0.00 14/12/1969 Item Checking Account $0.00 Total For 08/12/1969 to 14/12/1969 $0.00 15/12/1969 to 21/12/1969 15/12/1969 Item Checking Account $0.00 16/12/1969 Item Checking Account $0.00 17/12/1969 Item Checking Account $0.00 18/12/1969 Item Checking Account $0.00 19/12/1969 Item Checking Account $0.00 20/12/1969 Item Checking Account $0.00 21/12/1969 Item Checking Account $0.00 Total For 15/12/1969 to 21/12/1969 $0.00 22/12/1969 to 28/12/1969 22/12/1969 Item Checking Account $0.00 23/12/1969 Item Checking Account $0.00 23/12/1969 Item Checking Account $0.00 24/12/1969 Item Checking Account $0.00 25/12/1969 Item Checking Account $0.00 26/12/1969 Item Checking Account $0.00 27/12/1969 Item Checking Account $0.00 28/12/1969 Item Checking Account $0.00 Total For 22/12/1969 to 28/12/1969 $0.00 29/12/1969 to 04/01/1970 29/12/1969 Item Checking Account $0.00 30/12/1969 Item Checking Account $0.00 31/12/1969 Item Checking Account $0.00 Total For 29/12/1969 to 04/01/1970 $0.00 29/12/1969 to 04/01/1970 01/01/1970 Item Checking Account $0.00 02/01/1970 Item Checking Account $0.00 03/01/1970 Item Checking Account $0.00 04/01/1970 Item Checking Account $0.00 Total For 29/12/1969 to 04/01/1970 $0.00 05/01/1970 to 11/01/1970 05/01/1970 Item Checking Account $0.00 06/01/1970 Item Checking Account $0.00 07/01/1970 Item Checking Account $0.00 08/01/1970 Item Checking Account $0.00 09/01/1970 Item Checking Account $0.00 10/01/1970 Item Checking Account $0.00 11/01/1970 Item Checking Account $0.00 Total For 05/01/1970 to 11/01/1970 $0.00 12/01/1970 to 18/01/1970 12/01/1970 Item Checking Account $0.00 13/01/1970 Item Checking Account $0.00 14/01/1970 Item Checking Account $0.00 15/01/1970 Item Checking Account $0.00 16/01/1970 Item Checking Account $0.00 17/01/1970 Item Checking Account $0.00 18/01/1970 Item Checking Account $0.00 Total For 12/01/1970 to 18/01/1970 $0.00 19/01/1970 to 25/01/1970 19/01/1970 Item Checking Account $0.00 20/01/1970 Item Checking Account $0.00 21/01/1970 Item Checking Account $0.00 22/01/1970 Item Checking Account $0.00 23/01/1970 Item Checking Account $0.00 24/01/1970 Item Checking Account $0.00 25/01/1970 Item Checking Account $0.00 Total For 19/01/1970 to 25/01/1970 $0.00 26/01/1970 to 01/02/1970 26/01/1970 Item Checking Account $0.00 27/01/1970 Item Checking Account $0.00 28/01/1970 Item Checking Account $0.00 29/01/1970 Item Checking Account $0.00 30/01/1970 Item Checking Account $0.00 31/01/1970 Item Checking Account $0.00 Total For 26/01/1970 to 01/02/1970 $0.00 Total For Checking Account $0.00 Grand Total $0.00
Found it. Formula changed from (quotient (- (quotient time64 86400) 3) 7) to (floor (/ (- (/ time64 86400) 3) 7))
For the sake of completion, the default transaction.scm (unchanged for years!) splits weeks on year change. This is because the splits will be compared according to the complex formula as follows: (define (timepair-same-week tp-a tp-b) (and (timepair-same-year tp-a tp-b) (= (gnc:timepair-get-week tp-a) (gnc:timepair-get-week tp-b)))) It can be changed to the following which provides the expected behavior (define (timepair-same-week tp-a tp-b) (= (gnc:timepair-get-week tp-a) (gnc:timepair-get-week tp-b))) But the transaction.scm is due a refactor and I'll ensure the week comparator doesn't split according to year in refactored transaction.scm
GnuCash bug tracking has moved to a new Bugzilla host. This bug has been copied to https://bugs.gnucash.org/show_bug.cgi?id=790526. Please update any external references or bookmarks.