r20562 - gnucash/branches/2.4/src/app-utils - [20547] Bug #647242: Fix broken averaging for quarter or half-year step size
Christian Stimming
cstim at code.gnucash.org
Sun Apr 17 15:04:57 EDT 2011
Author: cstim
Date: 2011-04-17 15:04:57 -0400 (Sun, 17 Apr 2011)
New Revision: 20562
Trac: http://svn.gnucash.org/trac/changeset/20562
Modified:
gnucash/branches/2.4/src/app-utils/date-utilities.scm
Log:
[20547] 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.
Modified: gnucash/branches/2.4/src/app-utils/date-utilities.scm
===================================================================
--- gnucash/branches/2.4/src/app-utils/date-utilities.scm 2011-04-17 16:42:57 UTC (rev 20561)
+++ gnucash/branches/2.4/src/app-utils/date-utilities.scm 2011-04-17 19:04:57 UTC (rev 20562)
@@ -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