Wrong average balance for for transactions during DST?

John Ralls jralls at ceridwen.us
Thu Apr 23 17:54:30 EDT 2015


> On Apr 23, 2015, at 1:10 PM, Mosè Giordano <mose at gnu.org> wrote:
> 
> Hi John,
> 
> 2015-04-23 18:39 GMT+02:00 John Ralls <jralls at ceridwen.us>:
>> 
>>> On Apr 22, 2015, at 2:14 PM, Mosè Giordano <mose at gnu.org> wrote:
>>> 
>>> Hi all,
>>> 
>>> consider the attached account.  If I open the yearly average balance
>>> report (Reports > Assets & Liabilities > Average Balance, with Year as
>>> Step size) I get an average balance of 254.04$, instead of the
>>> expected integer 254$, why?  I noticed the extra decimals appear if
>>> the transaction is dated during daylight saving time, and disappear
>>> during standard time.  Is this an intended, yet unexpected, behavior?
>> 
>> I think that this is an expected, yet unintended behavior caused by the way the report calculates the average and the way GnuCash handles transaction posted dates.
>> 
>> GnuCash converts the posted date to a timestamp of midnight local time: The transaction in your test file has a date-posted of 2015-04-22 0:00:00 +02:00. This is represented in GnuCash's binary as a 64-bit number of seconds from 1970-01-01 0:00:00 UTC, which we call a time64. Without looking at the code in the report, I'll speculate that it's calculating the beginning and end of the year as time64s as well. If we have T_trans, T_begin, and T_end representing those time64s for the transaction's date-posted, beginning of the year, and end of the year, I expect that the averaging calculation looks like
>> 
>>     T_amount * (T_end - T_trans) / (T_end - T_begin)
>> 
>> Since DST times look like they're occurring at 01:00 instead of 00:00 the average gets shifted. I'm able to replicate your shift as follows:
>>  The date entered, 4/22, is the 111th day of the year, so there are 254 days remaining.
>>  (365 * (254 * 24 + 1)) / (365 * 24) = 254.0417
> 
> Thanks for the explanation. Is there a way to get the correct average
> balance?  It would be great to automatically have the right figure,
> and I think everyone using this report expects the same.  Is this
> worth filing a bug report?

There's no way to get a different average without changing the code in the report. 

Yes, either file a bug report or mention it as a comment to https://bugzilla.gnome.org/show_bug.cgi?id=137017, which is closely related.

Regards,
John Ralls




More information about the gnucash-user mailing list