From 33a7bb73db33efe1c5c9d80835cd628fba82402f Mon Sep 17 00:00:00 2001 From: Christopher Lam Date: Sun, 19 Nov 2017 05:20:35 +0800 Subject: [PATCH] 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. --- libgnucash/app-utils/date-utilities.scm | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/libgnucash/app-utils/date-utilities.scm b/libgnucash/app-utils/date-utilities.scm index 813c3fe675..008e141d5e 100644 --- a/libgnucash/app-utils/date-utilities.scm +++ b/libgnucash/app-utils/date-utilities.scm @@ -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