[GNC] Scheduled Transaction Calculations

John Ralls jralls at ceridwen.us
Sat Nov 2 13:27:29 EDT 2019



> On Nov 2, 2019, at 7:08 AM, Fred Bone <Fred.Bone at dial.pipex.com> wrote:
> 
> On 01 November 2019 at 12:34, John Ralls said:
> 
> [...]
>> You could try adding this to fin.scm:
>> 
>> (load-from-path "gnucash/app-utils")
>> (define (gnc:days-in-prev-month) (/ ( + 1 (- (gnc:get-end-prev-month)
>> (gnc:get-start-prev-month)))) 86400))
> 
> This will produce a non-integer result if
> (a) prev month includes daylight-saving-time shift
> or
> (b) prev month includes a leap second.
> 
> (While I'm not familiar with Scheme, if the potential non-integer result 
> isn't an issue -- i.e. if it gets auto-rounded to nearest integer -- then 
> there was no point in adding the odd second).
> 

Time in GnuCash is UTC internally so there are no daylight-time changes. A leap second might be an issue, though a rather rare one.

See https://www.gnu.org/software/guile/manual/html_node/Exactness.html. Without adding the second back in the result of the division for October was 2678399/86400. One could instead use 
  (round (/ (- (gnc:get-end-prev-month) (gnc:get-start-prev-month)))) 86400))
which would resolve the leap-second problem.

Regards,
John Ralls


More information about the gnucash-user mailing list