Merge Chris Lam's Bug 790526 fix into maint.

This commit is contained in:
John Ralls 2017-12-19 22:04:18 -08:00
commit a28bcdf19b
4 changed files with 43 additions and 2 deletions

View File

@ -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

View File

@ -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)
test-print-parse-amount.c test-print-queries.c test-scm-query-string.c test-sx.c test-date-utilities.scm)

View File

@ -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 = \

View File

@ -0,0 +1,38 @@
(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 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)))
(define (weeknums-equal? pair-of-dates)
(let ((d1 (car pair-of-dates))
(d2 (cdr pair-of-dates)))
(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)
'(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))))
))