AUDIT: r20547 - gnucash/trunk/src/app-utils - Bug #647242: Fix broken averaging for quarter or half-year step size
Christian Stimming
cstim at code.gnucash.org
Sat Apr 9 14:44:51 EDT 2011
Author: cstim
Date: 2011-04-09 14:44:50 -0400 (Sat, 09 Apr 2011)
New Revision: 20547
Trac: http://svn.gnucash.org/trac/changeset/20547
Modified:
gnucash/trunk/src/app-utils/date-utilities.scm
Log:
Bug #647242: Fix broken averaging for quarter or half-year step size
Patch by "joshua":
I think the problem is in the file date-utilities.scm in the define statement
starting on line 191. There were no options for TwoWeekDelta, QuarterDelta, or HalfYearDelta.
BP
Modified: gnucash/trunk/src/app-utils/date-utilities.scm
===================================================================
--- gnucash/trunk/src/app-utils/date-utilities.scm 2011-04-09 13:28:10 UTC (rev 20546)
+++ gnucash/trunk/src/app-utils/date-utilities.scm 2011-04-09 18:44:50 UTC (rev 20547)
@@ -163,6 +163,16 @@
(/ (- dayadj2 dayadj1)
366.0))))
+;; convert a date in seconds since 1970 into # of 1/2 years since 1970 as
+;; a fraction (doubling date-to-year-fraction)
+(define (gnc:date-to-halfyear-fraction caltime)
+ (* (gnc:date-to-year-fraction caltime) 2))
+
+;; convert a date in seconds since 1970 into # of quarters since 1970
+;; (assuming quarter = 3 months and using 1/3 of date-to-month-fraction)
+(define (gnc:date-to-quarter-fraction caltime)
+ (/ (gnc:date-to-month-fraction caltime) 3))
+
;; convert a date in seconds since 1970 into # of months since 1970
(define (gnc:date-to-month-fraction caltime)
(let ((lt (localtime caltime)))
@@ -172,6 +182,11 @@
(gnc:date-get-month lt)
(gnc:date-get-year lt))))))
+;; convert a date in seconds since 1970 into # of two-week periods since
+;; Jan 4, 1970 ignoring leap-seconds (just halfing date-to-week-fraction)
+(define (gnc:date-to-twoweek-fraction caltime)
+ (/ (gnc:date-to-week-fraction caltime) 2))
+
;; convert a date in seconds since 1970 into # of weeks since Jan 4, 1970
;; ignoring leap-seconds
(define (gnc:date-to-week-fraction caltime)
@@ -191,7 +206,10 @@
(define (gnc:date-get-fraction-func interval)
(case interval
((YearDelta) gnc:date-to-year-fraction)
+ ((HalfYearDelta) gnc:date-to-halfyear-fraction)
+ ((QuarterDelta) gnc:date-to-quarter-fraction)
((MonthDelta) gnc:date-to-month-fraction)
+ ((TwoWeekDelta) gnc:date-to-twoweek-fraction)
((WeekDelta) gnc:date-to-week-fraction)
((DayDelta) gnc:date-to-day-fraction)
(else #f)))
More information about the gnucash-changes
mailing list