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.
This commit is contained in:
Christopher Lam 2017-11-19 05:20:35 +08:00
parent 335165104b
commit 33a7bb73db

View File

@ -64,9 +64,8 @@
(+ (tm:wday datevec) 1))
;; jan 1 == 1
(define (gnc:date-get-week datevec)
(gnc:date-to-week (gnc:timepair->secs
(gnc:timepair-start-day-time
(gnc:date->timepair datevec)))))
(gnc:date-to-week (gnc:time64-start-day-time
(gnc-mktime datevec))))
(define (gnc:date-get-year-day datevec)
(+ (tm:yday datevec) 1))
@ -235,7 +234,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